Patch by Christof Lutteroth:
* copyright headers for the files of the libraries linprog and alm * new class Summand for representing summands in a linear constraint * merged class SoftConstraint into class Constraint; Constraint now supports both soft and hard constraint functionality * new AddConstraint methods in class LinearSpec for directly setting constraints with 1 to 4 summands * code cleanups by using aforementioned AddConstraint methods * a new very simple test application for alm * some style corrections git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24108 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+32
-27
@@ -1,8 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef AREA_H
|
#ifndef AREA_H
|
||||||
#define AREA_H
|
#define AREA_H
|
||||||
|
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
#include "SoftConstraint.h"
|
|
||||||
|
|
||||||
#include <Alignment.h>
|
#include <Alignment.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
@@ -26,51 +31,51 @@ class Area {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
bool AutoPrefContentSize() const;
|
bool AutoPrefContentSize() const;
|
||||||
void SetAutoPrefContentSize(bool value);
|
void SetAutoPrefContentSize(bool value);
|
||||||
XTab* Left() const;
|
XTab* Left() const;
|
||||||
void SetLeft(XTab* left);
|
void SetLeft(XTab* left);
|
||||||
XTab* Right() const;
|
XTab* Right() const;
|
||||||
void SetRight(XTab* right);
|
void SetRight(XTab* right);
|
||||||
YTab* Top() const;
|
YTab* Top() const;
|
||||||
void SetTop(YTab* top);
|
void SetTop(YTab* top);
|
||||||
YTab* Bottom() const;
|
YTab* Bottom() const;
|
||||||
void SetBottom(YTab* bottom);
|
void SetBottom(YTab* bottom);
|
||||||
Row* GetRow() const;
|
Row* GetRow() const;
|
||||||
void SetRow(Row* row);
|
void SetRow(Row* row);
|
||||||
Column* GetColumn() const;
|
Column* GetColumn() const;
|
||||||
void SetColumn(Column* column);
|
void SetColumn(Column* column);
|
||||||
BView* Content() const;
|
BView* Content() const;
|
||||||
void SetContent(BView* content);
|
void SetContent(BView* content);
|
||||||
XTab* ContentLeft() const;
|
XTab* ContentLeft() const;
|
||||||
YTab* ContentTop() const;
|
YTab* ContentTop() const;
|
||||||
XTab* ContentRight() const;
|
XTab* ContentRight() const;
|
||||||
YTab* ContentBottom() const;
|
YTab* ContentBottom() const;
|
||||||
BSize MinContentSize() const;
|
BSize MinContentSize() const;
|
||||||
void SetMinContentSize(BSize min);
|
void SetMinContentSize(BSize min);
|
||||||
BSize MaxContentSize() const;
|
BSize MaxContentSize() const;
|
||||||
void SetMaxContentSize(BSize max);
|
void SetMaxContentSize(BSize max);
|
||||||
BSize PrefContentSize() const;
|
BSize PrefContentSize() const;
|
||||||
void SetPrefContentSize(BSize pref);
|
void SetPrefContentSize(BSize pref);
|
||||||
BSize ShrinkRigidity() const;
|
BSize ShrinkRigidity() const;
|
||||||
void SetShrinkRigidity(BSize shrink);
|
void SetShrinkRigidity(BSize shrink);
|
||||||
BSize ExpandRigidity() const;
|
BSize ExpandRigidity() const;
|
||||||
void SetExpandRigidity(BSize expand);
|
void SetExpandRigidity(BSize expand);
|
||||||
double ContentAspectRatio() const;
|
double ContentAspectRatio() const;
|
||||||
void SetContentAspectRatio(double ratio);
|
void SetContentAspectRatio(double ratio);
|
||||||
BAlignment Alignment() const;
|
BAlignment Alignment() const;
|
||||||
void SetAlignment(BAlignment alignment);
|
void SetAlignment(BAlignment alignment);
|
||||||
void SetHAlignment(alignment horizontal);
|
void SetHAlignment(alignment horizontal);
|
||||||
void SetVAlignment(vertical_alignment vertical);
|
void SetVAlignment(vertical_alignment vertical);
|
||||||
int32 LeftInset() const;
|
int32 LeftInset() const;
|
||||||
void SetLeftInset(int32 left);
|
void SetLeftInset(int32 left);
|
||||||
int32 TopInset() const;
|
int32 TopInset() const;
|
||||||
void SetTopInset(int32 top);
|
void SetTopInset(int32 top);
|
||||||
int32 RightInset() const;
|
int32 RightInset() const;
|
||||||
void SetRightInset(int32 right);
|
void SetRightInset(int32 right);
|
||||||
int32 BottomInset() const;
|
int32 BottomInset() const;
|
||||||
void SetBottomInset(int32 bottom);
|
void SetBottomInset(int32 bottom);
|
||||||
void SetDefaultPrefContentSize();
|
void SetDefaultPrefContentSize();
|
||||||
//~ string ToString();
|
//~ string ToString();
|
||||||
Constraint* HasSameWidthAs(Area* area);
|
Constraint* HasSameWidthAs(Area* area);
|
||||||
Constraint* HasSameHeightAs(Area* area);
|
Constraint* HasSameHeightAs(Area* area);
|
||||||
BList* HasSameSizetAs(Area* area);
|
BList* HasSameSizetAs(Area* area);
|
||||||
@@ -84,7 +89,7 @@ protected:
|
|||||||
Area(BALMLayout* ls, Row* row, Column* column,
|
Area(BALMLayout* ls, Row* row, Column* column,
|
||||||
BView* content,
|
BView* content,
|
||||||
BSize minContentSize);
|
BSize minContentSize);
|
||||||
void DoLayout();
|
void DoLayout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitChildArea();
|
void InitChildArea();
|
||||||
@@ -124,8 +129,8 @@ private:
|
|||||||
double fContentAspectRatio;
|
double fContentAspectRatio;
|
||||||
Constraint* fContentAspectRatioC;
|
Constraint* fContentAspectRatioC;
|
||||||
bool fAutoPrefContentSize;
|
bool fAutoPrefContentSize;
|
||||||
SoftConstraint* fPrefContentWidth;
|
Constraint* fPrefContentWidth;
|
||||||
SoftConstraint* fPrefContentHeight;
|
Constraint* fPrefContentHeight;
|
||||||
Area* fChildArea;
|
Area* fChildArea;
|
||||||
BAlignment fAlignment;
|
BAlignment fAlignment;
|
||||||
int32 fLeftInset;
|
int32 fLeftInset;
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef BALM_LAYOUT_H
|
#ifndef BALM_LAYOUT_H
|
||||||
#define BALM_LAYOUT_H
|
#define BALM_LAYOUT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef COLUMN_H
|
#ifndef COLUMN_H
|
||||||
#define COLUMN_H
|
#define COLUMN_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef LAYOUT_STYLE_TYPE_H
|
#ifndef LAYOUT_STYLE_TYPE_H
|
||||||
#define LAYOUT_STYLE_TYPE_H
|
#define LAYOUT_STYLE_TYPE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef ROW_H
|
#ifndef ROW_H
|
||||||
#define ROW_H
|
#define ROW_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef X_TAB_H
|
#ifndef X_TAB_H
|
||||||
#define X_TAB_H
|
#define X_TAB_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef Y_TAB_H
|
#ifndef Y_TAB_H
|
||||||
#define Y_TAB_H
|
#define Y_TAB_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef CONSTRAINT_H
|
#ifndef CONSTRAINT_H
|
||||||
#define CONSTRAINT_H
|
#define CONSTRAINT_H
|
||||||
|
|
||||||
#include "OperatorType.h"
|
#include "OperatorType.h"
|
||||||
|
#include "Variable.h"
|
||||||
|
#include "ObjFunctionSummand.h"
|
||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
namespace LinearProgramming {
|
namespace LinearProgramming {
|
||||||
@@ -20,32 +29,51 @@ class Constraint {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
int32 Index();
|
int32 Index();
|
||||||
BList* Coeffs();
|
BList* Summands();
|
||||||
BList* Vars();
|
void ChangeLeftSide(BList* summands);
|
||||||
virtual void ChangeLeftSide(BList* coeffs, BList* vars);
|
void ChangeLeftSide(double coeff1, Variable* var1);
|
||||||
virtual OperatorType Op();
|
void ChangeLeftSide(double coeff1, Variable* var1,
|
||||||
virtual void SetOp(OperatorType value);
|
double coeff2, Variable* var2);
|
||||||
|
void ChangeLeftSide(double coeff1, Variable* var1,
|
||||||
|
double coeff2, Variable* var2,
|
||||||
|
double coeff3, Variable* var3);
|
||||||
|
void ChangeLeftSide(double coeff1, Variable* var1,
|
||||||
|
double coeff2, Variable* var2,
|
||||||
|
double coeff3, Variable* var3,
|
||||||
|
double coeff4, Variable* var4);
|
||||||
|
OperatorType Op();
|
||||||
|
void SetOp(OperatorType value);
|
||||||
double RightSide();
|
double RightSide();
|
||||||
void SetRightSide(double value);
|
void SetRightSide(double value);
|
||||||
BString ToString();
|
double PenaltyNeg();
|
||||||
virtual ~Constraint();
|
void SetPenaltyNeg(double value);
|
||||||
|
double PenaltyPos();
|
||||||
|
void SetPenaltyPos(double value);
|
||||||
|
Variable* DNeg() const;
|
||||||
|
Variable* DPos() const;
|
||||||
|
|
||||||
|
BString ToString();
|
||||||
|
~Constraint();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Constraint();
|
Constraint(LinearSpec* ls, BList* summands,
|
||||||
|
OperatorType op, double rightSide,
|
||||||
|
double penaltyNeg, double penaltyPos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Constraint(LinearSpec* ls, BList* coeffs, BList* vars,
|
|
||||||
OperatorType op, double rightSide);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
LinearSpec* fLS;
|
LinearSpec* fLS;
|
||||||
BList* fCoeffs;
|
BList* fSummands;
|
||||||
BList* fVars;
|
OperatorType fOp;
|
||||||
OperatorType fOp;
|
|
||||||
double fRightSide;
|
double fRightSide;
|
||||||
|
Variable* fDNeg;
|
||||||
|
Variable* fDPos;
|
||||||
|
ObjFunctionSummand* fDNegSummand;
|
||||||
|
ObjFunctionSummand* fDPosSummand;
|
||||||
|
|
||||||
|
void _UpdateLeftSide();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class LinearSpec;
|
friend class LinearSpec;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef LINEAR_SPEC_H
|
#ifndef LINEAR_SPEC_H
|
||||||
#define LINEAR_SPEC_H
|
#define LINEAR_SPEC_H
|
||||||
|
|
||||||
@@ -10,6 +16,7 @@
|
|||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
namespace LinearProgramming {
|
namespace LinearProgramming {
|
||||||
@@ -17,7 +24,6 @@ namespace LinearProgramming {
|
|||||||
class Constraint;
|
class Constraint;
|
||||||
class ObjFunctionSummand;
|
class ObjFunctionSummand;
|
||||||
class PenaltyFunction;
|
class PenaltyFunction;
|
||||||
class SoftConstraint;
|
|
||||||
class Variable;
|
class Variable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,81 +34,81 @@ class LinearSpec {
|
|||||||
public:
|
public:
|
||||||
LinearSpec();
|
LinearSpec();
|
||||||
~LinearSpec();
|
~LinearSpec();
|
||||||
void UpdateObjFunction();
|
void UpdateObjFunction();
|
||||||
void SetObjFunction(BList* coeffs, BList* vars);
|
void SetObjFunction(BList* summands);
|
||||||
ObjFunctionSummand* AddObjFunctionSummand(double coeff, Variable* var);
|
ObjFunctionSummand* AddObjFunctionSummand(double coeff, Variable* var);
|
||||||
Variable* AddVariable();
|
Variable* AddVariable();
|
||||||
|
|
||||||
Constraint* AddConstraint(BList* coeffs, BList* vars,
|
Constraint* AddConstraint(BList* summands,
|
||||||
OperatorType op, double rightSide);
|
OperatorType op, double rightSide);
|
||||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
OperatorType op, double rightSide);
|
OperatorType op, double rightSide);
|
||||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
OperatorType op, double rightSide);
|
OperatorType op, double rightSide);
|
||||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
double coeff3, Variable* var3,
|
double coeff3, Variable* var3,
|
||||||
OperatorType op, double rightSide);
|
OperatorType op, double rightSide);
|
||||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
double coeff3, Variable* var3,
|
double coeff3, Variable* var3,
|
||||||
double coeff4, Variable* var4,
|
double coeff4, Variable* var4,
|
||||||
OperatorType op, double rightSide);
|
OperatorType op, double rightSide);
|
||||||
|
|
||||||
SoftConstraint* AddSoftConstraint(BList* coeffs, BList* vars,
|
Constraint* AddConstraint(BList* summands,
|
||||||
OperatorType op, double rightSide,
|
OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
OperatorType op, double rightSide,
|
OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
OperatorType op, double rightSide,
|
OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
double coeff3, Variable* var3,
|
double coeff3, Variable* var3,
|
||||||
OperatorType op, double rightSide,
|
OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
double coeff3, Variable* var3,
|
double coeff3, Variable* var3,
|
||||||
double coeff4, Variable* var4,
|
double coeff4, Variable* var4,
|
||||||
OperatorType op, double rightSide,
|
OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
|
|
||||||
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
|
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
|
||||||
void RemovePresolved();
|
void RemovePresolved();
|
||||||
ResultType Presolve();
|
ResultType Presolve();
|
||||||
ResultType Solve();
|
ResultType Solve();
|
||||||
void Save(char* fname);
|
void Save(char* fname);
|
||||||
|
|
||||||
int32 Columns() const;
|
int32 Columns() const;
|
||||||
void SetColumns(int32 value);
|
void SetColumns(int32 value);
|
||||||
OptimizationType Optimization() const;
|
OptimizationType Optimization() const;
|
||||||
void SetOptimization(OptimizationType value);
|
void SetOptimization(OptimizationType value);
|
||||||
lprec* LP() const;
|
lprec* LP() const;
|
||||||
void SetLP(lprec* value);
|
void SetLP(lprec* value);
|
||||||
BList* ObjFunctionSummands() const;
|
BList* ObjFunctionSummands() const;
|
||||||
void SetObjFunctionSummands(BList* value);
|
void SetObjFunctionSummands(BList* value);
|
||||||
BList* Variables() const;
|
BList* Variables() const;
|
||||||
void SetVariables(BList* value);
|
void SetVariables(BList* value);
|
||||||
BList* Constraints() const;
|
BList* Constraints() const;
|
||||||
void SetConstraints(BList* value);
|
void SetConstraints(BList* value);
|
||||||
ResultType Result() const;
|
ResultType Result() const;
|
||||||
void SetResult(ResultType value);
|
void SetResult(ResultType value);
|
||||||
double ObjectiveValue() const;
|
double ObjectiveValue() const;
|
||||||
void SetObjectiveValue(double value);
|
void SetObjectiveValue(double value);
|
||||||
double SolvingTime() const;
|
double SolvingTime() const;
|
||||||
void SetSolvingTime(double value);
|
void SetSolvingTime(double value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32 fColumns;
|
int32 fColumns;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
lprec* fLpPresolved;
|
lprec* fLpPresolved;
|
||||||
OptimizationType fOptimization;
|
OptimizationType fOptimization;
|
||||||
lprec* fLP;
|
lprec* fLP;
|
||||||
BList* fObjFunctionSummands;
|
BList* fObjFunctionSummands;
|
||||||
BList* fVariables;
|
BList* fVariables;
|
||||||
@@ -112,8 +118,8 @@ private:
|
|||||||
double fSolvingTime; // = Double.Nan
|
double fSolvingTime; // = Double.Nan
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class ObjFunctionSummand;
|
friend class ObjFunctionSummand;
|
||||||
friend class SoftConstraint;
|
friend class Constraint;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef OBJ_FUNCTION_SUMMAND_H
|
#ifndef OBJ_FUNCTION_SUMMAND_H
|
||||||
#define OBJ_FUNCTION_SUMMAND_H
|
#define OBJ_FUNCTION_SUMMAND_H
|
||||||
|
|
||||||
|
#include "Summand.h"
|
||||||
|
|
||||||
|
|
||||||
namespace LinearProgramming {
|
namespace LinearProgramming {
|
||||||
|
|
||||||
@@ -10,25 +18,21 @@ class Variable;
|
|||||||
/**
|
/**
|
||||||
* A summand of the objective function.
|
* A summand of the objective function.
|
||||||
*/
|
*/
|
||||||
class ObjFunctionSummand {
|
class ObjFunctionSummand : public Summand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
double Coeff();
|
void SetCoeff(double coeff);
|
||||||
void SetCoeff(double coeff);
|
void SetVar(Variable* var);
|
||||||
Variable* Var();
|
~ObjFunctionSummand();
|
||||||
void SetVar(Variable* var);
|
|
||||||
~ObjFunctionSummand();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var);
|
ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinearSpec* fLS;
|
LinearSpec* fLS;
|
||||||
double fCoeff;
|
|
||||||
Variable* fVar;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class LinearSpec;
|
friend class LinearSpec;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef OPERATOR_TYPE_H
|
#ifndef OPERATOR_TYPE_H
|
||||||
#define OPERATOR_TYPE_H
|
#define OPERATOR_TYPE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef OPTIMIZATION_TYPE_H
|
#ifndef OPTIMIZATION_TYPE_H
|
||||||
#define OPTIMIZATION_TYPE_H
|
#define OPTIMIZATION_TYPE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef PENALTY_FUNCTION_H
|
#ifndef PENALTY_FUNCTION_H
|
||||||
#define PENALTY_FUNCTION_H
|
#define PENALTY_FUNCTION_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RESULT_TYPE_H
|
#ifndef RESULT_TYPE_H
|
||||||
#define RESULT_TYPE_H
|
#define RESULT_TYPE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
#ifndef SOFT_CONSTRAINT_H
|
|
||||||
#define SOFT_CONSTRAINT_H
|
|
||||||
|
|
||||||
#include "Constraint.h"
|
|
||||||
|
|
||||||
#include <List.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace LinearProgramming {
|
|
||||||
|
|
||||||
class LinearSpec;
|
|
||||||
class ObjFunctionSummand;
|
|
||||||
class Variable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Soft constraint, i.e. one that does not necessarily have to be satisfied.
|
|
||||||
* Use this instead of hard constraints to avoid over-constrained specifications.
|
|
||||||
*/
|
|
||||||
class SoftConstraint : public Constraint {
|
|
||||||
|
|
||||||
public:
|
|
||||||
void ChangeLeftSide(BList* coeffs, BList* vars);
|
|
||||||
OperatorType Op();
|
|
||||||
void SetOp(OperatorType value);
|
|
||||||
double PenaltyNeg();
|
|
||||||
void SetPenaltyNeg(double value);
|
|
||||||
double PenaltyPos();
|
|
||||||
void SetPenaltyPos(double value);
|
|
||||||
//~ string ToString();
|
|
||||||
Variable* DNeg() const;
|
|
||||||
Variable* DPos() const;
|
|
||||||
~SoftConstraint();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SoftConstraint(LinearSpec* ls, BList* coeffs, BList* vars,
|
|
||||||
OperatorType op, double rightSide,
|
|
||||||
double penaltyNeg, double penaltyPos);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Variable* fDNeg;
|
|
||||||
Variable* fDPos;
|
|
||||||
ObjFunctionSummand* fDNegSummand;
|
|
||||||
ObjFunctionSummand* fDPosSummand;
|
|
||||||
|
|
||||||
public:
|
|
||||||
friend class LinearSpec;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace LinearProgramming
|
|
||||||
|
|
||||||
using LinearProgramming::SoftConstraint;
|
|
||||||
|
|
||||||
#endif // SOFT_CONSTRAINT_H
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SUMMAND_H
|
||||||
|
#define SUMMAND_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace LinearProgramming {
|
||||||
|
|
||||||
|
class LinearSpec;
|
||||||
|
class Variable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A summand of a linear term.
|
||||||
|
*/
|
||||||
|
class Summand {
|
||||||
|
|
||||||
|
public:
|
||||||
|
double Coeff();
|
||||||
|
void SetCoeff(double coeff);
|
||||||
|
Variable* Var();
|
||||||
|
void SetVar(Variable* var);
|
||||||
|
Summand(double coeff, Variable* var);
|
||||||
|
~Summand();
|
||||||
|
|
||||||
|
private:
|
||||||
|
double fCoeff;
|
||||||
|
Variable* fVar;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace LinearProgramming
|
||||||
|
|
||||||
|
using LinearProgramming::Summand;
|
||||||
|
|
||||||
|
#endif // OBJ_FUNCTION_SUMMAND_H
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef VARIABLE_H
|
#ifndef VARIABLE_H
|
||||||
#define VARIABLE_H
|
#define VARIABLE_H
|
||||||
|
|
||||||
@@ -17,15 +23,15 @@ class Variable {
|
|||||||
public:
|
public:
|
||||||
int32 Index();
|
int32 Index();
|
||||||
LinearSpec* LS() const;
|
LinearSpec* LS() const;
|
||||||
void SetLS(LinearSpec* value);
|
void SetLS(LinearSpec* value);
|
||||||
double Value() const;
|
double Value() const;
|
||||||
void SetValue(double value);
|
void SetValue(double value);
|
||||||
double Min() const;
|
double Min() const;
|
||||||
void SetMin(double min);
|
void SetMin(double min);
|
||||||
double Max() const;
|
double Max() const;
|
||||||
void SetMax(double max);
|
void SetMax(double max);
|
||||||
void SetRange(double min, double max);
|
void SetRange(double min, double max);
|
||||||
//~ string ToString();
|
//~ string ToString();
|
||||||
Constraint* IsEqual(Variable* var);
|
Constraint* IsEqual(Variable* var);
|
||||||
Constraint* IsSmallerOrEqual(Variable* var);
|
Constraint* IsSmallerOrEqual(Variable* var);
|
||||||
Constraint* IsGreaterorEqual(Variable* var);
|
Constraint* IsGreaterorEqual(Variable* var);
|
||||||
@@ -42,7 +48,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
friend class LinearSpec;
|
friend class LinearSpec;
|
||||||
friend class SoftConstraint;
|
friend class Constraint;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+64
-343
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||||
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Area.h"
|
#include "Area.h"
|
||||||
#include "Column.h"
|
#include "Column.h"
|
||||||
#include "BALMLayout.h"
|
#include "BALMLayout.h"
|
||||||
@@ -71,23 +77,10 @@ Area::SetLeft(XTab* left)
|
|||||||
fColumn = NULL;
|
fColumn = NULL;
|
||||||
|
|
||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
BList* coeffs = new BList(2);
|
fMinContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
fMinContentWidth->ChangeLeftSide(coeffs, vars);
|
|
||||||
|
|
||||||
if (fMaxContentWidth != NULL) {
|
if (fMaxContentWidth != NULL)
|
||||||
BList* coeffs2 = new BList(2);
|
fMaxContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fLeft);
|
|
||||||
vars2->AddItem(fRight);
|
|
||||||
fMaxContentWidth->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
fLS->InvalidateLayout();
|
||||||
@@ -119,23 +112,10 @@ Area::SetRight(XTab* right)
|
|||||||
fColumn = NULL;
|
fColumn = NULL;
|
||||||
|
|
||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
BList* coeffs = new BList(2);
|
fMinContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
fMinContentWidth->ChangeLeftSide(coeffs, vars);
|
|
||||||
|
|
||||||
if (fMaxContentWidth != NULL) {
|
if (fMaxContentWidth != NULL)
|
||||||
BList* coeffs2 = new BList(2);
|
fMaxContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fLeft);
|
|
||||||
vars2->AddItem(fRight);
|
|
||||||
fMaxContentWidth->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
fLS->InvalidateLayout();
|
||||||
@@ -163,23 +143,10 @@ Area::SetTop(YTab* top)
|
|||||||
fRow = NULL;
|
fRow = NULL;
|
||||||
|
|
||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
BList* coeffs = new BList(2);
|
fMinContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fTop);
|
|
||||||
vars->AddItem(fBottom);
|
|
||||||
fMinContentHeight->ChangeLeftSide(coeffs, vars);
|
|
||||||
|
|
||||||
if (fMaxContentHeight != NULL) {
|
if (fMaxContentHeight != NULL)
|
||||||
BList* coeffs2 = new BList(2);
|
fMaxContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fTop);
|
|
||||||
vars2->AddItem(fBottom);
|
|
||||||
fMaxContentHeight->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fLS->InvalidateLayout();
|
||||||
@@ -207,23 +174,10 @@ Area::SetBottom(YTab* bottom)
|
|||||||
fRow = NULL;
|
fRow = NULL;
|
||||||
|
|
||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
BList* coeffs = new BList(2);
|
fMinContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fTop);
|
|
||||||
vars->AddItem(fBottom);
|
|
||||||
fMinContentHeight->ChangeLeftSide(coeffs, vars);
|
|
||||||
|
|
||||||
if (fMaxContentHeight != NULL) {
|
if (fMaxContentHeight != NULL)
|
||||||
BList* coeffs2 = new BList(2);
|
fMaxContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fTop);
|
|
||||||
vars2->AddItem(fBottom);
|
|
||||||
fMaxContentHeight->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fLS->InvalidateLayout();
|
||||||
@@ -385,23 +339,11 @@ Area::SetMaxContentSize(BSize max)
|
|||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
fMaxContentSize = max;
|
fMaxContentSize = max;
|
||||||
if (fMaxContentWidth == NULL) {
|
if (fMaxContentWidth == NULL) {
|
||||||
BList* coeffs = new BList(2);
|
fMaxContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(LE),
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
fMaxContentWidth = fLS->AddConstraint(coeffs, vars, OperatorType(LE),
|
|
||||||
fMaxContentSize.Width());
|
fMaxContentSize.Width());
|
||||||
fConstraints->AddItem(fMaxContentWidth);
|
fConstraints->AddItem(fMaxContentWidth);
|
||||||
|
|
||||||
BList* coeffs2 = new BList(2);
|
fMaxContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, OperatorType(LE),
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fTop);
|
|
||||||
vars2->AddItem(fBottom);
|
|
||||||
fMaxContentHeight = fLS->AddConstraint(coeffs2, vars2, OperatorType(LE),
|
|
||||||
fMaxContentSize.Height());
|
fMaxContentSize.Height());
|
||||||
fConstraints->AddItem(fMaxContentHeight);
|
fConstraints->AddItem(fMaxContentHeight);
|
||||||
} else {
|
} else {
|
||||||
@@ -435,24 +377,12 @@ Area::SetPrefContentSize(BSize pref)
|
|||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
fPrefContentSize = pref;
|
fPrefContentSize = pref;
|
||||||
if (fPrefContentWidth == NULL) {
|
if (fPrefContentWidth == NULL) {
|
||||||
BList* coeffs = new BList(2);
|
fPrefContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(EQ),
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
fPrefContentWidth = fLS->AddSoftConstraint(coeffs, vars, OperatorType(EQ),
|
|
||||||
fPrefContentSize.Width(), fShrinkRigidity.Width(),
|
fPrefContentSize.Width(), fShrinkRigidity.Width(),
|
||||||
fExpandRigidity.Width());
|
fExpandRigidity.Width());
|
||||||
fConstraints->AddItem(fPrefContentWidth);
|
fConstraints->AddItem(fPrefContentWidth);
|
||||||
|
|
||||||
BList* coeffs2 = new BList(2);
|
fPrefContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, OperatorType(EQ),
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fTop);
|
|
||||||
vars2->AddItem(fBottom);
|
|
||||||
fPrefContentHeight = fLS->AddSoftConstraint(coeffs2, vars2, OperatorType(EQ),
|
|
||||||
fPrefContentSize.Height(), fShrinkRigidity.Height(),
|
fPrefContentSize.Height(), fShrinkRigidity.Height(),
|
||||||
fExpandRigidity.Height());
|
fExpandRigidity.Height());
|
||||||
fConstraints->AddItem(fPrefContentHeight);
|
fConstraints->AddItem(fPrefContentHeight);
|
||||||
@@ -536,31 +466,13 @@ Area::SetContentAspectRatio(double ratio)
|
|||||||
if (fChildArea == NULL) {
|
if (fChildArea == NULL) {
|
||||||
fContentAspectRatio = ratio;
|
fContentAspectRatio = ratio;
|
||||||
if (fContentAspectRatioC == NULL) {
|
if (fContentAspectRatioC == NULL) {
|
||||||
BList* coeffs = new BList(4);
|
fContentAspectRatioC = fLS->AddConstraint(
|
||||||
coeffs->AddItem(new double(-1.0));
|
-1.0, fLeft, 1.0, fRight, ratio, fTop, -ratio, fBottom,
|
||||||
coeffs->AddItem(new double(1.0));
|
OperatorType(EQ), 0.0);
|
||||||
coeffs->AddItem(new double(ratio));
|
|
||||||
coeffs->AddItem(new double(-ratio));
|
|
||||||
BList* vars = new BList(4);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
vars->AddItem(fTop);
|
|
||||||
vars->AddItem(fBottom);
|
|
||||||
fContentAspectRatioC = fLS->AddConstraint(coeffs, vars,
|
|
||||||
OperatorType(EQ), 0.0);
|
|
||||||
fConstraints->AddItem(fContentAspectRatioC);
|
fConstraints->AddItem(fContentAspectRatioC);
|
||||||
} else {
|
} else {
|
||||||
BList* coeffs2 = new BList(4);
|
fContentAspectRatioC->ChangeLeftSide(
|
||||||
coeffs2->AddItem(new double(-1.0));
|
-1.0, fLeft, 1.0, fRight, ratio, fTop, -ratio, fBottom);
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
coeffs2->AddItem(new double(ratio));
|
|
||||||
coeffs2->AddItem(new double(-ratio));
|
|
||||||
BList* vars2 = new BList(4);
|
|
||||||
vars2->AddItem(fLeft);
|
|
||||||
vars2->AddItem(fRight);
|
|
||||||
vars2->AddItem(fTop);
|
|
||||||
vars2->AddItem(fBottom);
|
|
||||||
fContentAspectRatioC->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
fChildArea->SetContentAspectRatio(ratio);
|
fChildArea->SetContentAspectRatio(ratio);
|
||||||
@@ -586,7 +498,6 @@ Area::SetAlignment(BAlignment alignment)
|
|||||||
{
|
{
|
||||||
fAlignment = alignment;
|
fAlignment = alignment;
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fLS->InvalidateLayout();
|
||||||
}
|
}
|
||||||
@@ -751,17 +662,9 @@ Area::SetDefaultPrefContentSize()
|
|||||||
Constraint*
|
Constraint*
|
||||||
Area::HasSameWidthAs(Area* area)
|
Area::HasSameWidthAs(Area* area)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(4);
|
return fLS->AddConstraint(
|
||||||
coeffs->AddItem(new double(-1.0));
|
-1.0, fLeft, 1.0, fRight, 1.0, area->fLeft, -1.0, area->fRight,
|
||||||
coeffs->AddItem(new double(1.0));
|
OperatorType(EQ), 0.0);
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
BList* vars = new BList(4);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
vars->AddItem(area->fLeft);
|
|
||||||
vars->AddItem(area->fRight);
|
|
||||||
return fLS->AddConstraint(coeffs, vars, OperatorType(EQ), 0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -774,17 +677,9 @@ Area::HasSameWidthAs(Area* area)
|
|||||||
Constraint*
|
Constraint*
|
||||||
Area::HasSameHeightAs(Area* area)
|
Area::HasSameHeightAs(Area* area)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(4);
|
return fLS->AddConstraint(
|
||||||
coeffs->AddItem(new double(-1.0));
|
-1.0, fTop, 1.0, fBottom, 1.0, area->fTop, -1.0, area->fBottom,
|
||||||
coeffs->AddItem(new double(1.0));
|
OperatorType(EQ), 0.0);
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
BList* vars = new BList(4);
|
|
||||||
vars->AddItem(fTop);
|
|
||||||
vars->AddItem(fBottom);
|
|
||||||
vars->AddItem(area->fTop);
|
|
||||||
vars->AddItem(area->fBottom);
|
|
||||||
return fLS->AddConstraint(coeffs, vars, OperatorType(EQ), 0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -891,23 +786,11 @@ Area::Init(BALMLayout* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|||||||
|
|
||||||
// adds the two essential constraints of the area that make sure that the left x-tab is
|
// adds the two essential constraints of the area that make sure that the left x-tab is
|
||||||
// really to the left of the right x-tab, and the top y-tab really above the bottom y-tab
|
// really to the left of the right x-tab, and the top y-tab really above the bottom y-tab
|
||||||
BList* coeffs = new BList(2);
|
fMinContentWidth = ls->AddConstraint(-1.0, left, 1.0, right, OperatorType(GE),
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(left);
|
|
||||||
vars->AddItem(right);
|
|
||||||
fMinContentWidth = ls->AddConstraint(coeffs, vars, OperatorType(GE),
|
|
||||||
minContentSize.Width());
|
minContentSize.Width());
|
||||||
fConstraints->AddItem(fMinContentWidth);
|
fConstraints->AddItem(fMinContentWidth);
|
||||||
|
|
||||||
BList* coeffs2 = new BList(2);
|
fMinContentHeight = ls->AddConstraint(-1.0, top, 1.0, bottom, OperatorType(GE),
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(top);
|
|
||||||
vars2->AddItem(bottom);
|
|
||||||
fMinContentHeight = ls->AddConstraint(coeffs2, vars2, OperatorType(GE),
|
|
||||||
minContentSize.Height());
|
minContentSize.Height());
|
||||||
fConstraints->AddItem(fMinContentHeight);
|
fConstraints->AddItem(fMinContentHeight);
|
||||||
}
|
}
|
||||||
@@ -946,13 +829,13 @@ Area::InitChildArea()
|
|||||||
// coresponding tabs of this area (for a start)
|
// coresponding tabs of this area (for a start)
|
||||||
fChildArea = new Area(fLS, new XTab(fLS), new YTab(fLS), new XTab(fLS),
|
fChildArea = new Area(fLS, new XTab(fLS), new YTab(fLS), new XTab(fLS),
|
||||||
new YTab(fLS), fContent, BSize(0, 0));
|
new YTab(fLS), fContent, BSize(0, 0));
|
||||||
fLeftConstraint = Left()->IsEqual(fChildArea->Left());
|
fLeftConstraint = fLeft->IsEqual(fChildArea->Left());
|
||||||
fConstraints->AddItem(fLeftConstraint);
|
fConstraints->AddItem(fLeftConstraint);
|
||||||
fTopConstraint = Top()->IsEqual(fChildArea->Top());
|
fTopConstraint = fTop->IsEqual(fChildArea->Top());
|
||||||
fConstraints->AddItem(fTopConstraint);
|
fConstraints->AddItem(fTopConstraint);
|
||||||
fRightConstraint = Right()->IsEqual(fChildArea->Right());
|
fRightConstraint = fRight->IsEqual(fChildArea->Right());
|
||||||
fConstraints->AddItem(fRightConstraint);
|
fConstraints->AddItem(fRightConstraint);
|
||||||
fBottomConstraint = Bottom()->IsEqual(fChildArea->Bottom());
|
fBottomConstraint = fBottom->IsEqual(fChildArea->Bottom());
|
||||||
fConstraints->AddItem(fBottomConstraint);
|
fConstraints->AddItem(fBottomConstraint);
|
||||||
|
|
||||||
// remove the minimum content size constraints from this area
|
// remove the minimum content size constraints from this area
|
||||||
@@ -972,22 +855,10 @@ Area::InitChildArea()
|
|||||||
fChildArea->fMaxContentSize = fMaxContentSize;
|
fChildArea->fMaxContentSize = fMaxContentSize;
|
||||||
|
|
||||||
fChildArea->fMaxContentWidth = fMaxContentWidth;
|
fChildArea->fMaxContentWidth = fMaxContentWidth;
|
||||||
BList* coeffs = new BList(2);
|
fMaxContentWidth->ChangeLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(fChildArea->Left());
|
|
||||||
vars->AddItem(fChildArea->Right());
|
|
||||||
fMaxContentWidth->ChangeLeftSide(coeffs, vars);
|
|
||||||
|
|
||||||
fChildArea->fMaxContentHeight = fMaxContentHeight;
|
fChildArea->fMaxContentHeight = fMaxContentHeight;
|
||||||
BList* coeffs2 = new BList(2);
|
fMaxContentHeight->ChangeLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
BList* vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Top());
|
|
||||||
vars2->AddItem(fChildArea->Bottom());
|
|
||||||
fMaxContentHeight->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are preferred content size constraints on this area,
|
// if there are preferred content size constraints on this area,
|
||||||
@@ -999,22 +870,10 @@ Area::InitChildArea()
|
|||||||
fChildArea->fExpandRigidity = fExpandRigidity;
|
fChildArea->fExpandRigidity = fExpandRigidity;
|
||||||
|
|
||||||
fChildArea->fPrefContentWidth = fPrefContentWidth;
|
fChildArea->fPrefContentWidth = fPrefContentWidth;
|
||||||
BList* coeffs3 = new BList(2);
|
fPrefContentWidth->ChangeLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
|
||||||
coeffs3->AddItem(new double(-1.0));
|
|
||||||
coeffs3->AddItem(new double(1.0));
|
|
||||||
BList* vars3 = new BList(2);
|
|
||||||
vars3->AddItem(fChildArea->Left());
|
|
||||||
vars3->AddItem(fChildArea->Right());
|
|
||||||
fPrefContentWidth->ChangeLeftSide(coeffs3, vars3);
|
|
||||||
|
|
||||||
fChildArea->fPrefContentHeight = fPrefContentHeight;
|
fChildArea->fPrefContentHeight = fPrefContentHeight;
|
||||||
BList* coeffs4 = new BList(2);
|
fPrefContentHeight->ChangeLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
|
||||||
coeffs4->AddItem(new double(-1.0));
|
|
||||||
coeffs4->AddItem(new double(1.0));
|
|
||||||
BList* vars4 = new BList(2);
|
|
||||||
vars4->AddItem(fChildArea->Top());
|
|
||||||
vars4->AddItem(fChildArea->Bottom());
|
|
||||||
fPrefContentHeight->ChangeLeftSide(coeffs4, vars4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1028,116 +887,47 @@ Area::UpdateHorizontal()
|
|||||||
// if the area does not have a childAdrea yet, this is the time to add it
|
// if the area does not have a childAdrea yet, this is the time to add it
|
||||||
if (fChildArea == NULL)
|
if (fChildArea == NULL)
|
||||||
InitChildArea();
|
InitChildArea();
|
||||||
|
|
||||||
BList* coeffs;
|
|
||||||
BList* coeffs2;
|
|
||||||
BList* vars;
|
|
||||||
BList* vars2;
|
|
||||||
|
|
||||||
// change the constraints leftConstraint and rightConstraint so that the horizontal
|
// change the constraints leftConstraint and rightConstraint so that the horizontal
|
||||||
// alignment and insets of the childArea within this area are as specified by the user
|
// alignment and insets of the childArea within this area are as specified by the user
|
||||||
if (fAlignment.Horizontal() == B_ALIGN_LEFT) {
|
if (fAlignment.Horizontal() == B_ALIGN_LEFT) {
|
||||||
coeffs = new BList(2);
|
fLeftConstraint->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Left());
|
|
||||||
vars->AddItem(fChildArea->Left());
|
|
||||||
fLeftConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fLeftConstraint->SetOp(OperatorType(EQ));
|
fLeftConstraint->SetOp(OperatorType(EQ));
|
||||||
fLeftConstraint->SetRightSide(fLeftInset);
|
fLeftConstraint->SetRightSide(fLeftInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fRightConstraint->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Right());
|
|
||||||
vars2->AddItem(Right());
|
|
||||||
fRightConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fRightConstraint->SetOp(OperatorType(GE));
|
fRightConstraint->SetOp(OperatorType(GE));
|
||||||
fRightConstraint->SetRightSide(fRightInset);
|
fRightConstraint->SetRightSide(fRightInset);
|
||||||
} else if (fAlignment.Horizontal() == B_ALIGN_RIGHT) {
|
} else if (fAlignment.Horizontal() == B_ALIGN_RIGHT) {
|
||||||
coeffs = new BList(2);
|
fLeftConstraint->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Left());
|
|
||||||
vars->AddItem(fChildArea->Left());
|
|
||||||
fLeftConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fLeftConstraint->SetOp(OperatorType(GE));
|
fLeftConstraint->SetOp(OperatorType(GE));
|
||||||
fLeftConstraint->SetRightSide(fLeftInset);
|
fLeftConstraint->SetRightSide(fLeftInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fRightConstraint->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Right());
|
|
||||||
vars2->AddItem(Right());
|
|
||||||
fRightConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fRightConstraint->SetOp(OperatorType(EQ));
|
fRightConstraint->SetOp(OperatorType(EQ));
|
||||||
fRightConstraint->SetRightSide(fRightInset);
|
fRightConstraint->SetRightSide(fRightInset);
|
||||||
} else if (fAlignment.Horizontal() == B_ALIGN_HORIZONTAL_CENTER) {
|
} else if (fAlignment.Horizontal() == B_ALIGN_HORIZONTAL_CENTER) {
|
||||||
coeffs = new BList(2);
|
fLeftConstraint->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Left());
|
|
||||||
vars->AddItem(fChildArea->Left());
|
|
||||||
fLeftConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fLeftConstraint->SetOp(OperatorType(GE));
|
fLeftConstraint->SetOp(OperatorType(GE));
|
||||||
fLeftConstraint->SetRightSide(max(fLeftInset, fRightInset));
|
fLeftConstraint->SetRightSide(max(fLeftInset, fRightInset));
|
||||||
|
|
||||||
coeffs2 = new BList(4);
|
fRightConstraint->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left(), 1.0, fChildArea->Right(), -1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
vars2 = new BList(4);
|
|
||||||
vars2->AddItem(Left());
|
|
||||||
vars2->AddItem(fChildArea->Left());
|
|
||||||
vars2->AddItem(fChildArea->Right());
|
|
||||||
vars2->AddItem(Right());
|
|
||||||
fRightConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fRightConstraint->SetOp(OperatorType(EQ));
|
fRightConstraint->SetOp(OperatorType(EQ));
|
||||||
fRightConstraint->SetRightSide(0);
|
fRightConstraint->SetRightSide(0);
|
||||||
} else if (fAlignment.Horizontal() == B_ALIGN_USE_FULL_WIDTH) {
|
} else if (fAlignment.Horizontal() == B_ALIGN_USE_FULL_WIDTH) {
|
||||||
coeffs = new BList(2);
|
fLeftConstraint->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Left());
|
|
||||||
vars->AddItem(fChildArea->Left());
|
|
||||||
fLeftConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fLeftConstraint->SetOp(OperatorType(EQ));
|
fLeftConstraint->SetOp(OperatorType(EQ));
|
||||||
fLeftConstraint->SetRightSide(fLeftInset);
|
fLeftConstraint->SetRightSide(fLeftInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fRightConstraint->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Right());
|
|
||||||
vars2->AddItem(Right());
|
|
||||||
fRightConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fRightConstraint->SetOp(OperatorType(EQ));
|
fRightConstraint->SetOp(OperatorType(EQ));
|
||||||
fRightConstraint->SetRightSide(fRightInset);
|
fRightConstraint->SetRightSide(fRightInset);
|
||||||
} else if (fAlignment.Horizontal() == B_ALIGN_HORIZONTAL_UNSET) {
|
} else if (fAlignment.Horizontal() == B_ALIGN_HORIZONTAL_UNSET) {
|
||||||
coeffs = new BList(2);
|
fLeftConstraint->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Left());
|
|
||||||
vars->AddItem(fChildArea->Left());
|
|
||||||
fLeftConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fLeftConstraint->SetOp(OperatorType(GE));
|
fLeftConstraint->SetOp(OperatorType(GE));
|
||||||
fLeftConstraint->SetRightSide(fLeftInset);
|
fLeftConstraint->SetRightSide(fLeftInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fRightConstraint->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Right());
|
|
||||||
vars2->AddItem(Right());
|
|
||||||
fRightConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fRightConstraint->SetOp(OperatorType(GE));
|
fRightConstraint->SetOp(OperatorType(GE));
|
||||||
fRightConstraint->SetRightSide(fRightInset);
|
fRightConstraint->SetRightSide(fRightInset);
|
||||||
}
|
}
|
||||||
@@ -1152,115 +942,46 @@ void Area::UpdateVertical() {
|
|||||||
if (fChildArea == NULL)
|
if (fChildArea == NULL)
|
||||||
InitChildArea();
|
InitChildArea();
|
||||||
|
|
||||||
BList* coeffs;
|
|
||||||
BList* coeffs2;
|
|
||||||
BList* vars;
|
|
||||||
BList* vars2;
|
|
||||||
|
|
||||||
// change the constraints topConstraint and bottomConstraint so that the vertical
|
// change the constraints topConstraint and bottomConstraint so that the vertical
|
||||||
// alignment and insets of the childArea within this area are as specified by the user
|
// alignment and insets of the childArea within this area are as specified by the user
|
||||||
if (fAlignment.Vertical() == B_ALIGN_TOP) {
|
if (fAlignment.Vertical() == B_ALIGN_TOP) {
|
||||||
coeffs = new BList(2);
|
fTopConstraint->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Top());
|
|
||||||
vars->AddItem(fChildArea->Top());
|
|
||||||
fTopConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fTopConstraint->SetOp(OperatorType(EQ));
|
fTopConstraint->SetOp(OperatorType(EQ));
|
||||||
fTopConstraint->SetRightSide(fTopInset);
|
fTopConstraint->SetRightSide(fTopInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fBottomConstraint->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Bottom());
|
|
||||||
vars2->AddItem(Bottom());
|
|
||||||
fBottomConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fBottomConstraint->SetOp(OperatorType(GE));
|
fBottomConstraint->SetOp(OperatorType(GE));
|
||||||
fBottomConstraint->SetRightSide(fBottomInset);
|
fBottomConstraint->SetRightSide(fBottomInset);
|
||||||
} else if (fAlignment.Vertical() == B_ALIGN_BOTTOM) {
|
} else if (fAlignment.Vertical() == B_ALIGN_BOTTOM) {
|
||||||
coeffs = new BList(2);
|
fTopConstraint->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Top());
|
|
||||||
vars->AddItem(fChildArea->Top());
|
|
||||||
fTopConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fTopConstraint->SetOp(OperatorType(GE));
|
fTopConstraint->SetOp(OperatorType(GE));
|
||||||
fTopConstraint->SetRightSide(fTopInset);
|
fTopConstraint->SetRightSide(fTopInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fBottomConstraint->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Bottom());
|
|
||||||
vars2->AddItem(Bottom());
|
|
||||||
fBottomConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fBottomConstraint->SetOp(OperatorType(EQ));
|
fBottomConstraint->SetOp(OperatorType(EQ));
|
||||||
fBottomConstraint->SetRightSide(fBottomInset);
|
fBottomConstraint->SetRightSide(fBottomInset);
|
||||||
} else if (fAlignment.Vertical() == B_ALIGN_VERTICAL_CENTER) {
|
} else if (fAlignment.Vertical() == B_ALIGN_VERTICAL_CENTER) {
|
||||||
coeffs = new BList(2);
|
fTopConstraint->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Top());
|
|
||||||
vars->AddItem(fChildArea->Top());
|
|
||||||
fTopConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fTopConstraint->SetOp(OperatorType(GE));
|
fTopConstraint->SetOp(OperatorType(GE));
|
||||||
fTopConstraint->SetRightSide(max(fTopInset, fBottomInset));
|
fTopConstraint->SetRightSide(max(fTopInset, fBottomInset));
|
||||||
|
|
||||||
coeffs2 = new BList(4);
|
fBottomConstraint->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top(), 1.0, fChildArea->Bottom(), -1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
vars2 = new BList(4);
|
|
||||||
vars2->AddItem(Top());
|
|
||||||
vars2->AddItem(fChildArea->Top());
|
|
||||||
vars2->AddItem(fChildArea->Bottom());
|
|
||||||
vars2->AddItem(Bottom());
|
|
||||||
fBottomConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fBottomConstraint->SetOp(OperatorType(EQ));
|
fBottomConstraint->SetOp(OperatorType(EQ));
|
||||||
fBottomConstraint->SetRightSide(0);
|
fBottomConstraint->SetRightSide(0);
|
||||||
} else if (fAlignment.Vertical() == B_ALIGN_USE_FULL_HEIGHT) {
|
} else if (fAlignment.Vertical() == B_ALIGN_USE_FULL_HEIGHT) {
|
||||||
coeffs = new BList(2);
|
fTopConstraint->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Top());
|
|
||||||
vars->AddItem(fChildArea->Top());
|
|
||||||
fTopConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fTopConstraint->SetOp(OperatorType(EQ));
|
fTopConstraint->SetOp(OperatorType(EQ));
|
||||||
fTopConstraint->SetRightSide(fTopInset);
|
fTopConstraint->SetRightSide(fTopInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fBottomConstraint->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Bottom());
|
|
||||||
vars2->AddItem(Bottom());
|
|
||||||
fBottomConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fBottomConstraint->SetOp(OperatorType(EQ));
|
fBottomConstraint->SetOp(OperatorType(EQ));
|
||||||
fBottomConstraint->SetRightSide(fBottomInset);
|
fBottomConstraint->SetRightSide(fBottomInset);
|
||||||
} else if (fAlignment.Vertical() == B_ALIGN_VERTICAL_UNSET) {
|
} else if (fAlignment.Vertical() == B_ALIGN_VERTICAL_UNSET) {
|
||||||
coeffs = new BList(2);
|
fTopConstraint->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
vars = new BList(2);
|
|
||||||
vars->AddItem(Top());
|
|
||||||
vars->AddItem(fChildArea->Top());
|
|
||||||
fTopConstraint->ChangeLeftSide(coeffs, vars);
|
|
||||||
fTopConstraint->SetOp(OperatorType(GE));
|
fTopConstraint->SetOp(OperatorType(GE));
|
||||||
fTopConstraint->SetRightSide(fTopInset);
|
fTopConstraint->SetRightSide(fTopInset);
|
||||||
|
|
||||||
coeffs2 = new BList(2);
|
fBottomConstraint->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||||
coeffs2->AddItem(new double(-1.0));
|
|
||||||
coeffs2->AddItem(new double(1.0));
|
|
||||||
vars2 = new BList(2);
|
|
||||||
vars2->AddItem(fChildArea->Bottom());
|
|
||||||
vars2->AddItem(Bottom());
|
|
||||||
fBottomConstraint->ChangeLeftSide(coeffs2, vars2);
|
|
||||||
fBottomConstraint->SetOp(OperatorType(GE));
|
fBottomConstraint->SetOp(OperatorType(GE));
|
||||||
fBottomConstraint->SetRightSide(fBottomInset);
|
fBottomConstraint->SetRightSide(fBottomInset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "BALMLayout.h"
|
#include "BALMLayout.h"
|
||||||
#include "Area.h"
|
#include "Area.h"
|
||||||
#include "Column.h"
|
#include "Column.h"
|
||||||
@@ -224,7 +230,7 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|||||||
View()->AddChild(content);
|
View()->AddChild(content);
|
||||||
Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0));
|
Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0));
|
||||||
area->SetDefaultPrefContentSize();
|
area->SetDefaultPrefContentSize();
|
||||||
area->SetAutoPrefContentSize(true);
|
area->SetAutoPrefContentSize(false);
|
||||||
fAreas->AddItem(area);
|
fAreas->AddItem(area);
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
@@ -246,7 +252,7 @@ BALMLayout::AddArea(Row* row, Column* column, BView* content)
|
|||||||
View()->AddChild(content);
|
View()->AddChild(content);
|
||||||
Area* area = new Area(this, row, column, content, BSize(0, 0));
|
Area* area = new Area(this, row, column, content, BSize(0, 0));
|
||||||
area->SetDefaultPrefContentSize();
|
area->SetDefaultPrefContentSize();
|
||||||
area->SetAutoPrefContentSize(true);
|
area->SetAutoPrefContentSize(false);
|
||||||
fAreas->AddItem(area);
|
fAreas->AddItem(area);
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-13
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Column.h"
|
#include "Column.h"
|
||||||
#include "BALMLayout.h"
|
#include "BALMLayout.h"
|
||||||
#include "OperatorType.h"
|
#include "OperatorType.h"
|
||||||
@@ -152,19 +158,9 @@ Column::InsertAfter(Column* column)
|
|||||||
Constraint*
|
Constraint*
|
||||||
Column::HasSameWidthAs(Column* column)
|
Column::HasSameWidthAs(Column* column)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(4);
|
Constraint* constraint = fLS->AddConstraint(
|
||||||
coeffs->AddItem(new double(-1.0));
|
-1.0, fLeft, 1.0, fRight, 1.0, column->fLeft, -1.0, column->fRight,
|
||||||
coeffs->AddItem(new double(1.0));
|
OperatorType(EQ), 0.0);
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(4);
|
|
||||||
vars->AddItem(fLeft);
|
|
||||||
vars->AddItem(fRight);
|
|
||||||
vars->AddItem(column->fLeft);
|
|
||||||
vars->AddItem(column->fRight);
|
|
||||||
|
|
||||||
Constraint* constraint = fLS->AddConstraint(coeffs, vars, OperatorType(EQ), 0.0);
|
|
||||||
fConstraints->AddItem(constraint);
|
fConstraints->AddItem(constraint);
|
||||||
return constraint;
|
return constraint;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-13
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Row.h"
|
#include "Row.h"
|
||||||
#include "BALMLayout.h"
|
#include "BALMLayout.h"
|
||||||
#include "OperatorType.h"
|
#include "OperatorType.h"
|
||||||
@@ -154,19 +160,9 @@ Row::InsertAfter(Row* row)
|
|||||||
Constraint*
|
Constraint*
|
||||||
Row::HasSameHeightAs(Row* row)
|
Row::HasSameHeightAs(Row* row)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(4);
|
Constraint* constraint = fLS->AddConstraint(
|
||||||
coeffs->AddItem(new double(-1.0));
|
-1.0, fTop, 1.0, fBottom, 1.0, row->fTop, -1.0, row->fBottom,
|
||||||
coeffs->AddItem(new double(1.0));
|
OperatorType(EQ), 0.0);
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(4);
|
|
||||||
vars->AddItem(fTop);
|
|
||||||
vars->AddItem(fBottom);
|
|
||||||
vars->AddItem(row->fTop);
|
|
||||||
vars->AddItem(row->fBottom);
|
|
||||||
|
|
||||||
Constraint* constraint = fLS->AddConstraint(coeffs, vars, OperatorType(EQ), 0.0);
|
|
||||||
fConstraints->AddItem(constraint);
|
fConstraints->AddItem(constraint);
|
||||||
return constraint;
|
return constraint;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "XTab.h"
|
#include "XTab.h"
|
||||||
#include "BALMLayout.h"
|
#include "BALMLayout.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "YTab.h"
|
#include "YTab.h"
|
||||||
#include "BALMLayout.h"
|
#include "BALMLayout.h"
|
||||||
|
|
||||||
|
|||||||
+246
-89
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
#include "LinearSpec.h"
|
#include "LinearSpec.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
@@ -21,26 +27,45 @@ Constraint::Index()
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the coefficients of the constraint.
|
* Gets the summands of the constraint.
|
||||||
*
|
*
|
||||||
* @return the coefficients of the constraint
|
* @return pointer to a BList containing the summands of the constraint
|
||||||
*/
|
*/
|
||||||
BList*
|
BList*
|
||||||
Constraint::Coeffs()
|
Constraint::Summands()
|
||||||
{
|
{
|
||||||
return fCoeffs;
|
return fSummands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
void
|
||||||
* Gets the variables of the constraint.
|
Constraint::_UpdateLeftSide()
|
||||||
*
|
|
||||||
* @return the variables of the constraint
|
|
||||||
*/
|
|
||||||
BList*
|
|
||||||
Constraint::Vars()
|
|
||||||
{
|
{
|
||||||
return fVars;
|
double coeffs[fSummands->CountItems() + 2];
|
||||||
|
int varIndexes[fSummands->CountItems() + 2];
|
||||||
|
int32 i;
|
||||||
|
for (i = 0; i < fSummands->CountItems(); i++) {
|
||||||
|
Summand* s = (Summand*)fSummands->ItemAt(i);
|
||||||
|
coeffs[i] = s->Coeff();
|
||||||
|
varIndexes[i] = s->Var()->Index();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fDNegSummand != NULL && fOp != OperatorType(LE)) {
|
||||||
|
varIndexes[i] = fDNegSummand->Var()->Index();
|
||||||
|
coeffs[i] = 1.0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fDPosSummand != NULL && fOp != OperatorType(GE)) {
|
||||||
|
varIndexes[i] = fDPosSummand->Var()->Index();
|
||||||
|
coeffs[i] = -1.0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!set_rowex(fLS->LP(), this->Index(), i, &coeffs[0], &varIndexes[0]))
|
||||||
|
printf("Error in set_rowex.");
|
||||||
|
|
||||||
|
fLS->RemovePresolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -48,32 +73,61 @@ Constraint::Vars()
|
|||||||
* Changes the left side of the constraint, i.e. its coefficients and variables.
|
* Changes the left side of the constraint, i.e. its coefficients and variables.
|
||||||
* There must be exactly one coefficient for each variable.
|
* There must be exactly one coefficient for each variable.
|
||||||
*
|
*
|
||||||
* @param coeffs the new coefficients
|
* @param summands a BList containing the Summand objects that make up the new left side
|
||||||
* @param vars the new variables
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Constraint::ChangeLeftSide(BList* coeffs, BList* vars)
|
Constraint::ChangeLeftSide(BList* summands)
|
||||||
{
|
{
|
||||||
int32 sizeCoeffs = coeffs->CountItems();
|
fSummands = summands;
|
||||||
int32 sizeVars = vars->CountItems();
|
_UpdateLeftSide();
|
||||||
if (sizeCoeffs != sizeVars)
|
}
|
||||||
printf("Number of coefficients and number of variables in a constraint must be equal.");
|
|
||||||
|
|
||||||
fCoeffs = coeffs;
|
void
|
||||||
fVars = vars;
|
Constraint::ChangeLeftSide(double coeff1, Variable* var1)
|
||||||
|
{
|
||||||
double coeffsArray[sizeCoeffs];
|
fSummands->MakeEmpty();
|
||||||
for (int32 i = 0; i < sizeCoeffs; i++)
|
fSummands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffsArray[i] = *(double*)coeffs->ItemAt(i);
|
_UpdateLeftSide();
|
||||||
|
}
|
||||||
int vIndexes[sizeCoeffs];
|
|
||||||
for (int32 i = 0; i < sizeVars; i++)
|
|
||||||
vIndexes[i] = ((Variable*)vars->ItemAt(i))->Index();
|
void
|
||||||
|
Constraint::ChangeLeftSide(double coeff1, Variable* var1,
|
||||||
|
double coeff2, Variable* var2)
|
||||||
|
{
|
||||||
|
fSummands->MakeEmpty();
|
||||||
|
fSummands->AddItem(new Summand(coeff1, var1));
|
||||||
|
fSummands->AddItem(new Summand(coeff2, var2));
|
||||||
|
_UpdateLeftSide();
|
||||||
|
}
|
||||||
|
|
||||||
if (!set_rowex(fLS->LP(), this->Index(), sizeCoeffs, &coeffsArray[0], &vIndexes[0]))
|
|
||||||
printf("Error in set_rowex.");
|
|
||||||
|
|
||||||
fLS->RemovePresolved();
|
void
|
||||||
|
Constraint::ChangeLeftSide(double coeff1, Variable* var1,
|
||||||
|
double coeff2, Variable* var2,
|
||||||
|
double coeff3, Variable* var3)
|
||||||
|
{
|
||||||
|
fSummands->MakeEmpty();
|
||||||
|
fSummands->AddItem(new Summand(coeff1, var1));
|
||||||
|
fSummands->AddItem(new Summand(coeff2, var2));
|
||||||
|
fSummands->AddItem(new Summand(coeff3, var3));
|
||||||
|
_UpdateLeftSide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Constraint::ChangeLeftSide(double coeff1, Variable* var1,
|
||||||
|
double coeff2, Variable* var2,
|
||||||
|
double coeff3, Variable* var3,
|
||||||
|
double coeff4, Variable* var4)
|
||||||
|
{
|
||||||
|
fSummands->MakeEmpty();
|
||||||
|
fSummands->AddItem(new Summand(coeff1, var1));
|
||||||
|
fSummands->AddItem(new Summand(coeff2, var2));
|
||||||
|
fSummands->AddItem(new Summand(coeff3, var3));
|
||||||
|
fSummands->AddItem(new Summand(coeff4, var4));
|
||||||
|
_UpdateLeftSide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,18 +190,156 @@ Constraint::SetRightSide(double value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Needs to be fixed. Use BString. Substring?
|
/**
|
||||||
//~ string Constraint::ToString() {
|
* Gets the penalty coefficient for negative deviations.
|
||||||
//~ string s = "";
|
*
|
||||||
//~ for (int32 i = 0; i < fVars->CountItems(); i++)
|
* @return the penalty coefficient
|
||||||
//~ s += (double)fCoeffs->ItemAt(i) + "*" + (Variable*)fVars->ItemAt(i).ToString() + " + ";
|
*/
|
||||||
//~ s = s.Substring(0, s.Length - 2);
|
double
|
||||||
//~ if (Op == OperatorType.EQ) s += "= ";
|
Constraint::PenaltyNeg()
|
||||||
//~ else if (Op == OperatorType.GE) s += ">= ";
|
{
|
||||||
//~ else s += "<= ";
|
if (fDNegSummand == NULL)
|
||||||
//~ s += rightSide.ToString();
|
return INFINITY;
|
||||||
//~ return s;
|
return fDNegSummand->Coeff();
|
||||||
//~ }
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The penalty coefficient for negative deviations from the soft constraint's exact solution,
|
||||||
|
* i.e. if the left side is too large.
|
||||||
|
*
|
||||||
|
* @param value coefficient of negative penalty <code>double</code>
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Constraint::SetPenaltyNeg(double value)
|
||||||
|
{
|
||||||
|
if (fDNegSummand == NULL) {
|
||||||
|
fDNegSummand = fLS->AddObjFunctionSummand(value, new Variable(fLS));
|
||||||
|
ChangeLeftSide(fSummands);
|
||||||
|
fLS->UpdateObjFunction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == fDNegSummand->Coeff())
|
||||||
|
return;
|
||||||
|
fDNegSummand->SetCoeff(value);
|
||||||
|
fLS->UpdateObjFunction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the penalty coefficient for positive deviations.
|
||||||
|
*
|
||||||
|
* @return the penalty coefficient
|
||||||
|
*/
|
||||||
|
double
|
||||||
|
Constraint::PenaltyPos()
|
||||||
|
{
|
||||||
|
if (fDPosSummand == NULL)
|
||||||
|
return INFINITY;
|
||||||
|
return fDPosSummand->Coeff();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The penalty coefficient for negative deviations from the soft constraint's exact solution,
|
||||||
|
* i.e. if the left side is too small.
|
||||||
|
*
|
||||||
|
* @param value coefficient of positive penalty <code>double</code>
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Constraint::SetPenaltyPos(double value)
|
||||||
|
{
|
||||||
|
if (fDPosSummand == NULL) {
|
||||||
|
fDPosSummand = fLS->AddObjFunctionSummand(value, new Variable(fLS));
|
||||||
|
ChangeLeftSide(fSummands);
|
||||||
|
fLS->UpdateObjFunction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == fDPosSummand->Coeff())
|
||||||
|
return;
|
||||||
|
fDPosSummand->SetCoeff(value);
|
||||||
|
fLS->UpdateObjFunction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the slack variable for the negative variations.
|
||||||
|
*
|
||||||
|
* @return the slack variable for the negative variations
|
||||||
|
*/
|
||||||
|
Variable*
|
||||||
|
Constraint::DNeg() const
|
||||||
|
{
|
||||||
|
if (fDNegSummand == NULL)
|
||||||
|
return NULL;
|
||||||
|
return fDNegSummand->Var();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the slack variable for the positive variations.
|
||||||
|
*
|
||||||
|
* @return the slack variable for the positive variations
|
||||||
|
*/
|
||||||
|
Variable*
|
||||||
|
Constraint::DPos() const
|
||||||
|
{
|
||||||
|
if (fDPosSummand == NULL)
|
||||||
|
return NULL;
|
||||||
|
return fDPosSummand->Var();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
Constraint::Constraint(LinearSpec* ls, BList* summands, OperatorType op,
|
||||||
|
double rightSide, double penaltyNeg, double penaltyPos)
|
||||||
|
{
|
||||||
|
fLS = ls;
|
||||||
|
fSummands = summands;
|
||||||
|
fOp = op;
|
||||||
|
fRightSide = rightSide;
|
||||||
|
|
||||||
|
double coeffs[summands->CountItems() + 2];
|
||||||
|
int varIndexes[summands->CountItems() + 2];
|
||||||
|
int32 i;
|
||||||
|
for (i = 0; i < summands->CountItems(); i++) {
|
||||||
|
Summand* s = (Summand*)summands->ItemAt(i);
|
||||||
|
coeffs[i] = s->Coeff();
|
||||||
|
varIndexes[i] = s->Var()->Index();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (penaltyNeg != INFINITY
|
||||||
|
&& fOp != OperatorType(LE)) {
|
||||||
|
fDNegSummand = ls->AddObjFunctionSummand(penaltyNeg, new Variable(ls));
|
||||||
|
varIndexes[i] = fDNegSummand->Var()->Index();
|
||||||
|
coeffs[i] = 1.0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fDNegSummand = NULL;
|
||||||
|
|
||||||
|
if (penaltyPos != INFINITY
|
||||||
|
&& fOp != OperatorType(GE)) {
|
||||||
|
fDPosSummand = ls->AddObjFunctionSummand(penaltyPos, new Variable(ls));
|
||||||
|
varIndexes[i] = fDPosSummand->Var()->Index();
|
||||||
|
coeffs[i] = -1.0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fDPosSummand = NULL;
|
||||||
|
|
||||||
|
if (!add_constraintex(ls->LP(), i, &coeffs[0], &varIndexes[0],
|
||||||
|
((fOp == OperatorType(EQ)) ? EQ
|
||||||
|
: (fOp == OperatorType(GE)) ? GE
|
||||||
|
: LE), rightSide))
|
||||||
|
printf("Error in add_constraintex.");
|
||||||
|
|
||||||
|
ls->Constraints()->AddItem(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,50 +349,15 @@ Constraint::SetRightSide(double value)
|
|||||||
Constraint::~Constraint()
|
Constraint::~Constraint()
|
||||||
{
|
{
|
||||||
del_constraint(fLS->LP(), Index());
|
del_constraint(fLS->LP(), Index());
|
||||||
delete fCoeffs;
|
delete fSummands;
|
||||||
delete fVars;
|
if(fDNegSummand != NULL) {
|
||||||
|
delete fDNegSummand->Var();
|
||||||
|
delete fDNegSummand;
|
||||||
|
}
|
||||||
|
if(fDPosSummand != NULL) {
|
||||||
|
delete fDPosSummand->Var();
|
||||||
|
delete fDPosSummand;
|
||||||
|
}
|
||||||
fLS->Constraints()->RemoveItem(this);
|
fLS->Constraints()->RemoveItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor.
|
|
||||||
*/
|
|
||||||
Constraint::Constraint() {}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
Constraint::Constraint(LinearSpec* ls, BList* coeffs, BList* vars, OperatorType op,
|
|
||||||
double rightSide)
|
|
||||||
{
|
|
||||||
|
|
||||||
int32 sizeCoeffs = coeffs->CountItems();
|
|
||||||
int32 sizeVars = vars->CountItems();
|
|
||||||
if (sizeCoeffs != sizeVars)
|
|
||||||
printf("Number of coefficients and number of variables in a constraint must be equal.");
|
|
||||||
|
|
||||||
fLS = ls;
|
|
||||||
fCoeffs = coeffs;
|
|
||||||
fVars = vars;
|
|
||||||
fOp = op;
|
|
||||||
fRightSide = rightSide;
|
|
||||||
|
|
||||||
double coeffsArray[sizeCoeffs];
|
|
||||||
for (int32 i = 0; i < sizeCoeffs; i++)
|
|
||||||
coeffsArray[i] = *(double*)coeffs->ItemAt(i);
|
|
||||||
|
|
||||||
int vIndexes[sizeCoeffs];
|
|
||||||
for (int32 i = 0; i < sizeVars; i++)
|
|
||||||
vIndexes[i] = ((Variable*)vars->ItemAt(i))->Index();
|
|
||||||
|
|
||||||
if (!add_constraintex(ls->LP(), sizeCoeffs, &coeffsArray[0], &vIndexes[0],
|
|
||||||
((op == OperatorType(EQ)) ? EQ
|
|
||||||
: (op == OperatorType(GE)) ? GE
|
|
||||||
: LE), rightSide))
|
|
||||||
printf("Error in add_constraintex.");
|
|
||||||
|
|
||||||
ls->Constraints()->AddItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ UseLibraryHeaders lp_solve linprog ;
|
|||||||
SharedLibrary liblinprog.so :
|
SharedLibrary liblinprog.so :
|
||||||
Constraint.cpp
|
Constraint.cpp
|
||||||
LinearSpec.cpp
|
LinearSpec.cpp
|
||||||
|
Summand.cpp
|
||||||
ObjFunctionSummand.cpp
|
ObjFunctionSummand.cpp
|
||||||
PenaltyFunction.cpp
|
PenaltyFunction.cpp
|
||||||
SoftConstraint.cpp
|
|
||||||
Variable.cpp
|
Variable.cpp
|
||||||
:
|
:
|
||||||
be liblpsolve55.so
|
be liblpsolve55.so
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "LinearSpec.h"
|
#include "LinearSpec.h"
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
#include "ObjFunctionSummand.h"
|
#include "ObjFunctionSummand.h"
|
||||||
#include "PenaltyFunction.h"
|
#include "PenaltyFunction.h"
|
||||||
#include "SoftConstraint.h"
|
#include "Constraint.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
|
|
||||||
#include "lp_lib.h"
|
#include "lp_lib.h"
|
||||||
@@ -46,17 +52,17 @@ LinearSpec::~LinearSpec()
|
|||||||
void
|
void
|
||||||
LinearSpec::UpdateObjFunction()
|
LinearSpec::UpdateObjFunction()
|
||||||
{
|
{
|
||||||
int32 size = fObjFunctionSummands->CountItems();;
|
int32 size = fObjFunctionSummands->CountItems();
|
||||||
double coeffs[size];
|
double coeffs[size];
|
||||||
int vIndexes[size];
|
int varIndexes[size];
|
||||||
ObjFunctionSummand* current;
|
ObjFunctionSummand* current;
|
||||||
for (int32 i = 0; i < size; i++) {
|
for (int32 i = 0; i < size; i++) {
|
||||||
current = (ObjFunctionSummand*)fObjFunctionSummands->ItemAt(i);
|
current = (ObjFunctionSummand*)fObjFunctionSummands->ItemAt(i);
|
||||||
coeffs[i] = current->Coeff();
|
coeffs[i] = current->Coeff();
|
||||||
vIndexes[i] = current->Var()->Index();
|
varIndexes[i] = current->Var()->Index();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!set_obj_fnex(fLP, size, &coeffs[0], &vIndexes[0]))
|
if (!set_obj_fnex(fLP, size, &coeffs[0], &varIndexes[0]))
|
||||||
printf("Error in set_obj_fnex.");
|
printf("Error in set_obj_fnex.");
|
||||||
|
|
||||||
RemovePresolved();
|
RemovePresolved();
|
||||||
@@ -70,18 +76,9 @@ LinearSpec::UpdateObjFunction()
|
|||||||
* @param vars the objective function's variables
|
* @param vars the objective function's variables
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
LinearSpec::SetObjFunction(BList* coeffs, BList* vars)
|
LinearSpec::SetObjFunction(BList* summands)
|
||||||
{
|
{
|
||||||
int32 sizeCoeffs = coeffs->CountItems();
|
fObjFunctionSummands = summands;
|
||||||
int32 sizeVars = vars->CountItems();
|
|
||||||
if (sizeCoeffs != sizeVars)
|
|
||||||
printf("Number of coefficients and number of fVariables in objective function must be equal.");
|
|
||||||
|
|
||||||
fObjFunctionSummands = new BList(1);
|
|
||||||
for (int32 i = 0; i < sizeCoeffs; i++)
|
|
||||||
fObjFunctionSummands->AddItem(new ObjFunctionSummand(this,
|
|
||||||
*(double*)coeffs->ItemAt(i), (Variable*)vars->ItemAt(i)));
|
|
||||||
|
|
||||||
UpdateObjFunction();
|
UpdateObjFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,10 +122,10 @@ LinearSpec::AddVariable()
|
|||||||
* @return the new constraint
|
* @return the new constraint
|
||||||
*/
|
*/
|
||||||
Constraint*
|
Constraint*
|
||||||
LinearSpec::AddConstraint(BList* coeffs, BList* vars, OperatorType op,
|
LinearSpec::AddConstraint(BList* summands, OperatorType op, double rightSide)
|
||||||
double rightSide)
|
|
||||||
{
|
{
|
||||||
Constraint* c = new Constraint(this, coeffs, vars, op, rightSide);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
|
INFINITY, INFINITY);
|
||||||
RemovePresolved();
|
RemovePresolved();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -147,11 +144,11 @@ Constraint*
|
|||||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||||
OperatorType op, double rightSide)
|
OperatorType op, double rightSide)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(1);
|
BList* summands = new BList(1);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
BList* vars = new BList(1);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
INFINITY, INFINITY);
|
||||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
RemovePresolved();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,13 +168,12 @@ Constraint*
|
|||||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2, OperatorType op, double rightSide)
|
double coeff2, Variable* var2, OperatorType op, double rightSide)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(2);
|
BList* summands = new BList(2);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffs->AddItem(new double(coeff2));
|
summands->AddItem(new Summand(coeff2, var2));
|
||||||
BList* vars = new BList(2);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
INFINITY, INFINITY);
|
||||||
vars->AddItem(var2);
|
RemovePresolved();
|
||||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,15 +196,13 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
|||||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||||
OperatorType op, double rightSide)
|
OperatorType op, double rightSide)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(3);
|
BList* summands = new BList(3);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffs->AddItem(new double(coeff2));
|
summands->AddItem(new Summand(coeff2, var2));
|
||||||
coeffs->AddItem(new double(coeff3));
|
summands->AddItem(new Summand(coeff3, var3));
|
||||||
BList* vars = new BList(3);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
INFINITY, INFINITY);
|
||||||
vars->AddItem(var2);
|
RemovePresolved();
|
||||||
vars->AddItem(var3);
|
|
||||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,17 +227,14 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
|||||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||||
double coeff4, Variable* var4, OperatorType op, double rightSide)
|
double coeff4, Variable* var4, OperatorType op, double rightSide)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(4);
|
BList* summands = new BList(3);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffs->AddItem(new double(coeff2));
|
summands->AddItem(new Summand(coeff2, var2));
|
||||||
coeffs->AddItem(new double(coeff3));
|
summands->AddItem(new Summand(coeff3, var3));
|
||||||
coeffs->AddItem(new double(coeff4));
|
summands->AddItem(new Summand(coeff4, var4));
|
||||||
BList* vars = new BList(4);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
INFINITY, INFINITY);
|
||||||
vars->AddItem(var2);
|
RemovePresolved();
|
||||||
vars->AddItem(var3);
|
|
||||||
vars->AddItem(var4);
|
|
||||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,13 +250,12 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
|||||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||||
*/
|
*/
|
||||||
SoftConstraint*
|
Constraint*
|
||||||
LinearSpec::AddSoftConstraint(BList* coeffs, BList* vars, OperatorType op,
|
LinearSpec::AddConstraint(BList* summands, OperatorType op,
|
||||||
double rightSide, double penaltyNeg, double penaltyPos)
|
double rightSide, double penaltyNeg, double penaltyPos)
|
||||||
{
|
{
|
||||||
SoftConstraint* c = new SoftConstraint(this, coeffs, vars, op, rightSide,
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
penaltyNeg, penaltyPos);
|
penaltyNeg, penaltyPos);
|
||||||
|
|
||||||
RemovePresolved();
|
RemovePresolved();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -281,17 +271,16 @@ LinearSpec::AddSoftConstraint(BList* coeffs, BList* vars, OperatorType op,
|
|||||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||||
*/
|
*/
|
||||||
SoftConstraint*
|
Constraint*
|
||||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||||
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
|
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(1);
|
BList* summands = new BList(1);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
BList* vars = new BList(1);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
|
||||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
|
||||||
penaltyNeg, penaltyPos);
|
penaltyNeg, penaltyPos);
|
||||||
return c;
|
RemovePresolved();
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -307,20 +296,18 @@ LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
|||||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||||
*/
|
*/
|
||||||
SoftConstraint*
|
Constraint*
|
||||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2, OperatorType op, double rightSide,
|
double coeff2, Variable* var2, OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos)
|
double penaltyNeg, double penaltyPos)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(2);
|
BList* summands = new BList(2);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffs->AddItem(new double(coeff2));
|
summands->AddItem(new Summand(coeff2, var2));
|
||||||
BList* vars = new BList(2);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
penaltyNeg, penaltyPos);
|
||||||
vars->AddItem(var2);
|
RemovePresolved();
|
||||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
return c;
|
||||||
penaltyNeg, penaltyPos);
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -338,21 +325,18 @@ LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
|||||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||||
*/
|
*/
|
||||||
SoftConstraint*
|
Constraint*
|
||||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||||
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
|
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(3);
|
BList* summands = new BList(2);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffs->AddItem(new double(coeff2));
|
summands->AddItem(new Summand(coeff2, var2));
|
||||||
coeffs->AddItem(new double(coeff3));
|
summands->AddItem(new Summand(coeff3, var3));
|
||||||
BList* vars = new BList(3);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
penaltyNeg, penaltyPos);
|
||||||
vars->AddItem(var2);
|
RemovePresolved();
|
||||||
vars->AddItem(var3);
|
|
||||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
|
||||||
penaltyNeg, penaltyPos);
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,24 +357,20 @@ LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
|||||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||||
*/
|
*/
|
||||||
SoftConstraint*
|
Constraint*
|
||||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||||
double coeff4, Variable* var4, OperatorType op, double rightSide,
|
double coeff4, Variable* var4, OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos)
|
double penaltyNeg, double penaltyPos)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(4);
|
BList* summands = new BList(2);
|
||||||
coeffs->AddItem(new double(coeff1));
|
summands->AddItem(new Summand(coeff1, var1));
|
||||||
coeffs->AddItem(new double(coeff2));
|
summands->AddItem(new Summand(coeff2, var2));
|
||||||
coeffs->AddItem(new double(coeff3));
|
summands->AddItem(new Summand(coeff3, var3));
|
||||||
coeffs->AddItem(new double(coeff4));
|
summands->AddItem(new Summand(coeff4, var4));
|
||||||
BList* vars = new BList(4);
|
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||||
vars->AddItem(var1);
|
|
||||||
vars->AddItem(var2);
|
|
||||||
vars->AddItem(var3);
|
|
||||||
vars->AddItem(var4);
|
|
||||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
|
||||||
penaltyNeg, penaltyPos);
|
penaltyNeg, penaltyPos);
|
||||||
|
RemovePresolved();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "ObjFunctionSummand.h"
|
#include "ObjFunctionSummand.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
#include "LinearSpec.h"
|
#include "LinearSpec.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the summmand's coefficient.
|
|
||||||
*
|
|
||||||
* @return the summand's coefficient
|
|
||||||
*/
|
|
||||||
double
|
|
||||||
ObjFunctionSummand::Coeff()
|
|
||||||
{
|
|
||||||
return fCoeff;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the summmand's coefficient.
|
* Sets the summmand's coefficient.
|
||||||
*
|
*
|
||||||
@@ -23,23 +17,11 @@ ObjFunctionSummand::Coeff()
|
|||||||
void
|
void
|
||||||
ObjFunctionSummand::SetCoeff(double coeff)
|
ObjFunctionSummand::SetCoeff(double coeff)
|
||||||
{
|
{
|
||||||
fCoeff = coeff;
|
Summand::SetCoeff(coeff);
|
||||||
fLS->UpdateObjFunction();
|
fLS->UpdateObjFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the summand's variable.
|
|
||||||
*
|
|
||||||
* @return the summand's variable
|
|
||||||
*/
|
|
||||||
Variable*
|
|
||||||
ObjFunctionSummand::Var()
|
|
||||||
{
|
|
||||||
return fVar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the summand's variable.
|
* Sets the summand's variable.
|
||||||
*
|
*
|
||||||
@@ -48,7 +30,7 @@ ObjFunctionSummand::Var()
|
|||||||
void
|
void
|
||||||
ObjFunctionSummand::SetVar(Variable* var)
|
ObjFunctionSummand::SetVar(Variable* var)
|
||||||
{
|
{
|
||||||
fVar = var;
|
Summand::SetVar(var);
|
||||||
fLS->UpdateObjFunction();
|
fLS->UpdateObjFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,9 +50,8 @@ ObjFunctionSummand::~ObjFunctionSummand()
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
ObjFunctionSummand::ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var)
|
ObjFunctionSummand::ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var)
|
||||||
|
: Summand(coeff, var)
|
||||||
{
|
{
|
||||||
fLS = ls;
|
fLS = ls;
|
||||||
fCoeff = coeff;
|
|
||||||
fVar = var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "PenaltyFunction.h"
|
#include "PenaltyFunction.h"
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
#include "ObjFunctionSummand.h"
|
#include "ObjFunctionSummand.h"
|
||||||
@@ -27,29 +33,15 @@ PenaltyFunction::PenaltyFunction(LinearSpec* ls, Variable* var, BList* xs, BList
|
|||||||
fGs = gs;
|
fGs = gs;
|
||||||
fConstraints = new BList(1);
|
fConstraints = new BList(1);
|
||||||
fObjFunctionSummands = new BList(1);
|
fObjFunctionSummands = new BList(1);
|
||||||
|
|
||||||
BList* coeffs = new BList(1);
|
fConstraints->AddItem(ls->AddConstraint(1.0, var, OperatorType(EQ),
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(1);
|
|
||||||
vars->AddItem(var);
|
|
||||||
|
|
||||||
fConstraints->AddItem(ls->AddSoftConstraint(coeffs, vars, OperatorType(EQ),
|
|
||||||
*(double*)(xs->ItemAt(0)), -*(double*)(gs->ItemAt(0)),
|
*(double*)(xs->ItemAt(0)), -*(double*)(gs->ItemAt(0)),
|
||||||
*(double*)(gs->ItemAt(1))));
|
*(double*)(gs->ItemAt(1))));
|
||||||
|
|
||||||
for (int32 i = 1; i < sizeGs; i++) {
|
for (int32 i = 1; i < sizeGs; i++) {
|
||||||
Variable* dPos = ls->AddVariable();
|
Variable* dPos = ls->AddVariable();
|
||||||
|
|
||||||
BList* coeffs = new BList(2);
|
fConstraints->AddItem(ls->AddConstraint(1.0, var, -1.0, dPos, OperatorType(LE),
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(var);
|
|
||||||
vars->AddItem(dPos);
|
|
||||||
|
|
||||||
fConstraints->AddItem(ls->AddConstraint(coeffs, vars, OperatorType(LE),
|
|
||||||
*(double*)(xs->ItemAt(i))));
|
*(double*)(xs->ItemAt(i))));
|
||||||
|
|
||||||
fObjFunctionSummands->AddItem(ls->AddObjFunctionSummand(
|
fObjFunctionSummands->AddItem(ls->AddObjFunctionSummand(
|
||||||
|
|||||||
@@ -1,235 +0,0 @@
|
|||||||
#include "SoftConstraint.h"
|
|
||||||
#include "ObjFunctionSummand.h"
|
|
||||||
#include "Variable.h"
|
|
||||||
#include "LinearSpec.h"
|
|
||||||
|
|
||||||
#include "lp_lib.h"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the left side of the soft constraint, i.e. its coefficients and variables.
|
|
||||||
* There must be exactly one coefficient for each variable.
|
|
||||||
*
|
|
||||||
* @param coeffs the constraint's coefficients
|
|
||||||
* @param vars the constraint's variables
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SoftConstraint::ChangeLeftSide(BList* coeffs, BList* vars)
|
|
||||||
{
|
|
||||||
int32 sizeCoeffs = coeffs->CountItems();
|
|
||||||
int32 sizeVars = vars->CountItems();
|
|
||||||
if (sizeCoeffs != sizeVars)
|
|
||||||
printf("Number of coefficients and number of variables in a constraint must be equal.");
|
|
||||||
|
|
||||||
fCoeffs = coeffs;
|
|
||||||
fVars = vars;
|
|
||||||
|
|
||||||
int vIndexes[sizeCoeffs + 2];
|
|
||||||
double coeffs2[sizeCoeffs + 2];
|
|
||||||
|
|
||||||
int32 i;
|
|
||||||
for (i = 0; i < sizeVars; i++) {
|
|
||||||
vIndexes[i] = ((Variable*)vars->ItemAt(i))->Index();
|
|
||||||
coeffs2[i] = *(double*)coeffs->ItemAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fOp != OperatorType(LE)) {
|
|
||||||
vIndexes[i] = fDNegSummand->Var()->Index();
|
|
||||||
coeffs2[i] = 1.0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fOp != OperatorType(GE)) {
|
|
||||||
vIndexes[i] = fDPosSummand->Var()->Index();
|
|
||||||
coeffs2[i] = -1.0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!set_rowex(fLS->LP(), this->Index(), i, &coeffs2[0], &vIndexes[0]))
|
|
||||||
printf("Error in set_rowex.");
|
|
||||||
|
|
||||||
fLS->RemovePresolved();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the operator used for this constraint.
|
|
||||||
*
|
|
||||||
* @return the operator used for this constraint
|
|
||||||
*/
|
|
||||||
OperatorType
|
|
||||||
SoftConstraint::Op()
|
|
||||||
{
|
|
||||||
return fOp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the operator used for this constraint.
|
|
||||||
*
|
|
||||||
* @param value operator type
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SoftConstraint::SetOp(OperatorType value)
|
|
||||||
{
|
|
||||||
fOp = value;
|
|
||||||
ChangeLeftSide(fCoeffs, fVars);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the coefficient of negative summand.
|
|
||||||
*
|
|
||||||
* @return the coefficient of negative summand.
|
|
||||||
*/
|
|
||||||
double
|
|
||||||
SoftConstraint::PenaltyNeg()
|
|
||||||
{
|
|
||||||
return fDNegSummand->Coeff();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The penalty coefficient for positive deviations from the soft constraint's exact solution,
|
|
||||||
* i.e. if the left side is too large.
|
|
||||||
*
|
|
||||||
* @param value coefficient of negative penalty <code>double</code>
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SoftConstraint::SetPenaltyNeg(double value)
|
|
||||||
{
|
|
||||||
if (value == fDNegSummand->Coeff())
|
|
||||||
return;
|
|
||||||
fDNegSummand->SetCoeff(value);
|
|
||||||
fLS->UpdateObjFunction();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the coefficient of positive summand.
|
|
||||||
*
|
|
||||||
* @return the coefficient of positive summand.
|
|
||||||
*/
|
|
||||||
double
|
|
||||||
SoftConstraint::PenaltyPos()
|
|
||||||
{
|
|
||||||
return fDPosSummand->Coeff();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The penalty coefficient for negative deviations from the soft constraint's exact solution,
|
|
||||||
* i.e. if the left side is too small.
|
|
||||||
*
|
|
||||||
* @param value coefficient of positive penalty <code>double</code>
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SoftConstraint::SetPenaltyPos(double value)
|
|
||||||
{
|
|
||||||
if (value == fDPosSummand->Coeff())
|
|
||||||
return;
|
|
||||||
fDPosSummand->SetCoeff(value);
|
|
||||||
fLS->UpdateObjFunction();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns positive and negative penalty coefficient as string.
|
|
||||||
*/
|
|
||||||
// Needs to be fixed.
|
|
||||||
//~ string SoftConstraint::ToString() {
|
|
||||||
//~ return base.ToString()
|
|
||||||
//~ + "; PenaltyNeg=" + PenaltyNeg()
|
|
||||||
//~ + "; PenaltyPos=" + PenaltyPos();
|
|
||||||
//~ }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the slack variable for the negative variations.
|
|
||||||
*
|
|
||||||
* @return the slack variable for the negative variations
|
|
||||||
*/
|
|
||||||
Variable*
|
|
||||||
SoftConstraint::DNeg() const
|
|
||||||
{
|
|
||||||
return fDNeg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the slack variable for the positive variations.
|
|
||||||
*
|
|
||||||
* @return the slack variable for the positive variations
|
|
||||||
*/
|
|
||||||
Variable*
|
|
||||||
SoftConstraint::DPos() const
|
|
||||||
{
|
|
||||||
return fDPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor.
|
|
||||||
* Removes the soft constraint from its specification.
|
|
||||||
*/
|
|
||||||
SoftConstraint::~SoftConstraint()
|
|
||||||
{
|
|
||||||
delete fDNegSummand->Var();
|
|
||||||
delete fDPosSummand->Var();
|
|
||||||
delete fDNegSummand;
|
|
||||||
delete fDPosSummand;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
SoftConstraint::SoftConstraint(LinearSpec* ls, BList* coeffs, BList* vars, OperatorType op,
|
|
||||||
double rightSide, double penaltyNeg, double penaltyPos)
|
|
||||||
{
|
|
||||||
int32 sizeCoeffs = coeffs->CountItems();
|
|
||||||
int32 sizeVars = vars->CountItems();
|
|
||||||
if (sizeCoeffs != sizeVars)
|
|
||||||
printf("Number of coefficients and number of variables in a constraint must be equal.");
|
|
||||||
|
|
||||||
fLS = ls;
|
|
||||||
fCoeffs = coeffs;
|
|
||||||
fVars = vars;
|
|
||||||
fOp = op;
|
|
||||||
fRightSide = rightSide;
|
|
||||||
|
|
||||||
fDNeg = new Variable(ls);
|
|
||||||
fDPos = new Variable(ls);
|
|
||||||
fDNegSummand = ls->AddObjFunctionSummand(penaltyNeg, DNeg());
|
|
||||||
fDPosSummand = ls->AddObjFunctionSummand(penaltyPos, DPos());
|
|
||||||
|
|
||||||
int vIndexes[sizeCoeffs + 2];
|
|
||||||
double coeffs2[sizeCoeffs + 2];
|
|
||||||
|
|
||||||
int32 i;
|
|
||||||
for (i=0; i < sizeVars; i++) {
|
|
||||||
vIndexes[i] = ((Variable*)vars->ItemAt(i))->Index();
|
|
||||||
coeffs2[i] = *(double*)coeffs->ItemAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fOp != OperatorType(LE)) {
|
|
||||||
vIndexes[i] = fDNegSummand->Var()->Index();
|
|
||||||
coeffs2[i] = 1.0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fOp != OperatorType(GE)) {
|
|
||||||
vIndexes[i] = fDPosSummand->Var()->Index();
|
|
||||||
coeffs2[i] = -1.0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!add_constraintex(ls->LP(), i, &coeffs2[0], &vIndexes[0],
|
|
||||||
((fOp == OperatorType(EQ)) ? EQ
|
|
||||||
: (fOp == OperatorType(GE)) ? GE
|
|
||||||
: LE), rightSide))
|
|
||||||
printf("Error in add_constraintex.");
|
|
||||||
|
|
||||||
ls->Constraints()->AddItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Summand.h"
|
||||||
|
#include "Variable.h"
|
||||||
|
#include "LinearSpec.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the summmand's coefficient.
|
||||||
|
*
|
||||||
|
* @return the summand's coefficient
|
||||||
|
*/
|
||||||
|
double
|
||||||
|
Summand::Coeff()
|
||||||
|
{
|
||||||
|
return fCoeff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the summmand's coefficient.
|
||||||
|
*
|
||||||
|
* @param coeff coefficient
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Summand::SetCoeff(double coeff)
|
||||||
|
{
|
||||||
|
fCoeff = coeff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the summand's variable.
|
||||||
|
*
|
||||||
|
* @return the summand's variable
|
||||||
|
*/
|
||||||
|
Variable*
|
||||||
|
Summand::Var()
|
||||||
|
{
|
||||||
|
return fVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the summand's variable.
|
||||||
|
*
|
||||||
|
* @param var variable
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Summand::SetVar(Variable* var)
|
||||||
|
{
|
||||||
|
fVar = var;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
Summand::~Summand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
Summand::Summand(double coeff, Variable* var)
|
||||||
|
{
|
||||||
|
fCoeff = coeff;
|
||||||
|
fVar = var;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
#include "LinearSpec.h"
|
#include "LinearSpec.h"
|
||||||
@@ -156,15 +162,7 @@ Variable::SetRange(double min, double max)
|
|||||||
Constraint*
|
Constraint*
|
||||||
Variable::IsEqual(Variable* var)
|
Variable::IsEqual(Variable* var)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(2);
|
return fLS->AddConstraint(1.0, this, -1.0, var, OperatorType(EQ), 0.0);
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(this);
|
|
||||||
vars->AddItem(var);
|
|
||||||
|
|
||||||
return fLS->AddConstraint(coeffs, vars, OperatorType(EQ), 0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,15 +175,7 @@ Variable::IsEqual(Variable* var)
|
|||||||
Constraint*
|
Constraint*
|
||||||
Variable::IsSmallerOrEqual(Variable* var)
|
Variable::IsSmallerOrEqual(Variable* var)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(2);
|
return fLS->AddConstraint(1.0, this, -1.0, var, OperatorType(LE), 0.0);
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(this);
|
|
||||||
vars->AddItem(var);
|
|
||||||
|
|
||||||
return fLS->AddConstraint(coeffs, vars, OperatorType(LE), 0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -198,15 +188,7 @@ Variable::IsSmallerOrEqual(Variable* var)
|
|||||||
Constraint*
|
Constraint*
|
||||||
Variable::IsGreaterorEqual(Variable* var)
|
Variable::IsGreaterorEqual(Variable* var)
|
||||||
{
|
{
|
||||||
BList* coeffs = new BList(2);
|
return fLS->AddConstraint(-1.0, var, 1.0, this, OperatorType(GE), 0.0);
|
||||||
coeffs->AddItem(new double(-1.0));
|
|
||||||
coeffs->AddItem(new double(1.0));
|
|
||||||
|
|
||||||
BList* vars = new BList(2);
|
|
||||||
vars->AddItem(var);
|
|
||||||
vars->AddItem(this);
|
|
||||||
|
|
||||||
return fLS->AddConstraint(coeffs, vars, OperatorType(GE), 0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,3 +22,9 @@ Application ALMTest2 :
|
|||||||
be liblpsolve55.so be liblinprog.so libalm.so
|
be liblpsolve55.so be liblinprog.so libalm.so
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Application ALMSimpleTest :
|
||||||
|
SimpleTest.cpp
|
||||||
|
:
|
||||||
|
be liblpsolve55.so be liblinprog.so libalm.so
|
||||||
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <List.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "Area.h"
|
||||||
|
#include "BALMLayout.h"
|
||||||
|
#include "OperatorType.h"
|
||||||
|
#include "XTab.h"
|
||||||
|
#include "YTab.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace BALM;
|
||||||
|
|
||||||
|
class SimpleTestWindow : public BWindow {
|
||||||
|
public:
|
||||||
|
SimpleTestWindow(BRect frame)
|
||||||
|
: BWindow(frame, "SimpleTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||||
|
{
|
||||||
|
fLS = new BALMLayout();
|
||||||
|
SetLayout(fLS);
|
||||||
|
|
||||||
|
button1 = new BButton("button1");
|
||||||
|
SetBALMLayout();
|
||||||
|
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SetBALMLayout()
|
||||||
|
{
|
||||||
|
Area* a = fLS->AddArea(fLS->Left(), fLS->Top(), fLS->Right(), fLS->Bottom(), button1);
|
||||||
|
a->SetLeftInset(10);
|
||||||
|
fLS->Save("/boot/home/Desktop/test1_ls.txt");
|
||||||
|
|
||||||
|
|
||||||
|
// fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
|
||||||
|
// fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
BALMLayout* fLS;
|
||||||
|
BButton* button1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleTest : public BApplication {
|
||||||
|
public:
|
||||||
|
SimpleTest()
|
||||||
|
: BApplication("application/x-vnd.haiku.simpletest")
|
||||||
|
{
|
||||||
|
BRect frameRect;
|
||||||
|
frameRect.Set(100, 100, 392, 366);
|
||||||
|
SimpleTestWindow* theWindow = new SimpleTestWindow(frameRect);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
SimpleTest test;
|
||||||
|
test.Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
@@ -14,9 +19,9 @@ using namespace BALM;
|
|||||||
|
|
||||||
class TableTestWindow : public BWindow {
|
class TableTestWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
TableTestWindow(BRect frame) : BWindow(frame, "TableTest", B_TITLED_WINDOW,
|
TableTestWindow(BRect frame)
|
||||||
B_QUIT_ON_WINDOW_CLOSE) {
|
: BWindow(frame, "TableTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||||
|
{
|
||||||
BALMLayout* fLS = new BALMLayout();
|
BALMLayout* fLS = new BALMLayout();
|
||||||
|
|
||||||
SetLayout(fLS);
|
SetLayout(fLS);
|
||||||
@@ -55,7 +60,9 @@ public:
|
|||||||
|
|
||||||
class TableTest : public BApplication {
|
class TableTest : public BApplication {
|
||||||
public:
|
public:
|
||||||
TableTest() : BApplication("application/x-vnd.haiku.table-test") {
|
TableTest()
|
||||||
|
: BApplication("application/x-vnd.haiku.table-test")
|
||||||
|
{
|
||||||
BRect frameRect;
|
BRect frameRect;
|
||||||
frameRect.Set(100, 100, 400, 400);
|
frameRect.Set(100, 100, 400, 400);
|
||||||
TableTestWindow* theWindow = new TableTestWindow(frameRect);
|
TableTestWindow* theWindow = new TableTestWindow(frameRect);
|
||||||
@@ -63,8 +70,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
TableTest test;
|
TableTest test;
|
||||||
test.Run();
|
test.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
@@ -14,9 +20,9 @@ using namespace BALM;
|
|||||||
|
|
||||||
class Test1Window : public BWindow {
|
class Test1Window : public BWindow {
|
||||||
public:
|
public:
|
||||||
Test1Window(BRect frame) : BWindow(frame, "Test1", B_TITLED_WINDOW,
|
Test1Window(BRect frame)
|
||||||
B_QUIT_ON_WINDOW_CLOSE) {
|
: BWindow(frame, "Test1", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||||
|
{
|
||||||
fLS = new BALMLayout();
|
fLS = new BALMLayout();
|
||||||
|
|
||||||
SetLayout(fLS);
|
SetLayout(fLS);
|
||||||
@@ -32,7 +38,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetBALMLayout() {
|
void
|
||||||
|
SetBALMLayout()
|
||||||
|
{
|
||||||
XTab* x1 = fLS->AddXTab();
|
XTab* x1 = fLS->AddXTab();
|
||||||
YTab* y1 = fLS->AddYTab();
|
YTab* y1 = fLS->AddYTab();
|
||||||
|
|
||||||
@@ -40,20 +48,8 @@ public:
|
|||||||
fLS->AddArea(x1, fLS->Top(), fLS->Right(), y1, button2);
|
fLS->AddArea(x1, fLS->Top(), fLS->Right(), y1, button2);
|
||||||
fLS->AddArea(fLS->Left(), y1, fLS->Right(), fLS->Bottom(), button3);
|
fLS->AddArea(fLS->Left(), y1, fLS->Right(), fLS->Bottom(), button3);
|
||||||
|
|
||||||
//~ BList* coeffs1 = new BList(2);
|
|
||||||
//~ coeffs1->AddItem(new double(2.0));
|
|
||||||
//~ coeffs1->AddItem(new double(-1.0));
|
|
||||||
//~ BList* vars1 = new BList(2);
|
|
||||||
//~ vars1->AddItem(x1);
|
|
||||||
//~ vars1->AddItem(fLS->Right());
|
|
||||||
fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
|
|
||||||
|
|
||||||
//~ BList* coeffs2 = new BList(2);
|
fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
|
||||||
//~ coeffs2->AddItem(new double(2.0));
|
|
||||||
//~ coeffs2->AddItem(new double(-1.0));
|
|
||||||
//~ BList* vars2 = new BList(2);
|
|
||||||
//~ vars2->AddItem(y1);
|
|
||||||
//~ vars2->AddItem(fLS->Bottom());
|
|
||||||
fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
|
fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +64,9 @@ private:
|
|||||||
|
|
||||||
class Test1 : public BApplication {
|
class Test1 : public BApplication {
|
||||||
public:
|
public:
|
||||||
Test1() : BApplication("application/x-vnd.haiku.test1") {
|
Test1()
|
||||||
|
: BApplication("application/x-vnd.haiku.test1")
|
||||||
|
{
|
||||||
BRect frameRect;
|
BRect frameRect;
|
||||||
frameRect.Set(100, 100, 392, 366);
|
frameRect.Set(100, 100, 392, 366);
|
||||||
Test1Window* theWindow = new Test1Window(frameRect);
|
Test1Window* theWindow = new Test1Window(frameRect);
|
||||||
@@ -76,8 +74,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
Test1 test;
|
Test1 test;
|
||||||
test.Run();
|
test.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
@@ -18,9 +23,9 @@ using namespace BALM;
|
|||||||
|
|
||||||
class Test2Window : public BWindow {
|
class Test2Window : public BWindow {
|
||||||
public:
|
public:
|
||||||
Test2Window(BRect frame) : BWindow(frame, "Test2", B_TITLED_WINDOW,
|
Test2Window(BRect frame)
|
||||||
B_QUIT_ON_WINDOW_CLOSE) {
|
: BWindow(frame, "Test2", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||||
|
{
|
||||||
fLS = new BALMLayout();
|
fLS = new BALMLayout();
|
||||||
|
|
||||||
SetLayout(fLS);
|
SetLayout(fLS);
|
||||||
@@ -50,7 +55,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetBALMLayout() {
|
void
|
||||||
|
SetBALMLayout()
|
||||||
|
{
|
||||||
XTab* x1 = fLS->AddXTab();
|
XTab* x1 = fLS->AddXTab();
|
||||||
XTab* x2 = fLS->AddXTab();
|
XTab* x2 = fLS->AddXTab();
|
||||||
XTab* x3 = fLS->AddXTab();
|
XTab* x3 = fLS->AddXTab();
|
||||||
@@ -67,32 +74,8 @@ public:
|
|||||||
fLS->AddArea(fLS->Left(), y2, x1, y3, button5);
|
fLS->AddArea(fLS->Left(), y2, x1, y3, button5);
|
||||||
fLS->AddArea(x1, y2, x2, y3, button6);
|
fLS->AddArea(x1, y2, x2, y3, button6);
|
||||||
|
|
||||||
//~ BList* coeffs1 = new BList(2);
|
|
||||||
//~ coeffs1->AddItem(new double(2.0));
|
|
||||||
//~ coeffs1->AddItem(new double(-1.0));
|
|
||||||
//~ BList* vars1 = new BList(2);
|
|
||||||
//~ vars1->AddItem(x1);
|
|
||||||
//~ vars1->AddItem(x2);
|
|
||||||
//~ fLS->AddConstraint(coeffs1, vars1, OperatorType(EQ), 0.0);
|
|
||||||
|
|
||||||
fLS->AddConstraint(2.0, x1, -1.0, x2, OperatorType(EQ), 0.0);
|
fLS->AddConstraint(2.0, x1, -1.0, x2, OperatorType(EQ), 0.0);
|
||||||
|
|
||||||
//~ BList* coeffs2 = new BList(2);
|
|
||||||
//~ coeffs2->AddItem(new double(2.0));
|
|
||||||
//~ coeffs2->AddItem(new double(-1.0));
|
|
||||||
//~ BList* vars2 = new BList(2);
|
|
||||||
//~ vars2->AddItem(y1);
|
|
||||||
//~ vars2->AddItem(y2);
|
|
||||||
fLS->AddConstraint(2.0, y1, -1.0, y2, OperatorType(EQ), 0.0);
|
fLS->AddConstraint(2.0, y1, -1.0, y2, OperatorType(EQ), 0.0);
|
||||||
|
|
||||||
//~ BList* coeffs3 = new BList(3);
|
|
||||||
//~ coeffs3->AddItem(new double(1.0));
|
|
||||||
//~ coeffs3->AddItem(new double(1.0));
|
|
||||||
//~ coeffs3->AddItem(new double(-1.0));
|
|
||||||
//~ BList* vars3 = new BList(3);
|
|
||||||
//~ vars3->AddItem(y1);
|
|
||||||
//~ vars3->AddItem(y2);
|
|
||||||
//~ vars3->AddItem(y3);
|
|
||||||
fLS->AddConstraint(1.0, y1, 1.0, y2, -1.0, y3, OperatorType(EQ), 0.0);
|
fLS->AddConstraint(1.0, y1, 1.0, y2, -1.0, y3, OperatorType(EQ), 0.0);
|
||||||
|
|
||||||
fLS->AddArea(fLS->Left(), y3, x2, y4, checkedListBox1);
|
fLS->AddArea(fLS->Left(), y3, x2, y4, checkedListBox1);
|
||||||
@@ -147,7 +130,9 @@ private:
|
|||||||
|
|
||||||
class Test2 : public BApplication {
|
class Test2 : public BApplication {
|
||||||
public:
|
public:
|
||||||
Test2() : BApplication("application/x-vnd.haiku.test2") {
|
Test2()
|
||||||
|
: BApplication("application/x-vnd.haiku.test2")
|
||||||
|
{
|
||||||
BRect frameRect;
|
BRect frameRect;
|
||||||
frameRect.Set(100, 100, 610, 456);
|
frameRect.Set(100, 100, 610, 456);
|
||||||
Test2Window* theWindow = new Test2Window(frameRect);
|
Test2Window* theWindow = new Test2Window(frameRect);
|
||||||
@@ -155,8 +140,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
Test2 test;
|
Test2 test;
|
||||||
test.Run();
|
test.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
|
|||||||
|
|
||||||
UseLibraryHeaders lp_solve linprog ;
|
UseLibraryHeaders lp_solve linprog ;
|
||||||
|
|
||||||
SimpleTest linprog :
|
SimpleTest linprog_test :
|
||||||
Program.cpp
|
Program.cpp
|
||||||
:
|
:
|
||||||
be liblpsolve55.so liblinprog.so
|
be liblpsolve55.so liblinprog.so
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
||||||
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
@@ -10,7 +15,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
void PrintVars(LinearSpec* ls) {
|
void
|
||||||
|
PrintVars(LinearSpec* ls)
|
||||||
|
{
|
||||||
int32 size = ls->Variables()->CountItems();
|
int32 size = ls->Variables()->CountItems();
|
||||||
Variable* variable;
|
Variable* variable;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@@ -21,7 +28,9 @@ void PrintVars(LinearSpec* ls) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Test1() {
|
void
|
||||||
|
Test1()
|
||||||
|
{
|
||||||
LinearSpec* ls = new LinearSpec();
|
LinearSpec* ls = new LinearSpec();
|
||||||
Variable* x1 = ls->AddVariable();
|
Variable* x1 = ls->AddVariable();
|
||||||
Variable* x2 = ls->AddVariable();
|
Variable* x2 = ls->AddVariable();
|
||||||
@@ -62,6 +71,9 @@ void Test1() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
Test1();
|
Test1();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
|
|||||||
|
|
||||||
UseLibraryHeaders lp_solve ;
|
UseLibraryHeaders lp_solve ;
|
||||||
|
|
||||||
SimpleTest lp_solve :
|
SimpleTest lp_solve_test :
|
||||||
demo.c
|
demo.c
|
||||||
:
|
:
|
||||||
liblpsolve55.so
|
liblpsolve55.so
|
||||||
|
|||||||
Reference in New Issue
Block a user