diff --git a/headers/libs/alm/Area.h b/headers/libs/alm/Area.h index d1165dc16f..d029ac9edc 100644 --- a/headers/libs/alm/Area.h +++ b/headers/libs/alm/Area.h @@ -18,11 +18,14 @@ #include "Area.h" #include "Row.h" #include "Column.h" -#include "Constraint.h" + + +class Constraint; namespace BALM { + class BALMLayout; /** diff --git a/headers/libs/linprog/Constraint.h b/headers/libs/linprog/Constraint.h index 69217cc4e1..789355a8aa 100644 --- a/headers/libs/linprog/Constraint.h +++ b/headers/libs/linprog/Constraint.h @@ -9,7 +9,7 @@ #include <math.h> #include <File.h> -#include <List.h> +#include <ObjectList.h> #include <String.h> #include <SupportDefs.h> @@ -31,8 +31,8 @@ class Constraint { public: int32 Index() const; - BList* LeftSide(); - void SetLeftSide(BList* summands); + SummandList* LeftSide(); + void SetLeftSide(SummandList* summands); void UpdateLeftSide(); void SetLeftSide(double coeff1, Variable* var1); void SetLeftSide(double coeff1, Variable* var1, @@ -71,13 +71,14 @@ public: ~Constraint(); protected: - Constraint(LinearSpec* ls, BList* summands, - OperatorType op, double rightSide, - double penaltyNeg, double penaltyPos); + Constraint(LinearSpec* ls, + SummandList* summands, OperatorType op, + double rightSide, double penaltyNeg, + double penaltyPos); private: LinearSpec* fLS; - BList* fLeftSide; + SummandList* fLeftSide; OperatorType fOp; double fRightSide; Summand* fDNegObjSummand; @@ -91,6 +92,10 @@ public: }; + +typedef BObjectList<Constraint> ConstraintList; + + } // namespace LinearProgramming using LinearProgramming::Constraint; diff --git a/headers/libs/linprog/LinearSpec.h b/headers/libs/linprog/LinearSpec.h index 1151d90444..1ad0d7532e 100644 --- a/headers/libs/linprog/LinearSpec.h +++ b/headers/libs/linprog/LinearSpec.h @@ -43,7 +43,7 @@ public: Variable* AddVariable(); - Constraint* AddConstraint(BList* summands, + Constraint* AddConstraint(SummandList* summands, OperatorType op, double rightSide); Constraint* AddConstraint(double coeff1, Variable* var1, OperatorType op, double rightSide); @@ -60,7 +60,7 @@ public: double coeff4, Variable* var4, OperatorType op, double rightSide); - Constraint* AddConstraint(BList* summands, + Constraint* AddConstraint(SummandList* summands, OperatorType op, double rightSide, double penaltyNeg, double penaltyPos); Constraint* AddConstraint(double coeff1, Variable* var1, @@ -85,8 +85,8 @@ public: PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs); - BList* ObjFunction(); - void SetObjFunction(BList* summands); + SummandList* ObjFunction(); + void SetObjFunction(SummandList* summands); void UpdateObjFunction(); ResultType Presolve(); @@ -115,7 +115,7 @@ private: lprec* fLpPresolved; OptimizationType fOptimization; lprec* fLP; - BList* fObjFunction; + SummandList* fObjFunction; BList fVariables; BList fConstraints; ResultType fResult; diff --git a/headers/libs/linprog/Summand.h b/headers/libs/linprog/Summand.h index 1978738b19..6370455bf0 100644 --- a/headers/libs/linprog/Summand.h +++ b/headers/libs/linprog/Summand.h @@ -6,6 +6,8 @@ #ifndef SUMMAND_H #define SUMMAND_H +#include <ObjectList.h> + namespace LinearProgramming { @@ -31,9 +33,13 @@ private: bool fUsedInPenaltyFunction; //not set yet }; +typedef BObjectList<Summand> SummandList; + } // namespace LinearProgramming using LinearProgramming::Summand; +using LinearProgramming::SummandList; + #endif // OBJ_FUNCTION_SUMMAND_H diff --git a/src/libs/alm/Area.cpp b/src/libs/alm/Area.cpp index 740d4275b0..0b852e3501 100644 --- a/src/libs/alm/Area.cpp +++ b/src/libs/alm/Area.cpp @@ -4,22 +4,24 @@ * 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 "Column.h" #include "BALMLayout.h" +#include "Column.h" +#include "Constraint.h" #include "OperatorType.h" #include "Row.h" #include "XTab.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; diff --git a/src/libs/alm/BALMLayout.cpp b/src/libs/alm/BALMLayout.cpp index 594b687879..b54dbb8346 100644 --- a/src/libs/alm/BALMLayout.cpp +++ b/src/libs/alm/BALMLayout.cpp @@ -602,16 +602,16 @@ BALMLayout::SetPerformancePath(char* path) BSize BALMLayout::CalculateMinSize() { - BList* oldObjFunction = ObjFunction(); - BList* newObjFunction = new BList(2); + SummandList* oldObjFunction = ObjFunction(); + SummandList* newObjFunction = new SummandList(2); newObjFunction->AddItem(new Summand(1.0, fRight)); newObjFunction->AddItem(new Summand(1.0, fBottom)); SetObjFunction(newObjFunction); SolveLayout(); SetObjFunction(oldObjFunction); UpdateObjFunction(); - delete (Summand*)newObjFunction->ItemAt(0); - delete (Summand*)newObjFunction->ItemAt(1); + delete newObjFunction->ItemAt(0); + delete newObjFunction->ItemAt(1); delete newObjFunction; if (Result() == UNBOUNDED) @@ -631,16 +631,16 @@ BALMLayout::CalculateMinSize() BSize BALMLayout::CalculateMaxSize() { - BList* oldObjFunction = ObjFunction(); - BList* newObjFunction = new BList(2); + SummandList* oldObjFunction = ObjFunction(); + SummandList* newObjFunction = new SummandList(2); newObjFunction->AddItem(new Summand(-1.0, fRight)); newObjFunction->AddItem(new Summand(-1.0, fBottom)); SetObjFunction(newObjFunction); SolveLayout(); SetObjFunction(oldObjFunction); UpdateObjFunction(); - delete (Summand*)newObjFunction->ItemAt(0); - delete (Summand*)newObjFunction->ItemAt(1); + delete newObjFunction->ItemAt(0); + delete newObjFunction->ItemAt(1); delete newObjFunction; if (Result() == UNBOUNDED) diff --git a/src/libs/linprog/Constraint.cpp b/src/libs/linprog/Constraint.cpp index 931003b6b5..d4c714149c 100644 --- a/src/libs/linprog/Constraint.cpp +++ b/src/libs/linprog/Constraint.cpp @@ -43,7 +43,7 @@ Constraint::Index() const * * @return pointer to a BList containing the summands on the left side of the constraint */ -BList* +SummandList* Constraint::LeftSide() { return fLeftSide; @@ -57,7 +57,7 @@ Constraint::LeftSide() * @param summands a BList containing the Summand objects that make up the new left side */ void -Constraint::SetLeftSide(BList* summands) +Constraint::SetLeftSide(SummandList* summands) { if (!fIsValid) return; @@ -77,7 +77,7 @@ Constraint::UpdateLeftSide() int varIndexes[fLeftSide->CountItems() + 2]; int32 i; for (i = 0; i < fLeftSide->CountItems(); i++) { - Summand* s = (Summand*)fLeftSide->ItemAt(i); + Summand* s = fLeftSide->ItemAt(i); coeffs[i] = s->Coeff(); varIndexes[i] = s->Var()->Index(); } @@ -109,7 +109,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1) return; for (int i=0; i<fLeftSide->CountItems(); i++) - delete (Summand*)fLeftSide->ItemAt(i); + delete fLeftSide->ItemAt(i); fLeftSide->MakeEmpty(); fLeftSide->AddItem(new Summand(coeff1, var1)); UpdateLeftSide(); @@ -124,7 +124,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1, return; for (int i=0; i<fLeftSide->CountItems(); i++) - delete (Summand*)fLeftSide->ItemAt(i); + delete fLeftSide->ItemAt(i); fLeftSide->MakeEmpty(); fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff2, var2)); @@ -141,7 +141,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1, return; for (int i=0; i<fLeftSide->CountItems(); i++) - delete (Summand*)fLeftSide->ItemAt(i); + delete fLeftSide->ItemAt(i); fLeftSide->MakeEmpty(); fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff2, var2)); @@ -160,7 +160,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1, return; for (int i=0; i<fLeftSide->CountItems(); i++) - delete (Summand*)fLeftSide->ItemAt(i); + delete fLeftSide->ItemAt(i); fLeftSide->MakeEmpty(); fLeftSide->AddItem(new Summand(coeff1, var1)); fLeftSide->AddItem(new Summand(coeff2, var2)); @@ -482,7 +482,7 @@ Constraint::GetString(BString& string) const /** * Constructor. */ -Constraint::Constraint(LinearSpec* ls, BList* summands, OperatorType op, +Constraint::Constraint(LinearSpec* ls, SummandList* summands, OperatorType op, double rightSide, double penaltyNeg, double penaltyPos) : fLS(ls), @@ -495,7 +495,7 @@ Constraint::Constraint(LinearSpec* ls, BList* summands, OperatorType op, int varIndexes[summands->CountItems() + 2]; int32 i; for (i = 0; i < summands->CountItems(); i++) { - Summand* s = (Summand*)summands->ItemAt(i); + Summand* s = summands->ItemAt(i); coeffs[i] = s->Coeff(); varIndexes[i] = s->Var()->Index(); } diff --git a/src/libs/linprog/LinearSpec.cpp b/src/libs/linprog/LinearSpec.cpp index 570b5f6bbb..046a9e3967 100644 --- a/src/libs/linprog/LinearSpec.cpp +++ b/src/libs/linprog/LinearSpec.cpp @@ -16,7 +16,7 @@ LinearSpec::LinearSpec() fCountColumns(0), fLpPresolved(NULL), fOptimization(MINIMIZE), - fObjFunction(new BList()), + fObjFunction(new SummandList()), fResult(ERROR), fObjectiveValue(NAN), fSolvingTime(NAN) @@ -70,7 +70,8 @@ LinearSpec::AddVariable() * @return the new 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, INFINITY, INFINITY); @@ -92,7 +93,7 @@ Constraint* LinearSpec::AddConstraint(double coeff1, Variable* var1, OperatorType op, double rightSide) { - BList* summands = new BList(1); + SummandList* summands = new SummandList(1); summands->AddItem(new Summand(coeff1, var1)); Constraint* c = new Constraint(this, summands, op, rightSide, INFINITY, INFINITY); @@ -116,7 +117,7 @@ Constraint* LinearSpec::AddConstraint(double coeff1, Variable* var1, 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(coeff2, var2)); 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, OperatorType op, double rightSide) { - BList* summands = new BList(3); + SummandList* summands = new SummandList(3); summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff2, var2)); 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 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(coeff2, var2)); 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 */ Constraint* -LinearSpec::AddConstraint(BList* summands, OperatorType op, +LinearSpec::AddConstraint(SummandList* summands, OperatorType op, double rightSide, double penaltyNeg, double penaltyPos) { Constraint* c = new Constraint(this, summands, op, rightSide, @@ -223,7 +224,7 @@ Constraint* LinearSpec::AddConstraint(double coeff1, Variable* var1, OperatorType op, double rightSide, double penaltyNeg, double penaltyPos) { - BList* summands = new BList(1); + SummandList* summands = new SummandList(1); summands->AddItem(new Summand(coeff1, var1)); Constraint* c = new Constraint(this, summands, op, rightSide, penaltyNeg, penaltyPos); @@ -249,7 +250,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1, double coeff2, Variable* var2, 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(coeff2, var2)); 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, 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(coeff2, var2)); 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 penaltyNeg, double penaltyPos) { - BList* summands = new BList(2); + SummandList* summands = new SummandList(2); summands->AddItem(new Summand(coeff1, var1)); summands->AddItem(new Summand(coeff2, var2)); 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 */ -BList* +SummandList* LinearSpec::ObjFunction() { return fObjFunction; @@ -357,7 +358,7 @@ LinearSpec::ObjFunction() * @param summands BList containing the objective function's summands */ void -LinearSpec::SetObjFunction(BList* summands) +LinearSpec::SetObjFunction(SummandList* summands) { fObjFunction = summands; UpdateObjFunction(); diff --git a/src/libs/linprog/Variable.cpp b/src/libs/linprog/Variable.cpp index e37532ad23..2a32978824 100644 --- a/src/libs/linprog/Variable.cpp +++ b/src/libs/linprog/Variable.cpp @@ -298,9 +298,9 @@ Variable::Invalidate() if (!constraint->IsValid()) continue; - BList* summands = constraint->LeftSide(); + SummandList* summands = constraint->LeftSide(); 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) { markedForInvalidation.AddItem(constraint); break;