- Hide constraint header in Area file.

- Start to replace BList with BObjectList.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38741 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-09-20 06:09:19 +00:00
parent 0401a9c712
commit 601eded950
9 changed files with 71 additions and 54 deletions
+4 -1
View File
@@ -18,11 +18,14 @@
#include "Area.h" #include "Area.h"
#include "Row.h" #include "Row.h"
#include "Column.h" #include "Column.h"
#include "Constraint.h"
class Constraint;
namespace BALM { namespace BALM {
class BALMLayout; class BALMLayout;
/** /**
+12 -7
View File
@@ -9,7 +9,7 @@
#include <math.h> #include <math.h>
#include <File.h> #include <File.h>
#include <List.h> #include <ObjectList.h>
#include <String.h> #include <String.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -31,8 +31,8 @@ class Constraint {
public: public:
int32 Index() const; int32 Index() const;
BList* LeftSide(); SummandList* LeftSide();
void SetLeftSide(BList* summands); void SetLeftSide(SummandList* summands);
void UpdateLeftSide(); void UpdateLeftSide();
void SetLeftSide(double coeff1, Variable* var1); void SetLeftSide(double coeff1, Variable* var1);
void SetLeftSide(double coeff1, Variable* var1, void SetLeftSide(double coeff1, Variable* var1,
@@ -71,13 +71,14 @@ public:
~Constraint(); ~Constraint();
protected: protected:
Constraint(LinearSpec* ls, BList* summands, Constraint(LinearSpec* ls,
OperatorType op, double rightSide, SummandList* summands, OperatorType op,
double penaltyNeg, double penaltyPos); double rightSide, double penaltyNeg,
double penaltyPos);
private: private:
LinearSpec* fLS; LinearSpec* fLS;
BList* fLeftSide; SummandList* fLeftSide;
OperatorType fOp; OperatorType fOp;
double fRightSide; double fRightSide;
Summand* fDNegObjSummand; Summand* fDNegObjSummand;
@@ -91,6 +92,10 @@ public:
}; };
typedef BObjectList<Constraint> ConstraintList;
} // namespace LinearProgramming } // namespace LinearProgramming
using LinearProgramming::Constraint; using LinearProgramming::Constraint;
+5 -5
View File
@@ -43,7 +43,7 @@ public:
Variable* AddVariable(); Variable* AddVariable();
Constraint* AddConstraint(BList* summands, Constraint* AddConstraint(SummandList* summands,
OperatorType op, double rightSide); OperatorType op, double rightSide);
Constraint* AddConstraint(double coeff1, Variable* var1, Constraint* AddConstraint(double coeff1, Variable* var1,
OperatorType op, double rightSide); OperatorType op, double rightSide);
@@ -60,7 +60,7 @@ public:
double coeff4, Variable* var4, double coeff4, Variable* var4,
OperatorType op, double rightSide); OperatorType op, double rightSide);
Constraint* AddConstraint(BList* summands, Constraint* AddConstraint(SummandList* summands,
OperatorType op, double rightSide, OperatorType op, double rightSide,
double penaltyNeg, double penaltyPos); double penaltyNeg, double penaltyPos);
Constraint* AddConstraint(double coeff1, Variable* var1, Constraint* AddConstraint(double coeff1, Variable* var1,
@@ -85,8 +85,8 @@ public:
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs,
BList* gs); BList* gs);
BList* ObjFunction(); SummandList* ObjFunction();
void SetObjFunction(BList* summands); void SetObjFunction(SummandList* summands);
void UpdateObjFunction(); void UpdateObjFunction();
ResultType Presolve(); ResultType Presolve();
@@ -115,7 +115,7 @@ private:
lprec* fLpPresolved; lprec* fLpPresolved;
OptimizationType fOptimization; OptimizationType fOptimization;
lprec* fLP; lprec* fLP;
BList* fObjFunction; SummandList* fObjFunction;
BList fVariables; BList fVariables;
BList fConstraints; BList fConstraints;
ResultType fResult; ResultType fResult;
+6
View File
@@ -6,6 +6,8 @@
#ifndef SUMMAND_H #ifndef SUMMAND_H
#define SUMMAND_H #define SUMMAND_H
#include <ObjectList.h>
namespace LinearProgramming { namespace LinearProgramming {
@@ -31,9 +33,13 @@ private:
bool fUsedInPenaltyFunction; //not set yet bool fUsedInPenaltyFunction; //not set yet
}; };
typedef BObjectList<Summand> SummandList;
} // namespace LinearProgramming } // namespace LinearProgramming
using LinearProgramming::Summand; using LinearProgramming::Summand;
using LinearProgramming::SummandList;
#endif // OBJ_FUNCTION_SUMMAND_H #endif // OBJ_FUNCTION_SUMMAND_H
+11 -9
View File
@@ -4,22 +4,24 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <algorithm> // for max
#include <Button.h>
#include <CheckBox.h>
#include <PictureButton.h>
#include <RadioButton.h>
#include <StatusBar.h>
#include <StringView.h>
#include "Area.h" #include "Area.h"
#include "Column.h"
#include "BALMLayout.h" #include "BALMLayout.h"
#include "Column.h"
#include "Constraint.h"
#include "OperatorType.h" #include "OperatorType.h"
#include "Row.h" #include "Row.h"
#include "XTab.h" #include "XTab.h"
#include "YTab.h" #include "YTab.h"
#include <Button.h>
#include <RadioButton.h>
#include <CheckBox.h>
#include <StringView.h>
#include <PictureButton.h>
#include <StatusBar.h>
#include <algorithm> // for max
using namespace std; using namespace std;
+8 -8
View File
@@ -602,16 +602,16 @@ BALMLayout::SetPerformancePath(char* path)
BSize BSize
BALMLayout::CalculateMinSize() BALMLayout::CalculateMinSize()
{ {
BList* oldObjFunction = ObjFunction(); SummandList* oldObjFunction = ObjFunction();
BList* newObjFunction = new BList(2); SummandList* newObjFunction = new SummandList(2);
newObjFunction->AddItem(new Summand(1.0, fRight)); newObjFunction->AddItem(new Summand(1.0, fRight));
newObjFunction->AddItem(new Summand(1.0, fBottom)); newObjFunction->AddItem(new Summand(1.0, fBottom));
SetObjFunction(newObjFunction); SetObjFunction(newObjFunction);
SolveLayout(); SolveLayout();
SetObjFunction(oldObjFunction); SetObjFunction(oldObjFunction);
UpdateObjFunction(); UpdateObjFunction();
delete (Summand*)newObjFunction->ItemAt(0); delete newObjFunction->ItemAt(0);
delete (Summand*)newObjFunction->ItemAt(1); delete newObjFunction->ItemAt(1);
delete newObjFunction; delete newObjFunction;
if (Result() == UNBOUNDED) if (Result() == UNBOUNDED)
@@ -631,16 +631,16 @@ BALMLayout::CalculateMinSize()
BSize BSize
BALMLayout::CalculateMaxSize() BALMLayout::CalculateMaxSize()
{ {
BList* oldObjFunction = ObjFunction(); SummandList* oldObjFunction = ObjFunction();
BList* newObjFunction = new BList(2); SummandList* newObjFunction = new SummandList(2);
newObjFunction->AddItem(new Summand(-1.0, fRight)); newObjFunction->AddItem(new Summand(-1.0, fRight));
newObjFunction->AddItem(new Summand(-1.0, fBottom)); newObjFunction->AddItem(new Summand(-1.0, fBottom));
SetObjFunction(newObjFunction); SetObjFunction(newObjFunction);
SolveLayout(); SolveLayout();
SetObjFunction(oldObjFunction); SetObjFunction(oldObjFunction);
UpdateObjFunction(); UpdateObjFunction();
delete (Summand*)newObjFunction->ItemAt(0); delete newObjFunction->ItemAt(0);
delete (Summand*)newObjFunction->ItemAt(1); delete newObjFunction->ItemAt(1);
delete newObjFunction; delete newObjFunction;
if (Result() == UNBOUNDED) if (Result() == UNBOUNDED)
+9 -9
View File
@@ -43,7 +43,7 @@ Constraint::Index() const
* *
* @return pointer to a BList containing the summands on the left side of the constraint * @return pointer to a BList containing the summands on the left side of the constraint
*/ */
BList* SummandList*
Constraint::LeftSide() Constraint::LeftSide()
{ {
return fLeftSide; return fLeftSide;
@@ -57,7 +57,7 @@ Constraint::LeftSide()
* @param summands a BList containing the Summand objects that make up the new left side * @param summands a BList containing the Summand objects that make up the new left side
*/ */
void void
Constraint::SetLeftSide(BList* summands) Constraint::SetLeftSide(SummandList* summands)
{ {
if (!fIsValid) if (!fIsValid)
return; return;
@@ -77,7 +77,7 @@ Constraint::UpdateLeftSide()
int varIndexes[fLeftSide->CountItems() + 2]; int varIndexes[fLeftSide->CountItems() + 2];
int32 i; int32 i;
for (i = 0; i < fLeftSide->CountItems(); i++) { for (i = 0; i < fLeftSide->CountItems(); i++) {
Summand* s = (Summand*)fLeftSide->ItemAt(i); Summand* s = fLeftSide->ItemAt(i);
coeffs[i] = s->Coeff(); coeffs[i] = s->Coeff();
varIndexes[i] = s->Var()->Index(); varIndexes[i] = s->Var()->Index();
} }
@@ -109,7 +109,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1)
return; return;
for (int i=0; i<fLeftSide->CountItems(); i++) for (int i=0; i<fLeftSide->CountItems(); i++)
delete (Summand*)fLeftSide->ItemAt(i); delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty(); fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff1, var1));
UpdateLeftSide(); UpdateLeftSide();
@@ -124,7 +124,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1,
return; return;
for (int i=0; i<fLeftSide->CountItems(); i++) for (int i=0; i<fLeftSide->CountItems(); i++)
delete (Summand*)fLeftSide->ItemAt(i); delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty(); fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new Summand(coeff2, var2)); fLeftSide->AddItem(new Summand(coeff2, var2));
@@ -141,7 +141,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1,
return; return;
for (int i=0; i<fLeftSide->CountItems(); i++) for (int i=0; i<fLeftSide->CountItems(); i++)
delete (Summand*)fLeftSide->ItemAt(i); delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty(); fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new Summand(coeff2, var2)); fLeftSide->AddItem(new Summand(coeff2, var2));
@@ -160,7 +160,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1,
return; return;
for (int i=0; i<fLeftSide->CountItems(); i++) for (int i=0; i<fLeftSide->CountItems(); i++)
delete (Summand*)fLeftSide->ItemAt(i); delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty(); fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new Summand(coeff2, var2)); fLeftSide->AddItem(new Summand(coeff2, var2));
@@ -482,7 +482,7 @@ Constraint::GetString(BString& string) const
/** /**
* Constructor. * Constructor.
*/ */
Constraint::Constraint(LinearSpec* ls, BList* summands, OperatorType op, Constraint::Constraint(LinearSpec* ls, SummandList* summands, OperatorType op,
double rightSide, double penaltyNeg, double penaltyPos) double rightSide, double penaltyNeg, double penaltyPos)
: :
fLS(ls), fLS(ls),
@@ -495,7 +495,7 @@ Constraint::Constraint(LinearSpec* ls, BList* summands, OperatorType op,
int varIndexes[summands->CountItems() + 2]; int varIndexes[summands->CountItems() + 2];
int32 i; int32 i;
for (i = 0; i < summands->CountItems(); i++) { for (i = 0; i < summands->CountItems(); i++) {
Summand* s = (Summand*)summands->ItemAt(i); Summand* s = summands->ItemAt(i);
coeffs[i] = s->Coeff(); coeffs[i] = s->Coeff();
varIndexes[i] = s->Var()->Index(); varIndexes[i] = s->Var()->Index();
} }
+14 -13
View File
@@ -16,7 +16,7 @@ LinearSpec::LinearSpec()
fCountColumns(0), fCountColumns(0),
fLpPresolved(NULL), fLpPresolved(NULL),
fOptimization(MINIMIZE), fOptimization(MINIMIZE),
fObjFunction(new BList()), fObjFunction(new SummandList()),
fResult(ERROR), fResult(ERROR),
fObjectiveValue(NAN), fObjectiveValue(NAN),
fSolvingTime(NAN) fSolvingTime(NAN)
@@ -70,7 +70,8 @@ LinearSpec::AddVariable()
* @return the new constraint * @return the new constraint
*/ */
Constraint* Constraint*
LinearSpec::AddConstraint(BList* summands, OperatorType op, double rightSide) LinearSpec::AddConstraint(SummandList* summands, OperatorType op,
double rightSide)
{ {
Constraint* c = new Constraint(this, summands, op, rightSide, Constraint* c = new Constraint(this, summands, op, rightSide,
INFINITY, INFINITY); INFINITY, INFINITY);
@@ -92,7 +93,7 @@ Constraint*
LinearSpec::AddConstraint(double coeff1, Variable* var1, LinearSpec::AddConstraint(double coeff1, Variable* var1,
OperatorType op, double rightSide) OperatorType op, double rightSide)
{ {
BList* summands = new BList(1); SummandList* summands = new SummandList(1);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
Constraint* c = new Constraint(this, summands, op, rightSide, Constraint* c = new Constraint(this, summands, op, rightSide,
INFINITY, INFINITY); INFINITY, INFINITY);
@@ -116,7 +117,7 @@ Constraint*
LinearSpec::AddConstraint(double coeff1, Variable* var1, LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, OperatorType op, double rightSide) double coeff2, Variable* var2, OperatorType op, double rightSide)
{ {
BList* summands = new BList(2); SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2)); summands->AddItem(new Summand(coeff2, var2));
Constraint* c = new Constraint(this, summands, op, rightSide, Constraint* c = new Constraint(this, summands, op, rightSide,
@@ -144,7 +145,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, double coeff3, Variable* var3, double coeff2, Variable* var2, double coeff3, Variable* var3,
OperatorType op, double rightSide) OperatorType op, double rightSide)
{ {
BList* summands = new BList(3); SummandList* summands = new SummandList(3);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2)); summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3)); summands->AddItem(new Summand(coeff3, var3));
@@ -175,7 +176,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, double coeff3, Variable* var3, double coeff2, Variable* var2, double coeff3, Variable* var3,
double coeff4, Variable* var4, OperatorType op, double rightSide) double coeff4, Variable* var4, OperatorType op, double rightSide)
{ {
BList* summands = new BList(3); SummandList* summands = new SummandList(3);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2)); summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3)); summands->AddItem(new Summand(coeff3, var3));
@@ -199,7 +200,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
* @param penaltyPos the coefficient penalizing positive deviations from the exact solution * @param penaltyPos the coefficient penalizing positive deviations from the exact solution
*/ */
Constraint* Constraint*
LinearSpec::AddConstraint(BList* summands, OperatorType op, LinearSpec::AddConstraint(SummandList* summands, OperatorType op,
double rightSide, double penaltyNeg, double penaltyPos) double rightSide, double penaltyNeg, double penaltyPos)
{ {
Constraint* c = new Constraint(this, summands, op, rightSide, Constraint* c = new Constraint(this, summands, op, rightSide,
@@ -223,7 +224,7 @@ Constraint*
LinearSpec::AddConstraint(double coeff1, Variable* var1, LinearSpec::AddConstraint(double coeff1, Variable* var1,
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos) OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
{ {
BList* summands = new BList(1); SummandList* summands = new SummandList(1);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
Constraint* c = new Constraint(this, summands, op, rightSide, Constraint* c = new Constraint(this, summands, op, rightSide,
penaltyNeg, penaltyPos); penaltyNeg, penaltyPos);
@@ -249,7 +250,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, OperatorType op, double rightSide, double coeff2, Variable* var2, OperatorType op, double rightSide,
double penaltyNeg, double penaltyPos) double penaltyNeg, double penaltyPos)
{ {
BList* summands = new BList(2); SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2)); summands->AddItem(new Summand(coeff2, var2));
Constraint* c = new Constraint(this, summands, op, rightSide, Constraint* c = new Constraint(this, summands, op, rightSide,
@@ -278,7 +279,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, double coeff3, Variable* var3, double coeff2, Variable* var2, double coeff3, Variable* var3,
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos) OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
{ {
BList* summands = new BList(2); SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2)); summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3)); summands->AddItem(new Summand(coeff3, var3));
@@ -311,7 +312,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff4, Variable* var4, OperatorType op, double rightSide, double coeff4, Variable* var4, OperatorType op, double rightSide,
double penaltyNeg, double penaltyPos) double penaltyNeg, double penaltyPos)
{ {
BList* summands = new BList(2); SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2)); summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3)); summands->AddItem(new Summand(coeff3, var3));
@@ -343,7 +344,7 @@ LinearSpec::AddPenaltyFunction(Variable* var, BList* xs, BList* gs)
* *
* @return BList containing the objective function's summands * @return BList containing the objective function's summands
*/ */
BList* SummandList*
LinearSpec::ObjFunction() LinearSpec::ObjFunction()
{ {
return fObjFunction; return fObjFunction;
@@ -357,7 +358,7 @@ LinearSpec::ObjFunction()
* @param summands BList containing the objective function's summands * @param summands BList containing the objective function's summands
*/ */
void void
LinearSpec::SetObjFunction(BList* summands) LinearSpec::SetObjFunction(SummandList* summands)
{ {
fObjFunction = summands; fObjFunction = summands;
UpdateObjFunction(); UpdateObjFunction();
+2 -2
View File
@@ -298,9 +298,9 @@ Variable::Invalidate()
if (!constraint->IsValid()) if (!constraint->IsValid())
continue; continue;
BList* summands = constraint->LeftSide(); SummandList* summands = constraint->LeftSide();
for (int j = 0; j < summands->CountItems(); j++) { for (int j = 0; j < summands->CountItems(); j++) {
Summand* summand = static_cast<Summand*>(summands->ItemAt(j)); Summand* summand = summands->ItemAt(j);
if (summand->Var() == this) { if (summand->Var() == this) {
markedForInvalidation.AddItem(constraint); markedForInvalidation.AddItem(constraint);
break; break;