diff --git a/headers/libs/linprog/Constraint.h b/headers/libs/linprog/Constraint.h index 1a4a9171c8..d69c8a8bea 100644 --- a/headers/libs/linprog/Constraint.h +++ b/headers/libs/linprog/Constraint.h @@ -13,7 +13,7 @@ #include #include -#include "OperatorType.h" +#include "LinearProgrammingTypes.h" #include "Summand.h" #include "Variable.h" diff --git a/headers/libs/linprog/LinearProgrammingTypes.h b/headers/libs/linprog/LinearProgrammingTypes.h new file mode 100644 index 0000000000..8843e51ebc --- /dev/null +++ b/headers/libs/linprog/LinearProgrammingTypes.h @@ -0,0 +1,57 @@ +/* + * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz + * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz + * Copyright 2010, Clemens Zeidler + * Distributed under the terms of the MIT License. + */ + +#ifndef LINEAR_PROGRAMMING_TYPES_H +#define LINEAR_PROGRAMMING_TYPES_H + + +namespace LinearProgramming { + + +/** + * The possible results of a solving attempt. + */ +enum ResultType { + kNoMemory = -2, + kError = -1, + kOptimal = 0, + kSuboptimal = 1, + kInfeasible = 2, + kUnbounded = 3, + kDegenerate = 4, + kNumFailure = 5 +}; + + +/** + * Possible operators for linear constraints. + */ +enum OperatorType { + kEQ, + kLE, + kGE +}; + + + +/** + * The two possibilities for optimizing the objective function. + */ +enum OptimizationType { + kMinimize, + kMaximize +}; + +} // namespace LinearProgramming + + +using LinearProgramming::ResultType; +using LinearProgramming::OperatorType; +using LinearProgramming::OptimizationType; + + +#endif // LINEAR_PROGRAMMING_TYPES_H diff --git a/headers/libs/linprog/LinearSpec.h b/headers/libs/linprog/LinearSpec.h index d1af92b567..7970f6c543 100644 --- a/headers/libs/linprog/LinearSpec.h +++ b/headers/libs/linprog/LinearSpec.h @@ -15,10 +15,8 @@ #include #include "Constraint.h" -#include "OperatorType.h" -#include "OptimizationType.h" +#include "LinearProgrammingTypes.h" #include "PenaltyFunction.h" -#include "ResultType.h" #include "Summand.h" #include "Variable.h" diff --git a/headers/libs/linprog/OperatorType.h b/headers/libs/linprog/OperatorType.h deleted file mode 100644 index 48972b6154..0000000000 --- a/headers/libs/linprog/OperatorType.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 - - -namespace LinearProgramming { - -/** - * Possible operators for linear constraints. - */ -enum OperatorType { - kEQ, - kLE, - kGE -}; - -} // namespace LinearProgramming - -using LinearProgramming::OperatorType; - -#endif diff --git a/headers/libs/linprog/OptimizationType.h b/headers/libs/linprog/OptimizationType.h deleted file mode 100644 index 7ed46a7d34..0000000000 --- a/headers/libs/linprog/OptimizationType.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 - - -namespace LinearProgramming { - -/** - * The two possibilities for optimizing the objective function. - */ -enum OptimizationType { - MINIMIZE, MAXIMIZE -}; - -} // namespace LinearProgramming - -using LinearProgramming::OptimizationType; - -#endif diff --git a/headers/libs/linprog/ResultType.h b/headers/libs/linprog/ResultType.h deleted file mode 100644 index 53575c7c98..0000000000 --- a/headers/libs/linprog/ResultType.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 - - -namespace LinearProgramming { - -/** - * The possible results of a solving attempt. - */ -enum ResultType { - NOMEMORY = -2, - ERROR = -1, - OPTIMAL = 0, - SUBOPTIMAL = 1, - INFEASIBLE = 2, - UNBOUNDED = 3, - DEGENERATE = 4, - NUMFAILURE = 5, - USERABORT = 6, - TIMEOUT = 7, - PRESOLVED = 9, - PROCFAIL = 10, - PROCBREAK = 11, - FEASFOUND = 12, - NOFEASFOUND = 13 -}; - -} // namespace LinearProgramming - -using LinearProgramming::ResultType; - -#endif diff --git a/src/add-ons/decorators/SATDecorator/SATWindow.cpp b/src/add-ons/decorators/SATDecorator/SATWindow.cpp index a492d5fd73..d4c1f1a0bc 100644 --- a/src/add-ons/decorators/SATDecorator/SATWindow.cpp +++ b/src/add-ons/decorators/SATDecorator/SATWindow.cpp @@ -88,11 +88,11 @@ GroupCookie::DoGroupLayout(SATWindow* triggerWindow) ResultType result; for (int32 tries = 0; tries < 15; tries++) { result = fSATGroup->GetLinearSpec()->Solve(); - if (result == INFEASIBLE) { + if (result == kInfeasible) { debug_printf("can't solve constraints!\n"); break; } - if (result == OPTIMAL) { + if (result == kOptimal) { fSATGroup->AdjustWindows(triggerWindow); _UpdateWindowSize(frame); break; diff --git a/src/libs/alm/ALMLayout.cpp b/src/libs/alm/ALMLayout.cpp index c07f57b050..97e4711400 100644 --- a/src/libs/alm/ALMLayout.cpp +++ b/src/libs/alm/ALMLayout.cpp @@ -14,8 +14,6 @@ #include "ViewLayoutItem.h" -#include "ResultType.h" - using namespace LinearProgramming; @@ -706,10 +704,10 @@ BALMLayout::DerivedLayoutItems() _SolveLayout(); // if new layout is infeasible, use previous layout - if (fSolver->Result() == INFEASIBLE) + if (fSolver->Result() == kInfeasible) return; - if (fSolver->Result() != OPTIMAL) { + if (fSolver->Result() != kOptimal) { fSolver->Save("failed-layout.txt"); printf("Could not solve the layout specification (%d). ", fSolver->Result()); @@ -791,7 +789,7 @@ BALMLayout::_CreateLayoutItem(BView* view) void BALMLayout::_SolveLayout() { - // Try to solve the layout until the result is OPTIMAL or INFEASIBLE, + // Try to solve the layout until the result is kOptimal or kInfeasible, // maximally 15 tries sometimes the solving algorithm encounters numerical // problems (NUMFAILURE), and repeating the solving often helps to overcome // them. @@ -811,7 +809,7 @@ BALMLayout::_SolveLayout() fSolver->Variables()->CountItems(), fSolver->Constraints()->CountItems()));*/ } - if (result == OPTIMAL || result == INFEASIBLE) + if (result == kOptimal || result == kInfeasible) break; } delete file; @@ -834,9 +832,9 @@ BALMLayout::_CalculateMinSize() _SolveLayout(); fSolver->SetObjectiveFunction(oldObjFunction); - if (fSolver->Result() == UNBOUNDED) + if (fSolver->Result() == kUnbounded) return kMinSize; - if (fSolver->Result() != OPTIMAL) { + if (fSolver->Result() != kOptimal) { fSolver->Save("failed-layout.txt"); printf("Could not solve the layout specification (%d). " "Saved specification in file failed-layout.txt", fSolver->Result()); @@ -863,9 +861,9 @@ BALMLayout::_CalculateMaxSize() _SolveLayout(); fSolver->SetObjectiveFunction(oldObjFunction); - if (fSolver->Result() == UNBOUNDED) + if (fSolver->Result() == kUnbounded) return kMaxSize; - if (fSolver->Result() != OPTIMAL) { + if (fSolver->Result() != kOptimal) { fSolver->Save("failed-layout.txt"); printf("Could not solve the layout specification (%d). " "Saved specification in file failed-layout.txt", fSolver->Result()); @@ -885,7 +883,7 @@ BALMLayout::_CalculatePreferredSize() _UpdateAreaConstraints(); _SolveLayout(); - if (fSolver->Result() != OPTIMAL) { + if (fSolver->Result() != kOptimal) { fSolver->Save("failed-layout.txt"); printf("Could not solve the layout specification (%d). " "Saved specification in file failed-layout.txt", fSolver->Result()); diff --git a/src/libs/alm/Column.cpp b/src/libs/alm/Column.cpp index 9f0f2936a6..965363b696 100644 --- a/src/libs/alm/Column.cpp +++ b/src/libs/alm/Column.cpp @@ -9,7 +9,6 @@ #include "Column.h" #include "ALMLayout.h" -#include "OperatorType.h" #include "Tab.h" diff --git a/src/libs/alm/Row.cpp b/src/libs/alm/Row.cpp index fb635cb165..3d507f486e 100644 --- a/src/libs/alm/Row.cpp +++ b/src/libs/alm/Row.cpp @@ -9,7 +9,6 @@ #include "Row.h" #include "ALMLayout.h" -#include "OperatorType.h" #include "Tab.h" #include diff --git a/src/libs/linprog/LPSolveInterface.cpp b/src/libs/linprog/LPSolveInterface.cpp index a9d8b6830b..e22a715246 100644 --- a/src/libs/linprog/LPSolveInterface.cpp +++ b/src/libs/linprog/LPSolveInterface.cpp @@ -1,3 +1,11 @@ +/* + * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz + * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz + * Copyright 2010, Clemens Zeidler + * Distributed under the terms of the MIT License. + */ + + #include "LPSolveInterface.h" @@ -160,7 +168,7 @@ LPSolveInterface::SetObjectiveFunction(int nElements, double* coefficients, bool LPSolveInterface::SetOptimization(OptimizationType value) { - if (value == LinearProgramming::MINIMIZE) + if (value == kMinimize) set_minim(fLP); else set_maxim(fLP); diff --git a/src/libs/linprog/LPSolveInterface.h b/src/libs/linprog/LPSolveInterface.h index 7eda73ab52..0e3a85e13e 100644 --- a/src/libs/linprog/LPSolveInterface.h +++ b/src/libs/linprog/LPSolveInterface.h @@ -1,3 +1,7 @@ +/* + * Copyright 2010, Clemens Zeidler + * Distributed under the terms of the MIT License. + */ #ifndef LP_SOLVE_INTERFACE_H #define LP_SOLVE_INTERFACE_H diff --git a/src/libs/linprog/LinearSpec.cpp b/src/libs/linprog/LinearSpec.cpp index 79e8e09045..fb80b50440 100644 --- a/src/libs/linprog/LinearSpec.cpp +++ b/src/libs/linprog/LinearSpec.cpp @@ -20,9 +20,9 @@ */ LinearSpec::LinearSpec() : - fOptimization(MINIMIZE), + fOptimization(kMinimize), fObjFunction(new(std::nothrow) SummandList()), - fResult(ERROR), + fResult(kError), fObjectiveValue(NAN), fSolvingTime(NAN) { @@ -773,20 +773,20 @@ LinearSpec::GetString(BString& string) const string << "\n"; } string << "Result="; - if (fResult==-1) - string << "ERROR"; - else if (fResult==0) - string << "OPTIMAL"; - else if (fResult==1) - string << "SUBOPTIMAL"; - else if (fResult==2) - string << "INFEASIBLE"; - else if (fResult==3) - string << "UNBOUNDED"; - else if (fResult==4) - string << "DEGENERATE"; - else if (fResult==5) - string << "NUMFAILURE"; + if (fResult == kError) + string << "kError"; + else if (fResult == kOptimal) + string << "kOptimal"; + else if (fResult == kSuboptimal) + string << "kSuboptimal"; + else if (fResult == kInfeasible) + string << "kInfeasible"; + else if (fResult == kUnbounded) + string << "kUnbounded"; + else if (fResult == kDegenerate) + string << "kDegenerate"; + else if (fResult == kNumFailure) + string << "kNumFailure"; else string << fResult; string << " SolvingTime=" << (float)fSolvingTime << "ms"; diff --git a/src/libs/linprog/PenaltyFunction.cpp b/src/libs/linprog/PenaltyFunction.cpp index 481029f6ad..ac6071f2ed 100644 --- a/src/libs/linprog/PenaltyFunction.cpp +++ b/src/libs/linprog/PenaltyFunction.cpp @@ -11,7 +11,6 @@ #include "Constraint.h" #include "LinearSpec.h" -#include "OperatorType.h" #include "Summand.h" #include "Variable.h"