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:
parent
da51719239
commit
0306945545
@ -1,8 +1,13 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AREA_H
|
||||
#define AREA_H
|
||||
|
||||
#include "Constraint.h"
|
||||
#include "SoftConstraint.h"
|
||||
|
||||
#include <Alignment.h>
|
||||
#include <List.h>
|
||||
@ -26,51 +31,51 @@ class Area {
|
||||
|
||||
public:
|
||||
bool AutoPrefContentSize() const;
|
||||
void SetAutoPrefContentSize(bool value);
|
||||
void SetAutoPrefContentSize(bool value);
|
||||
XTab* Left() const;
|
||||
void SetLeft(XTab* left);
|
||||
void SetLeft(XTab* left);
|
||||
XTab* Right() const;
|
||||
void SetRight(XTab* right);
|
||||
void SetRight(XTab* right);
|
||||
YTab* Top() const;
|
||||
void SetTop(YTab* top);
|
||||
void SetTop(YTab* top);
|
||||
YTab* Bottom() const;
|
||||
void SetBottom(YTab* bottom);
|
||||
void SetBottom(YTab* bottom);
|
||||
Row* GetRow() const;
|
||||
void SetRow(Row* row);
|
||||
void SetRow(Row* row);
|
||||
Column* GetColumn() const;
|
||||
void SetColumn(Column* column);
|
||||
void SetColumn(Column* column);
|
||||
BView* Content() const;
|
||||
void SetContent(BView* content);
|
||||
void SetContent(BView* content);
|
||||
XTab* ContentLeft() const;
|
||||
YTab* ContentTop() const;
|
||||
XTab* ContentRight() const;
|
||||
YTab* ContentBottom() const;
|
||||
BSize MinContentSize() const;
|
||||
void SetMinContentSize(BSize min);
|
||||
void SetMinContentSize(BSize min);
|
||||
BSize MaxContentSize() const;
|
||||
void SetMaxContentSize(BSize max);
|
||||
void SetMaxContentSize(BSize max);
|
||||
BSize PrefContentSize() const;
|
||||
void SetPrefContentSize(BSize pref);
|
||||
void SetPrefContentSize(BSize pref);
|
||||
BSize ShrinkRigidity() const;
|
||||
void SetShrinkRigidity(BSize shrink);
|
||||
void SetShrinkRigidity(BSize shrink);
|
||||
BSize ExpandRigidity() const;
|
||||
void SetExpandRigidity(BSize expand);
|
||||
void SetExpandRigidity(BSize expand);
|
||||
double ContentAspectRatio() const;
|
||||
void SetContentAspectRatio(double ratio);
|
||||
void SetContentAspectRatio(double ratio);
|
||||
BAlignment Alignment() const;
|
||||
void SetAlignment(BAlignment alignment);
|
||||
void SetHAlignment(alignment horizontal);
|
||||
void SetVAlignment(vertical_alignment vertical);
|
||||
void SetAlignment(BAlignment alignment);
|
||||
void SetHAlignment(alignment horizontal);
|
||||
void SetVAlignment(vertical_alignment vertical);
|
||||
int32 LeftInset() const;
|
||||
void SetLeftInset(int32 left);
|
||||
void SetLeftInset(int32 left);
|
||||
int32 TopInset() const;
|
||||
void SetTopInset(int32 top);
|
||||
void SetTopInset(int32 top);
|
||||
int32 RightInset() const;
|
||||
void SetRightInset(int32 right);
|
||||
void SetRightInset(int32 right);
|
||||
int32 BottomInset() const;
|
||||
void SetBottomInset(int32 bottom);
|
||||
void SetDefaultPrefContentSize();
|
||||
//~ string ToString();
|
||||
void SetBottomInset(int32 bottom);
|
||||
void SetDefaultPrefContentSize();
|
||||
//~ string ToString();
|
||||
Constraint* HasSameWidthAs(Area* area);
|
||||
Constraint* HasSameHeightAs(Area* area);
|
||||
BList* HasSameSizetAs(Area* area);
|
||||
@ -84,7 +89,7 @@ protected:
|
||||
Area(BALMLayout* ls, Row* row, Column* column,
|
||||
BView* content,
|
||||
BSize minContentSize);
|
||||
void DoLayout();
|
||||
void DoLayout();
|
||||
|
||||
private:
|
||||
void InitChildArea();
|
||||
@ -124,8 +129,8 @@ private:
|
||||
double fContentAspectRatio;
|
||||
Constraint* fContentAspectRatioC;
|
||||
bool fAutoPrefContentSize;
|
||||
SoftConstraint* fPrefContentWidth;
|
||||
SoftConstraint* fPrefContentHeight;
|
||||
Constraint* fPrefContentWidth;
|
||||
Constraint* fPrefContentHeight;
|
||||
Area* fChildArea;
|
||||
BAlignment fAlignment;
|
||||
int32 fLeftInset;
|
||||
|
@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BALM_LAYOUT_H
|
||||
#define BALM_LAYOUT_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.
|
||||
*/
|
||||
|
||||
#ifndef COLUMN_H
|
||||
#define COLUMN_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.
|
||||
*/
|
||||
|
||||
#ifndef LAYOUT_STYLE_TYPE_H
|
||||
#define LAYOUT_STYLE_TYPE_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.
|
||||
*/
|
||||
|
||||
#ifndef ROW_H
|
||||
#define ROW_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.
|
||||
*/
|
||||
|
||||
#ifndef X_TAB_H
|
||||
#define X_TAB_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.
|
||||
*/
|
||||
|
||||
#ifndef Y_TAB_H
|
||||
#define Y_TAB_H
|
||||
|
||||
|
@ -1,11 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CONSTRAINT_H
|
||||
#define CONSTRAINT_H
|
||||
|
||||
#include "OperatorType.h"
|
||||
#include "Variable.h"
|
||||
#include "ObjFunctionSummand.h"
|
||||
|
||||
#include <List.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
@ -20,32 +29,51 @@ class Constraint {
|
||||
|
||||
public:
|
||||
int32 Index();
|
||||
BList* Coeffs();
|
||||
BList* Vars();
|
||||
virtual void ChangeLeftSide(BList* coeffs, BList* vars);
|
||||
virtual OperatorType Op();
|
||||
virtual void SetOp(OperatorType value);
|
||||
BList* Summands();
|
||||
void ChangeLeftSide(BList* summands);
|
||||
void ChangeLeftSide(double coeff1, Variable* var1);
|
||||
void ChangeLeftSide(double coeff1, Variable* var1,
|
||||
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();
|
||||
void SetRightSide(double value);
|
||||
BString ToString();
|
||||
virtual ~Constraint();
|
||||
void SetRightSide(double value);
|
||||
double PenaltyNeg();
|
||||
void SetPenaltyNeg(double value);
|
||||
double PenaltyPos();
|
||||
void SetPenaltyPos(double value);
|
||||
Variable* DNeg() const;
|
||||
Variable* DPos() const;
|
||||
|
||||
BString ToString();
|
||||
~Constraint();
|
||||
|
||||
protected:
|
||||
Constraint();
|
||||
Constraint(LinearSpec* ls, BList* summands,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
|
||||
private:
|
||||
Constraint(LinearSpec* ls, BList* coeffs, BList* vars,
|
||||
OperatorType op, double rightSide);
|
||||
|
||||
protected:
|
||||
LinearSpec* fLS;
|
||||
BList* fCoeffs;
|
||||
BList* fVars;
|
||||
OperatorType fOp;
|
||||
BList* fSummands;
|
||||
OperatorType fOp;
|
||||
double fRightSide;
|
||||
Variable* fDNeg;
|
||||
Variable* fDPos;
|
||||
ObjFunctionSummand* fDNegSummand;
|
||||
ObjFunctionSummand* fDPosSummand;
|
||||
|
||||
void _UpdateLeftSide();
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
friend class LinearSpec;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
||||
#ifndef LINEAR_SPEC_H
|
||||
#define LINEAR_SPEC_H
|
||||
|
||||
@ -10,6 +16,7 @@
|
||||
#include <List.h>
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
@ -17,7 +24,6 @@ namespace LinearProgramming {
|
||||
class Constraint;
|
||||
class ObjFunctionSummand;
|
||||
class PenaltyFunction;
|
||||
class SoftConstraint;
|
||||
class Variable;
|
||||
|
||||
/**
|
||||
@ -28,81 +34,81 @@ class LinearSpec {
|
||||
public:
|
||||
LinearSpec();
|
||||
~LinearSpec();
|
||||
void UpdateObjFunction();
|
||||
void SetObjFunction(BList* coeffs, BList* vars);
|
||||
void UpdateObjFunction();
|
||||
void SetObjFunction(BList* summands);
|
||||
ObjFunctionSummand* AddObjFunctionSummand(double coeff, Variable* var);
|
||||
Variable* AddVariable();
|
||||
Variable* AddVariable();
|
||||
|
||||
Constraint* AddConstraint(BList* coeffs, BList* vars,
|
||||
Constraint* AddConstraint(BList* summands,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
double coeff4, Variable* var4,
|
||||
OperatorType op, double rightSide);
|
||||
|
||||
SoftConstraint* AddSoftConstraint(BList* coeffs, BList* vars,
|
||||
Constraint* AddConstraint(BList* summands,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
double coeff4, Variable* var4,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
|
||||
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
|
||||
void RemovePresolved();
|
||||
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
|
||||
void RemovePresolved();
|
||||
ResultType Presolve();
|
||||
ResultType Solve();
|
||||
void Save(char* fname);
|
||||
void Save(char* fname);
|
||||
|
||||
int32 Columns() const;
|
||||
void SetColumns(int32 value);
|
||||
OptimizationType Optimization() const;
|
||||
void SetOptimization(OptimizationType value);
|
||||
void SetColumns(int32 value);
|
||||
OptimizationType Optimization() const;
|
||||
void SetOptimization(OptimizationType value);
|
||||
lprec* LP() const;
|
||||
void SetLP(lprec* value);
|
||||
void SetLP(lprec* value);
|
||||
BList* ObjFunctionSummands() const;
|
||||
void SetObjFunctionSummands(BList* value);
|
||||
void SetObjFunctionSummands(BList* value);
|
||||
BList* Variables() const;
|
||||
void SetVariables(BList* value);
|
||||
void SetVariables(BList* value);
|
||||
BList* Constraints() const;
|
||||
void SetConstraints(BList* value);
|
||||
void SetConstraints(BList* value);
|
||||
ResultType Result() const;
|
||||
void SetResult(ResultType value);
|
||||
void SetResult(ResultType value);
|
||||
double ObjectiveValue() const;
|
||||
void SetObjectiveValue(double value);
|
||||
void SetObjectiveValue(double value);
|
||||
double SolvingTime() const;
|
||||
void SetSolvingTime(double value);
|
||||
void SetSolvingTime(double value);
|
||||
|
||||
protected:
|
||||
int32 fColumns;
|
||||
|
||||
private:
|
||||
lprec* fLpPresolved;
|
||||
OptimizationType fOptimization;
|
||||
OptimizationType fOptimization;
|
||||
lprec* fLP;
|
||||
BList* fObjFunctionSummands;
|
||||
BList* fVariables;
|
||||
@ -112,8 +118,8 @@ private:
|
||||
double fSolvingTime; // = Double.Nan
|
||||
|
||||
public:
|
||||
friend class ObjFunctionSummand;
|
||||
friend class SoftConstraint;
|
||||
friend class ObjFunctionSummand;
|
||||
friend class Constraint;
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,6 +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.
|
||||
*/
|
||||
|
||||
#ifndef OBJ_FUNCTION_SUMMAND_H
|
||||
#define OBJ_FUNCTION_SUMMAND_H
|
||||
|
||||
#include "Summand.h"
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
@ -10,25 +18,21 @@ class Variable;
|
||||
/**
|
||||
* A summand of the objective function.
|
||||
*/
|
||||
class ObjFunctionSummand {
|
||||
class ObjFunctionSummand : public Summand {
|
||||
|
||||
public:
|
||||
double Coeff();
|
||||
void SetCoeff(double coeff);
|
||||
Variable* Var();
|
||||
void SetVar(Variable* var);
|
||||
~ObjFunctionSummand();
|
||||
void SetCoeff(double coeff);
|
||||
void SetVar(Variable* var);
|
||||
~ObjFunctionSummand();
|
||||
|
||||
protected:
|
||||
ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var);
|
||||
|
||||
private:
|
||||
LinearSpec* fLS;
|
||||
double fCoeff;
|
||||
Variable* fVar;
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
friend class LinearSpec;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OPERATOR_TYPE_H
|
||||
#define OPERATOR_TYPE_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.
|
||||
*/
|
||||
|
||||
#ifndef OPTIMIZATION_TYPE_H
|
||||
#define OPTIMIZATION_TYPE_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.
|
||||
*/
|
||||
|
||||
#ifndef PENALTY_FUNCTION_H
|
||||
#define PENALTY_FUNCTION_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.
|
||||
*/
|
||||
|
||||
#ifndef 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
|
39
headers/libs/linprog/Summand.h
Normal file
39
headers/libs/linprog/Summand.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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, lutteroth@cs.auckland.ac.nz
|
||||
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef VARIABLE_H
|
||||
#define VARIABLE_H
|
||||
|
||||
@ -17,15 +23,15 @@ class Variable {
|
||||
public:
|
||||
int32 Index();
|
||||
LinearSpec* LS() const;
|
||||
void SetLS(LinearSpec* value);
|
||||
void SetLS(LinearSpec* value);
|
||||
double Value() const;
|
||||
void SetValue(double value);
|
||||
void SetValue(double value);
|
||||
double Min() const;
|
||||
void SetMin(double min);
|
||||
void SetMin(double min);
|
||||
double Max() const;
|
||||
void SetMax(double max);
|
||||
void SetRange(double min, double max);
|
||||
//~ string ToString();
|
||||
void SetMax(double max);
|
||||
void SetRange(double min, double max);
|
||||
//~ string ToString();
|
||||
Constraint* IsEqual(Variable* var);
|
||||
Constraint* IsSmallerOrEqual(Variable* var);
|
||||
Constraint* IsGreaterorEqual(Variable* var);
|
||||
@ -42,7 +48,7 @@ private:
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
friend class SoftConstraint;
|
||||
friend class 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 "Area.h"
|
||||
#include "Column.h"
|
||||
#include "BALMLayout.h"
|
||||
@ -71,23 +77,10 @@ Area::SetLeft(XTab* left)
|
||||
fColumn = NULL;
|
||||
|
||||
if (fChildArea == NULL) {
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
fMinContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||
|
||||
if (fMaxContentWidth != NULL) {
|
||||
BList* coeffs2 = new BList(2);
|
||||
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);
|
||||
}
|
||||
if (fMaxContentWidth != NULL)
|
||||
fMaxContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||
} else
|
||||
UpdateHorizontal();
|
||||
fLS->InvalidateLayout();
|
||||
@ -119,23 +112,10 @@ Area::SetRight(XTab* right)
|
||||
fColumn = NULL;
|
||||
|
||||
if (fChildArea == NULL) {
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
fMinContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||
|
||||
if (fMaxContentWidth != NULL) {
|
||||
BList* coeffs2 = new BList(2);
|
||||
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);
|
||||
}
|
||||
if (fMaxContentWidth != NULL)
|
||||
fMaxContentWidth->ChangeLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||
} else
|
||||
UpdateHorizontal();
|
||||
fLS->InvalidateLayout();
|
||||
@ -163,23 +143,10 @@ Area::SetTop(YTab* top)
|
||||
fRow = NULL;
|
||||
|
||||
if (fChildArea == NULL) {
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
fMinContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||
|
||||
if (fMaxContentHeight != NULL) {
|
||||
BList* coeffs2 = new BList(2);
|
||||
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);
|
||||
}
|
||||
if (fMaxContentHeight != NULL)
|
||||
fMaxContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||
} else
|
||||
UpdateVertical();
|
||||
fLS->InvalidateLayout();
|
||||
@ -207,23 +174,10 @@ Area::SetBottom(YTab* bottom)
|
||||
fRow = NULL;
|
||||
|
||||
if (fChildArea == NULL) {
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
fMinContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||
|
||||
if (fMaxContentHeight != NULL) {
|
||||
BList* coeffs2 = new BList(2);
|
||||
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);
|
||||
}
|
||||
if (fMaxContentHeight != NULL)
|
||||
fMaxContentHeight->ChangeLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||
} else
|
||||
UpdateVertical();
|
||||
fLS->InvalidateLayout();
|
||||
@ -385,23 +339,11 @@ Area::SetMaxContentSize(BSize max)
|
||||
if (fChildArea == NULL) {
|
||||
fMaxContentSize = max;
|
||||
if (fMaxContentWidth == NULL) {
|
||||
BList* coeffs = new BList(2);
|
||||
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),
|
||||
fMaxContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(LE),
|
||||
fMaxContentSize.Width());
|
||||
fConstraints->AddItem(fMaxContentWidth);
|
||||
|
||||
BList* coeffs2 = new BList(2);
|
||||
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),
|
||||
fMaxContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, OperatorType(LE),
|
||||
fMaxContentSize.Height());
|
||||
fConstraints->AddItem(fMaxContentHeight);
|
||||
} else {
|
||||
@ -435,24 +377,12 @@ Area::SetPrefContentSize(BSize pref)
|
||||
if (fChildArea == NULL) {
|
||||
fPrefContentSize = pref;
|
||||
if (fPrefContentWidth == NULL) {
|
||||
BList* coeffs = new BList(2);
|
||||
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),
|
||||
fPrefContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(EQ),
|
||||
fPrefContentSize.Width(), fShrinkRigidity.Width(),
|
||||
fExpandRigidity.Width());
|
||||
fConstraints->AddItem(fPrefContentWidth);
|
||||
|
||||
BList* coeffs2 = new BList(2);
|
||||
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),
|
||||
fPrefContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, OperatorType(EQ),
|
||||
fPrefContentSize.Height(), fShrinkRigidity.Height(),
|
||||
fExpandRigidity.Height());
|
||||
fConstraints->AddItem(fPrefContentHeight);
|
||||
@ -536,31 +466,13 @@ Area::SetContentAspectRatio(double ratio)
|
||||
if (fChildArea == NULL) {
|
||||
fContentAspectRatio = ratio;
|
||||
if (fContentAspectRatioC == NULL) {
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(-1.0));
|
||||
coeffs->AddItem(new double(1.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);
|
||||
fContentAspectRatioC = fLS->AddConstraint(
|
||||
-1.0, fLeft, 1.0, fRight, ratio, fTop, -ratio, fBottom,
|
||||
OperatorType(EQ), 0.0);
|
||||
fConstraints->AddItem(fContentAspectRatioC);
|
||||
} else {
|
||||
BList* coeffs2 = new BList(4);
|
||||
coeffs2->AddItem(new double(-1.0));
|
||||
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);
|
||||
fContentAspectRatioC->ChangeLeftSide(
|
||||
-1.0, fLeft, 1.0, fRight, ratio, fTop, -ratio, fBottom);
|
||||
}
|
||||
} else
|
||||
fChildArea->SetContentAspectRatio(ratio);
|
||||
@ -586,7 +498,6 @@ Area::SetAlignment(BAlignment alignment)
|
||||
{
|
||||
fAlignment = alignment;
|
||||
UpdateHorizontal();
|
||||
fLS->InvalidateLayout();
|
||||
UpdateVertical();
|
||||
fLS->InvalidateLayout();
|
||||
}
|
||||
@ -751,17 +662,9 @@ Area::SetDefaultPrefContentSize()
|
||||
Constraint*
|
||||
Area::HasSameWidthAs(Area* area)
|
||||
{
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(-1.0));
|
||||
coeffs->AddItem(new double(1.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);
|
||||
return fLS->AddConstraint(
|
||||
-1.0, fLeft, 1.0, fRight, 1.0, area->fLeft, -1.0, area->fRight,
|
||||
OperatorType(EQ), 0.0);
|
||||
}
|
||||
|
||||
|
||||
@ -774,17 +677,9 @@ Area::HasSameWidthAs(Area* area)
|
||||
Constraint*
|
||||
Area::HasSameHeightAs(Area* area)
|
||||
{
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(-1.0));
|
||||
coeffs->AddItem(new double(1.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);
|
||||
return fLS->AddConstraint(
|
||||
-1.0, fTop, 1.0, fBottom, 1.0, area->fTop, -1.0, area->fBottom,
|
||||
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
|
||||
// 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);
|
||||
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),
|
||||
fMinContentWidth = ls->AddConstraint(-1.0, left, 1.0, right, OperatorType(GE),
|
||||
minContentSize.Width());
|
||||
fConstraints->AddItem(fMinContentWidth);
|
||||
|
||||
BList* coeffs2 = new BList(2);
|
||||
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),
|
||||
fMinContentHeight = ls->AddConstraint(-1.0, top, 1.0, bottom, OperatorType(GE),
|
||||
minContentSize.Height());
|
||||
fConstraints->AddItem(fMinContentHeight);
|
||||
}
|
||||
@ -946,13 +829,13 @@ Area::InitChildArea()
|
||||
// coresponding tabs of this area (for a start)
|
||||
fChildArea = new Area(fLS, new XTab(fLS), new YTab(fLS), new XTab(fLS),
|
||||
new YTab(fLS), fContent, BSize(0, 0));
|
||||
fLeftConstraint = Left()->IsEqual(fChildArea->Left());
|
||||
fLeftConstraint = fLeft->IsEqual(fChildArea->Left());
|
||||
fConstraints->AddItem(fLeftConstraint);
|
||||
fTopConstraint = Top()->IsEqual(fChildArea->Top());
|
||||
fTopConstraint = fTop->IsEqual(fChildArea->Top());
|
||||
fConstraints->AddItem(fTopConstraint);
|
||||
fRightConstraint = Right()->IsEqual(fChildArea->Right());
|
||||
fRightConstraint = fRight->IsEqual(fChildArea->Right());
|
||||
fConstraints->AddItem(fRightConstraint);
|
||||
fBottomConstraint = Bottom()->IsEqual(fChildArea->Bottom());
|
||||
fBottomConstraint = fBottom->IsEqual(fChildArea->Bottom());
|
||||
fConstraints->AddItem(fBottomConstraint);
|
||||
|
||||
// remove the minimum content size constraints from this area
|
||||
@ -972,22 +855,10 @@ Area::InitChildArea()
|
||||
fChildArea->fMaxContentSize = fMaxContentSize;
|
||||
|
||||
fChildArea->fMaxContentWidth = fMaxContentWidth;
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
fMaxContentWidth->ChangeLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
|
||||
|
||||
fChildArea->fMaxContentHeight = fMaxContentHeight;
|
||||
BList* coeffs2 = new BList(2);
|
||||
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);
|
||||
fMaxContentHeight->ChangeLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
|
||||
}
|
||||
|
||||
// if there are preferred content size constraints on this area,
|
||||
@ -999,22 +870,10 @@ Area::InitChildArea()
|
||||
fChildArea->fExpandRigidity = fExpandRigidity;
|
||||
|
||||
fChildArea->fPrefContentWidth = fPrefContentWidth;
|
||||
BList* coeffs3 = new BList(2);
|
||||
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);
|
||||
fPrefContentWidth->ChangeLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
|
||||
|
||||
fChildArea->fPrefContentHeight = fPrefContentHeight;
|
||||
BList* coeffs4 = new BList(2);
|
||||
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);
|
||||
fPrefContentHeight->ChangeLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1028,116 +887,47 @@ Area::UpdateHorizontal()
|
||||
// if the area does not have a childAdrea yet, this is the time to add it
|
||||
if (fChildArea == NULL)
|
||||
InitChildArea();
|
||||
|
||||
BList* coeffs;
|
||||
BList* coeffs2;
|
||||
BList* vars;
|
||||
BList* vars2;
|
||||
|
||||
|
||||
// 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
|
||||
if (fAlignment.Horizontal() == B_ALIGN_LEFT) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||
fLeftConstraint->SetOp(OperatorType(EQ));
|
||||
fLeftConstraint->SetRightSide(fLeftInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||
fRightConstraint->SetOp(OperatorType(GE));
|
||||
fRightConstraint->SetRightSide(fRightInset);
|
||||
} else if (fAlignment.Horizontal() == B_ALIGN_RIGHT) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||
fLeftConstraint->SetOp(OperatorType(GE));
|
||||
fLeftConstraint->SetRightSide(fLeftInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||
fRightConstraint->SetOp(OperatorType(EQ));
|
||||
fRightConstraint->SetRightSide(fRightInset);
|
||||
} else if (fAlignment.Horizontal() == B_ALIGN_HORIZONTAL_CENTER) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||
fLeftConstraint->SetOp(OperatorType(GE));
|
||||
fLeftConstraint->SetRightSide(max(fLeftInset, fRightInset));
|
||||
|
||||
coeffs2 = new BList(4);
|
||||
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->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left(), 1.0, fChildArea->Right(), -1.0, fRight);
|
||||
fRightConstraint->SetOp(OperatorType(EQ));
|
||||
fRightConstraint->SetRightSide(0);
|
||||
} else if (fAlignment.Horizontal() == B_ALIGN_USE_FULL_WIDTH) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||
fLeftConstraint->SetOp(OperatorType(EQ));
|
||||
fLeftConstraint->SetRightSide(fLeftInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||
fRightConstraint->SetOp(OperatorType(EQ));
|
||||
fRightConstraint->SetRightSide(fRightInset);
|
||||
} else if (fAlignment.Horizontal() == B_ALIGN_HORIZONTAL_UNSET) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fLeft, 1.0, fChildArea->Left());
|
||||
fLeftConstraint->SetOp(OperatorType(GE));
|
||||
fLeftConstraint->SetRightSide(fLeftInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Right(), 1.0, fRight);
|
||||
fRightConstraint->SetOp(OperatorType(GE));
|
||||
fRightConstraint->SetRightSide(fRightInset);
|
||||
}
|
||||
@ -1152,115 +942,46 @@ void Area::UpdateVertical() {
|
||||
if (fChildArea == NULL)
|
||||
InitChildArea();
|
||||
|
||||
BList* coeffs;
|
||||
BList* coeffs2;
|
||||
BList* vars;
|
||||
BList* vars2;
|
||||
|
||||
// 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
|
||||
if (fAlignment.Vertical() == B_ALIGN_TOP) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||
fTopConstraint->SetOp(OperatorType(EQ));
|
||||
fTopConstraint->SetRightSide(fTopInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||
fBottomConstraint->SetOp(OperatorType(GE));
|
||||
fBottomConstraint->SetRightSide(fBottomInset);
|
||||
} else if (fAlignment.Vertical() == B_ALIGN_BOTTOM) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||
fTopConstraint->SetOp(OperatorType(GE));
|
||||
fTopConstraint->SetRightSide(fTopInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||
fBottomConstraint->SetOp(OperatorType(EQ));
|
||||
fBottomConstraint->SetRightSide(fBottomInset);
|
||||
} else if (fAlignment.Vertical() == B_ALIGN_VERTICAL_CENTER) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||
fTopConstraint->SetOp(OperatorType(GE));
|
||||
fTopConstraint->SetRightSide(max(fTopInset, fBottomInset));
|
||||
|
||||
coeffs2 = new BList(4);
|
||||
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->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top(), 1.0, fChildArea->Bottom(), -1.0, fBottom);
|
||||
fBottomConstraint->SetOp(OperatorType(EQ));
|
||||
fBottomConstraint->SetRightSide(0);
|
||||
} else if (fAlignment.Vertical() == B_ALIGN_USE_FULL_HEIGHT) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||
fTopConstraint->SetOp(OperatorType(EQ));
|
||||
fTopConstraint->SetRightSide(fTopInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||
fBottomConstraint->SetOp(OperatorType(EQ));
|
||||
fBottomConstraint->SetRightSide(fBottomInset);
|
||||
} else if (fAlignment.Vertical() == B_ALIGN_VERTICAL_UNSET) {
|
||||
coeffs = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fTop, 1.0, fChildArea->Top());
|
||||
fTopConstraint->SetOp(OperatorType(GE));
|
||||
fTopConstraint->SetRightSide(fTopInset);
|
||||
|
||||
coeffs2 = new BList(2);
|
||||
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->ChangeLeftSide(-1.0, fChildArea->Bottom(), 1.0, fBottom);
|
||||
fBottomConstraint->SetOp(OperatorType(GE));
|
||||
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 "Area.h"
|
||||
#include "Column.h"
|
||||
@ -224,7 +230,7 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
|
||||
View()->AddChild(content);
|
||||
Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0));
|
||||
area->SetDefaultPrefContentSize();
|
||||
area->SetAutoPrefContentSize(true);
|
||||
area->SetAutoPrefContentSize(false);
|
||||
fAreas->AddItem(area);
|
||||
return area;
|
||||
}
|
||||
@ -246,7 +252,7 @@ BALMLayout::AddArea(Row* row, Column* column, BView* content)
|
||||
View()->AddChild(content);
|
||||
Area* area = new Area(this, row, column, content, BSize(0, 0));
|
||||
area->SetDefaultPrefContentSize();
|
||||
area->SetAutoPrefContentSize(true);
|
||||
area->SetAutoPrefContentSize(false);
|
||||
fAreas->AddItem(area);
|
||||
return area;
|
||||
}
|
||||
|
@ -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 "BALMLayout.h"
|
||||
#include "OperatorType.h"
|
||||
@ -152,19 +158,9 @@ Column::InsertAfter(Column* column)
|
||||
Constraint*
|
||||
Column::HasSameWidthAs(Column* column)
|
||||
{
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(-1.0));
|
||||
coeffs->AddItem(new double(1.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);
|
||||
Constraint* constraint = fLS->AddConstraint(
|
||||
-1.0, fLeft, 1.0, fRight, 1.0, column->fLeft, -1.0, column->fRight,
|
||||
OperatorType(EQ), 0.0);
|
||||
fConstraints->AddItem(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 "Row.h"
|
||||
#include "BALMLayout.h"
|
||||
#include "OperatorType.h"
|
||||
@ -154,19 +160,9 @@ Row::InsertAfter(Row* row)
|
||||
Constraint*
|
||||
Row::HasSameHeightAs(Row* row)
|
||||
{
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(-1.0));
|
||||
coeffs->AddItem(new double(1.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);
|
||||
Constraint* constraint = fLS->AddConstraint(
|
||||
-1.0, fTop, 1.0, fBottom, 1.0, row->fTop, -1.0, row->fBottom,
|
||||
OperatorType(EQ), 0.0);
|
||||
fConstraints->AddItem(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 "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 "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 "Constraint.h"
|
||||
#include "LinearSpec.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*
|
||||
Constraint::Coeffs()
|
||||
Constraint::Summands()
|
||||
{
|
||||
return fCoeffs;
|
||||
return fSummands;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the variables of the constraint.
|
||||
*
|
||||
* @return the variables of the constraint
|
||||
*/
|
||||
BList*
|
||||
Constraint::Vars()
|
||||
void
|
||||
Constraint::_UpdateLeftSide()
|
||||
{
|
||||
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.
|
||||
* There must be exactly one coefficient for each variable.
|
||||
*
|
||||
* @param coeffs the new coefficients
|
||||
* @param vars the new variables
|
||||
* @param summands a BList containing the Summand objects that make up the new left side
|
||||
*/
|
||||
void
|
||||
Constraint::ChangeLeftSide(BList* coeffs, BList* vars)
|
||||
Constraint::ChangeLeftSide(BList* summands)
|
||||
{
|
||||
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;
|
||||
|
||||
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();
|
||||
fSummands = summands;
|
||||
_UpdateLeftSide();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Constraint::ChangeLeftSide(double coeff1, Variable* var1)
|
||||
{
|
||||
fSummands->MakeEmpty();
|
||||
fSummands->AddItem(new Summand(coeff1, var1));
|
||||
_UpdateLeftSide();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
//~ string s = "";
|
||||
//~ for (int32 i = 0; i < fVars->CountItems(); i++)
|
||||
//~ s += (double)fCoeffs->ItemAt(i) + "*" + (Variable*)fVars->ItemAt(i).ToString() + " + ";
|
||||
//~ s = s.Substring(0, s.Length - 2);
|
||||
//~ if (Op == OperatorType.EQ) s += "= ";
|
||||
//~ else if (Op == OperatorType.GE) s += ">= ";
|
||||
//~ else s += "<= ";
|
||||
//~ s += rightSide.ToString();
|
||||
//~ return s;
|
||||
//~ }
|
||||
/**
|
||||
* Gets the penalty coefficient for negative deviations.
|
||||
*
|
||||
* @return the penalty coefficient
|
||||
*/
|
||||
double
|
||||
Constraint::PenaltyNeg()
|
||||
{
|
||||
if (fDNegSummand == NULL)
|
||||
return INFINITY;
|
||||
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()
|
||||
{
|
||||
del_constraint(fLS->LP(), Index());
|
||||
delete fCoeffs;
|
||||
delete fVars;
|
||||
delete fSummands;
|
||||
if(fDNegSummand != NULL) {
|
||||
delete fDNegSummand->Var();
|
||||
delete fDNegSummand;
|
||||
}
|
||||
if(fDPosSummand != NULL) {
|
||||
delete fDPosSummand->Var();
|
||||
delete fDPosSummand;
|
||||
}
|
||||
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 :
|
||||
Constraint.cpp
|
||||
LinearSpec.cpp
|
||||
Summand.cpp
|
||||
ObjFunctionSummand.cpp
|
||||
PenaltyFunction.cpp
|
||||
SoftConstraint.cpp
|
||||
Variable.cpp
|
||||
:
|
||||
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 "Constraint.h"
|
||||
#include "ObjFunctionSummand.h"
|
||||
#include "PenaltyFunction.h"
|
||||
#include "SoftConstraint.h"
|
||||
#include "Constraint.h"
|
||||
#include "Variable.h"
|
||||
|
||||
#include "lp_lib.h"
|
||||
@ -46,17 +52,17 @@ LinearSpec::~LinearSpec()
|
||||
void
|
||||
LinearSpec::UpdateObjFunction()
|
||||
{
|
||||
int32 size = fObjFunctionSummands->CountItems();;
|
||||
int32 size = fObjFunctionSummands->CountItems();
|
||||
double coeffs[size];
|
||||
int vIndexes[size];
|
||||
int varIndexes[size];
|
||||
ObjFunctionSummand* current;
|
||||
for (int32 i = 0; i < size; i++) {
|
||||
current = (ObjFunctionSummand*)fObjFunctionSummands->ItemAt(i);
|
||||
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.");
|
||||
|
||||
RemovePresolved();
|
||||
@ -70,18 +76,9 @@ LinearSpec::UpdateObjFunction()
|
||||
* @param vars the objective function's variables
|
||||
*/
|
||||
void
|
||||
LinearSpec::SetObjFunction(BList* coeffs, BList* vars)
|
||||
LinearSpec::SetObjFunction(BList* summands)
|
||||
{
|
||||
int32 sizeCoeffs = coeffs->CountItems();
|
||||
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)));
|
||||
|
||||
fObjFunctionSummands = summands;
|
||||
UpdateObjFunction();
|
||||
}
|
||||
|
||||
@ -125,10 +122,10 @@ LinearSpec::AddVariable()
|
||||
* @return the new constraint
|
||||
*/
|
||||
Constraint*
|
||||
LinearSpec::AddConstraint(BList* coeffs, BList* vars, OperatorType op,
|
||||
double rightSide)
|
||||
LinearSpec::AddConstraint(BList* summands, OperatorType op, double rightSide)
|
||||
{
|
||||
Constraint* c = new Constraint(this, coeffs, vars, op, rightSide);
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
INFINITY, INFINITY);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
@ -147,11 +144,11 @@ Constraint*
|
||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
OperatorType op, double rightSide)
|
||||
{
|
||||
BList* coeffs = new BList(1);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
BList* vars = new BList(1);
|
||||
vars->AddItem(var1);
|
||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
||||
BList* summands = new BList(1);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
INFINITY, INFINITY);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -171,13 +168,12 @@ Constraint*
|
||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2, OperatorType op, double rightSide)
|
||||
{
|
||||
BList* coeffs = new BList(2);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
coeffs->AddItem(new double(coeff2));
|
||||
BList* vars = new BList(2);
|
||||
vars->AddItem(var1);
|
||||
vars->AddItem(var2);
|
||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
||||
BList* summands = new BList(2);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
summands->AddItem(new Summand(coeff2, var2));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
INFINITY, INFINITY);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -200,15 +196,13 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||
OperatorType op, double rightSide)
|
||||
{
|
||||
BList* coeffs = new BList(3);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
coeffs->AddItem(new double(coeff2));
|
||||
coeffs->AddItem(new double(coeff3));
|
||||
BList* vars = new BList(3);
|
||||
vars->AddItem(var1);
|
||||
vars->AddItem(var2);
|
||||
vars->AddItem(var3);
|
||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
||||
BList* summands = new BList(3);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
summands->AddItem(new Summand(coeff2, var2));
|
||||
summands->AddItem(new Summand(coeff3, var3));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
INFINITY, INFINITY);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -233,17 +227,14 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||
double coeff4, Variable* var4, OperatorType op, double rightSide)
|
||||
{
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
coeffs->AddItem(new double(coeff2));
|
||||
coeffs->AddItem(new double(coeff3));
|
||||
coeffs->AddItem(new double(coeff4));
|
||||
BList* vars = new BList(4);
|
||||
vars->AddItem(var1);
|
||||
vars->AddItem(var2);
|
||||
vars->AddItem(var3);
|
||||
vars->AddItem(var4);
|
||||
Constraint* c = AddConstraint(coeffs, vars, op, rightSide);
|
||||
BList* summands = new BList(3);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
summands->AddItem(new Summand(coeff2, var2));
|
||||
summands->AddItem(new Summand(coeff3, var3));
|
||||
summands->AddItem(new Summand(coeff4, var4));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
INFINITY, INFINITY);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -259,13 +250,12 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||
*/
|
||||
SoftConstraint*
|
||||
LinearSpec::AddSoftConstraint(BList* coeffs, BList* vars, OperatorType op,
|
||||
Constraint*
|
||||
LinearSpec::AddConstraint(BList* summands, OperatorType op,
|
||||
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);
|
||||
|
||||
RemovePresolved();
|
||||
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 penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||
*/
|
||||
SoftConstraint*
|
||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint*
|
||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
|
||||
{
|
||||
BList* coeffs = new BList(1);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
BList* vars = new BList(1);
|
||||
vars->AddItem(var1);
|
||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
||||
BList* summands = new BList(1);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
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 penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||
*/
|
||||
SoftConstraint*
|
||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint*
|
||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2, OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos)
|
||||
{
|
||||
BList* coeffs = new BList(2);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
coeffs->AddItem(new double(coeff2));
|
||||
BList* vars = new BList(2);
|
||||
vars->AddItem(var1);
|
||||
vars->AddItem(var2);
|
||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
||||
penaltyNeg, penaltyPos);
|
||||
return c;
|
||||
BList* summands = new BList(2);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
summands->AddItem(new Summand(coeff2, var2));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
penaltyNeg, penaltyPos);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@ -338,21 +325,18 @@ LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||
*/
|
||||
SoftConstraint*
|
||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint*
|
||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
|
||||
{
|
||||
BList* coeffs = new BList(3);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
coeffs->AddItem(new double(coeff2));
|
||||
coeffs->AddItem(new double(coeff3));
|
||||
BList* vars = new BList(3);
|
||||
vars->AddItem(var1);
|
||||
vars->AddItem(var2);
|
||||
vars->AddItem(var3);
|
||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
||||
penaltyNeg, penaltyPos);
|
||||
BList* summands = new BList(2);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
summands->AddItem(new Summand(coeff2, var2));
|
||||
summands->AddItem(new Summand(coeff3, var3));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
penaltyNeg, penaltyPos);
|
||||
RemovePresolved();
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -373,24 +357,20 @@ LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
||||
* @param penaltyNeg the coefficient penalizing negative deviations from the exact solution
|
||||
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution
|
||||
*/
|
||||
SoftConstraint*
|
||||
LinearSpec::AddSoftConstraint(double coeff1, Variable* var1,
|
||||
Constraint*
|
||||
LinearSpec::AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2, double coeff3, Variable* var3,
|
||||
double coeff4, Variable* var4, OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos)
|
||||
{
|
||||
BList* coeffs = new BList(4);
|
||||
coeffs->AddItem(new double(coeff1));
|
||||
coeffs->AddItem(new double(coeff2));
|
||||
coeffs->AddItem(new double(coeff3));
|
||||
coeffs->AddItem(new double(coeff4));
|
||||
BList* vars = new BList(4);
|
||||
vars->AddItem(var1);
|
||||
vars->AddItem(var2);
|
||||
vars->AddItem(var3);
|
||||
vars->AddItem(var4);
|
||||
SoftConstraint* c = AddSoftConstraint(coeffs, vars, op, rightSide,
|
||||
BList* summands = new BList(2);
|
||||
summands->AddItem(new Summand(coeff1, var1));
|
||||
summands->AddItem(new Summand(coeff2, var2));
|
||||
summands->AddItem(new Summand(coeff3, var3));
|
||||
summands->AddItem(new Summand(coeff4, var4));
|
||||
Constraint* c = new Constraint(this, summands, op, rightSide,
|
||||
penaltyNeg, penaltyPos);
|
||||
RemovePresolved();
|
||||
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 "Variable.h"
|
||||
#include "LinearSpec.h"
|
||||
|
||||
|
||||
/**
|
||||
* Gets the summmand's coefficient.
|
||||
*
|
||||
* @return the summand's coefficient
|
||||
*/
|
||||
double
|
||||
ObjFunctionSummand::Coeff()
|
||||
{
|
||||
return fCoeff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the summmand's coefficient.
|
||||
*
|
||||
@ -23,23 +17,11 @@ ObjFunctionSummand::Coeff()
|
||||
void
|
||||
ObjFunctionSummand::SetCoeff(double coeff)
|
||||
{
|
||||
fCoeff = coeff;
|
||||
Summand::SetCoeff(coeff);
|
||||
fLS->UpdateObjFunction();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the summand's variable.
|
||||
*
|
||||
* @return the summand's variable
|
||||
*/
|
||||
Variable*
|
||||
ObjFunctionSummand::Var()
|
||||
{
|
||||
return fVar;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the summand's variable.
|
||||
*
|
||||
@ -48,7 +30,7 @@ ObjFunctionSummand::Var()
|
||||
void
|
||||
ObjFunctionSummand::SetVar(Variable* var)
|
||||
{
|
||||
fVar = var;
|
||||
Summand::SetVar(var);
|
||||
fLS->UpdateObjFunction();
|
||||
}
|
||||
|
||||
@ -68,9 +50,8 @@ ObjFunctionSummand::~ObjFunctionSummand()
|
||||
* Constructor.
|
||||
*/
|
||||
ObjFunctionSummand::ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var)
|
||||
: Summand(coeff, var)
|
||||
{
|
||||
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 "Constraint.h"
|
||||
#include "ObjFunctionSummand.h"
|
||||
@ -27,29 +33,15 @@ PenaltyFunction::PenaltyFunction(LinearSpec* ls, Variable* var, BList* xs, BList
|
||||
fGs = gs;
|
||||
fConstraints = new BList(1);
|
||||
fObjFunctionSummands = new BList(1);
|
||||
|
||||
BList* coeffs = new BList(1);
|
||||
coeffs->AddItem(new double(1.0));
|
||||
|
||||
BList* vars = new BList(1);
|
||||
vars->AddItem(var);
|
||||
|
||||
fConstraints->AddItem(ls->AddSoftConstraint(coeffs, vars, OperatorType(EQ),
|
||||
|
||||
fConstraints->AddItem(ls->AddConstraint(1.0, var, OperatorType(EQ),
|
||||
*(double*)(xs->ItemAt(0)), -*(double*)(gs->ItemAt(0)),
|
||||
*(double*)(gs->ItemAt(1))));
|
||||
|
||||
for (int32 i = 1; i < sizeGs; i++) {
|
||||
Variable* dPos = ls->AddVariable();
|
||||
|
||||
BList* coeffs = new BList(2);
|
||||
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),
|
||||
|
||||
fConstraints->AddItem(ls->AddConstraint(1.0, var, -1.0, dPos, OperatorType(LE),
|
||||
*(double*)(xs->ItemAt(i))));
|
||||
|
||||
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);
|
||||
}
|
||||
|
76
src/libs/linprog/Summand.cpp
Normal file
76
src/libs/linprog/Summand.cpp
Normal file
@ -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 "Constraint.h"
|
||||
#include "LinearSpec.h"
|
||||
@ -156,15 +162,7 @@ Variable::SetRange(double min, double max)
|
||||
Constraint*
|
||||
Variable::IsEqual(Variable* var)
|
||||
{
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
return fLS->AddConstraint(1.0, this, -1.0, var, OperatorType(EQ), 0.0);
|
||||
}
|
||||
|
||||
|
||||
@ -177,15 +175,7 @@ Variable::IsEqual(Variable* var)
|
||||
Constraint*
|
||||
Variable::IsSmallerOrEqual(Variable* var)
|
||||
{
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
return fLS->AddConstraint(1.0, this, -1.0, var, OperatorType(LE), 0.0);
|
||||
}
|
||||
|
||||
|
||||
@ -198,15 +188,7 @@ Variable::IsSmallerOrEqual(Variable* var)
|
||||
Constraint*
|
||||
Variable::IsGreaterorEqual(Variable* var)
|
||||
{
|
||||
BList* coeffs = new BList(2);
|
||||
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);
|
||||
return fLS->AddConstraint(-1.0, var, 1.0, this, OperatorType(GE), 0.0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,3 +22,9 @@ Application ALMTest2 :
|
||||
be liblpsolve55.so be liblinprog.so libalm.so
|
||||
;
|
||||
|
||||
Application ALMSimpleTest :
|
||||
SimpleTest.cpp
|
||||
:
|
||||
be liblpsolve55.so be liblinprog.so libalm.so
|
||||
;
|
||||
|
||||
|
74
src/tests/libs/alm/SimpleTest.cpp
Normal file
74
src/tests/libs/alm/SimpleTest.cpp
Normal file
@ -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 <File.h>
|
||||
@ -14,9 +19,9 @@ using namespace BALM;
|
||||
|
||||
class TableTestWindow : public BWindow {
|
||||
public:
|
||||
TableTestWindow(BRect frame) : BWindow(frame, "TableTest", B_TITLED_WINDOW,
|
||||
B_QUIT_ON_WINDOW_CLOSE) {
|
||||
|
||||
TableTestWindow(BRect frame)
|
||||
: BWindow(frame, "TableTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
BALMLayout* fLS = new BALMLayout();
|
||||
|
||||
SetLayout(fLS);
|
||||
@ -55,7 +60,9 @@ public:
|
||||
|
||||
class TableTest : public BApplication {
|
||||
public:
|
||||
TableTest() : BApplication("application/x-vnd.haiku.table-test") {
|
||||
TableTest()
|
||||
: BApplication("application/x-vnd.haiku.table-test")
|
||||
{
|
||||
BRect frameRect;
|
||||
frameRect.Set(100, 100, 400, 400);
|
||||
TableTestWindow* theWindow = new TableTestWindow(frameRect);
|
||||
@ -63,8 +70,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
int
|
||||
main()
|
||||
{
|
||||
TableTest test;
|
||||
test.Run();
|
||||
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 <Button.h>
|
||||
#include <List.h>
|
||||
@ -14,9 +20,9 @@ using namespace BALM;
|
||||
|
||||
class Test1Window : public BWindow {
|
||||
public:
|
||||
Test1Window(BRect frame) : BWindow(frame, "Test1", B_TITLED_WINDOW,
|
||||
B_QUIT_ON_WINDOW_CLOSE) {
|
||||
|
||||
Test1Window(BRect frame)
|
||||
: BWindow(frame, "Test1", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
fLS = new BALMLayout();
|
||||
|
||||
SetLayout(fLS);
|
||||
@ -32,7 +38,9 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void SetBALMLayout() {
|
||||
void
|
||||
SetBALMLayout()
|
||||
{
|
||||
XTab* x1 = fLS->AddXTab();
|
||||
YTab* y1 = fLS->AddYTab();
|
||||
|
||||
@ -40,20 +48,8 @@ public:
|
||||
fLS->AddArea(x1, fLS->Top(), fLS->Right(), y1, button2);
|
||||
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);
|
||||
//~ 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, x1, -1.0, fLS->Right(), 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 {
|
||||
public:
|
||||
Test1() : BApplication("application/x-vnd.haiku.test1") {
|
||||
Test1()
|
||||
: BApplication("application/x-vnd.haiku.test1")
|
||||
{
|
||||
BRect frameRect;
|
||||
frameRect.Set(100, 100, 392, 366);
|
||||
Test1Window* theWindow = new Test1Window(frameRect);
|
||||
@ -76,8 +74,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
int
|
||||
main()
|
||||
{
|
||||
Test1 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 <Button.h>
|
||||
@ -18,9 +23,9 @@ using namespace BALM;
|
||||
|
||||
class Test2Window : public BWindow {
|
||||
public:
|
||||
Test2Window(BRect frame) : BWindow(frame, "Test2", B_TITLED_WINDOW,
|
||||
B_QUIT_ON_WINDOW_CLOSE) {
|
||||
|
||||
Test2Window(BRect frame)
|
||||
: BWindow(frame, "Test2", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
fLS = new BALMLayout();
|
||||
|
||||
SetLayout(fLS);
|
||||
@ -50,7 +55,9 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void SetBALMLayout() {
|
||||
void
|
||||
SetBALMLayout()
|
||||
{
|
||||
XTab* x1 = fLS->AddXTab();
|
||||
XTab* x2 = fLS->AddXTab();
|
||||
XTab* x3 = fLS->AddXTab();
|
||||
@ -67,32 +74,8 @@ public:
|
||||
fLS->AddArea(fLS->Left(), y2, x1, y3, button5);
|
||||
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);
|
||||
|
||||
//~ 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);
|
||||
|
||||
//~ 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->AddArea(fLS->Left(), y3, x2, y4, checkedListBox1);
|
||||
@ -147,7 +130,9 @@ private:
|
||||
|
||||
class Test2 : public BApplication {
|
||||
public:
|
||||
Test2() : BApplication("application/x-vnd.haiku.test2") {
|
||||
Test2()
|
||||
: BApplication("application/x-vnd.haiku.test2")
|
||||
{
|
||||
BRect frameRect;
|
||||
frameRect.Set(100, 100, 610, 456);
|
||||
Test2Window* theWindow = new Test2Window(frameRect);
|
||||
@ -155,8 +140,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
int
|
||||
main()
|
||||
{
|
||||
Test2 test;
|
||||
test.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
UseLibraryHeaders lp_solve linprog ;
|
||||
|
||||
SimpleTest linprog :
|
||||
SimpleTest linprog_test :
|
||||
Program.cpp
|
||||
:
|
||||
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 <SupportDefs.h>
|
||||
@ -10,7 +15,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void PrintVars(LinearSpec* ls) {
|
||||
void
|
||||
PrintVars(LinearSpec* ls)
|
||||
{
|
||||
int32 size = ls->Variables()->CountItems();
|
||||
Variable* variable;
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -21,7 +28,9 @@ void PrintVars(LinearSpec* ls) {
|
||||
}
|
||||
|
||||
|
||||
void Test1() {
|
||||
void
|
||||
Test1()
|
||||
{
|
||||
LinearSpec* ls = new LinearSpec();
|
||||
Variable* x1 = ls->AddVariable();
|
||||
Variable* x2 = ls->AddVariable();
|
||||
@ -62,6 +71,9 @@ void Test1() {
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
int
|
||||
main()
|
||||
{
|
||||
Test1();
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
UseLibraryHeaders lp_solve ;
|
||||
|
||||
SimpleTest lp_solve :
|
||||
SimpleTest lp_solve_test :
|
||||
demo.c
|
||||
:
|
||||
liblpsolve55.so
|
||||
|
Loading…
Reference in New Issue
Block a user