Merge all linear programming types in one file an rename them.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39832 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-12-13 19:23:33 +00:00
parent cbe1fb0f0c
commit f108cdbfab
14 changed files with 99 additions and 125 deletions
+1 -1
View File
@@ -13,7 +13,7 @@
#include <String.h> #include <String.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include "OperatorType.h" #include "LinearProgrammingTypes.h"
#include "Summand.h" #include "Summand.h"
#include "Variable.h" #include "Variable.h"
@@ -0,0 +1,57 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Copyright 2010, Clemens Zeidler <[email protected]>
* 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
+1 -3
View File
@@ -15,10 +15,8 @@
#include <SupportDefs.h> #include <SupportDefs.h>
#include "Constraint.h" #include "Constraint.h"
#include "OperatorType.h" #include "LinearProgrammingTypes.h"
#include "OptimizationType.h"
#include "PenaltyFunction.h" #include "PenaltyFunction.h"
#include "ResultType.h"
#include "Summand.h" #include "Summand.h"
#include "Variable.h" #include "Variable.h"
-26
View File
@@ -1,26 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#ifndef OPERATOR_TYPE_H
#define OPERATOR_TYPE_H
namespace LinearProgramming {
/**
* Possible operators for linear constraints.
*/
enum OperatorType {
kEQ,
kLE,
kGE
};
} // namespace LinearProgramming
using LinearProgramming::OperatorType;
#endif
-24
View File
@@ -1,24 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#ifndef OPTIMIZATION_TYPE_H
#define OPTIMIZATION_TYPE_H
namespace LinearProgramming {
/**
* The two possibilities for optimizing the objective function.
*/
enum OptimizationType {
MINIMIZE, MAXIMIZE
};
} // namespace LinearProgramming
using LinearProgramming::OptimizationType;
#endif
-38
View File
@@ -1,38 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#ifndef RESULT_TYPE_H
#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
@@ -88,11 +88,11 @@ GroupCookie::DoGroupLayout(SATWindow* triggerWindow)
ResultType result; ResultType result;
for (int32 tries = 0; tries < 15; tries++) { for (int32 tries = 0; tries < 15; tries++) {
result = fSATGroup->GetLinearSpec()->Solve(); result = fSATGroup->GetLinearSpec()->Solve();
if (result == INFEASIBLE) { if (result == kInfeasible) {
debug_printf("can't solve constraints!\n"); debug_printf("can't solve constraints!\n");
break; break;
} }
if (result == OPTIMAL) { if (result == kOptimal) {
fSATGroup->AdjustWindows(triggerWindow); fSATGroup->AdjustWindows(triggerWindow);
_UpdateWindowSize(frame); _UpdateWindowSize(frame);
break; break;
+9 -11
View File
@@ -14,8 +14,6 @@
#include "ViewLayoutItem.h" #include "ViewLayoutItem.h"
#include "ResultType.h"
using namespace LinearProgramming; using namespace LinearProgramming;
@@ -706,10 +704,10 @@ BALMLayout::DerivedLayoutItems()
_SolveLayout(); _SolveLayout();
// if new layout is infeasible, use previous layout // if new layout is infeasible, use previous layout
if (fSolver->Result() == INFEASIBLE) if (fSolver->Result() == kInfeasible)
return; return;
if (fSolver->Result() != OPTIMAL) { if (fSolver->Result() != kOptimal) {
fSolver->Save("failed-layout.txt"); fSolver->Save("failed-layout.txt");
printf("Could not solve the layout specification (%d). ", printf("Could not solve the layout specification (%d). ",
fSolver->Result()); fSolver->Result());
@@ -791,7 +789,7 @@ BALMLayout::_CreateLayoutItem(BView* view)
void void
BALMLayout::_SolveLayout() 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 // maximally 15 tries sometimes the solving algorithm encounters numerical
// problems (NUMFAILURE), and repeating the solving often helps to overcome // problems (NUMFAILURE), and repeating the solving often helps to overcome
// them. // them.
@@ -811,7 +809,7 @@ BALMLayout::_SolveLayout()
fSolver->Variables()->CountItems(), fSolver->Variables()->CountItems(),
fSolver->Constraints()->CountItems()));*/ fSolver->Constraints()->CountItems()));*/
} }
if (result == OPTIMAL || result == INFEASIBLE) if (result == kOptimal || result == kInfeasible)
break; break;
} }
delete file; delete file;
@@ -834,9 +832,9 @@ BALMLayout::_CalculateMinSize()
_SolveLayout(); _SolveLayout();
fSolver->SetObjectiveFunction(oldObjFunction); fSolver->SetObjectiveFunction(oldObjFunction);
if (fSolver->Result() == UNBOUNDED) if (fSolver->Result() == kUnbounded)
return kMinSize; return kMinSize;
if (fSolver->Result() != OPTIMAL) { if (fSolver->Result() != kOptimal) {
fSolver->Save("failed-layout.txt"); fSolver->Save("failed-layout.txt");
printf("Could not solve the layout specification (%d). " printf("Could not solve the layout specification (%d). "
"Saved specification in file failed-layout.txt", fSolver->Result()); "Saved specification in file failed-layout.txt", fSolver->Result());
@@ -863,9 +861,9 @@ BALMLayout::_CalculateMaxSize()
_SolveLayout(); _SolveLayout();
fSolver->SetObjectiveFunction(oldObjFunction); fSolver->SetObjectiveFunction(oldObjFunction);
if (fSolver->Result() == UNBOUNDED) if (fSolver->Result() == kUnbounded)
return kMaxSize; return kMaxSize;
if (fSolver->Result() != OPTIMAL) { if (fSolver->Result() != kOptimal) {
fSolver->Save("failed-layout.txt"); fSolver->Save("failed-layout.txt");
printf("Could not solve the layout specification (%d). " printf("Could not solve the layout specification (%d). "
"Saved specification in file failed-layout.txt", fSolver->Result()); "Saved specification in file failed-layout.txt", fSolver->Result());
@@ -885,7 +883,7 @@ BALMLayout::_CalculatePreferredSize()
_UpdateAreaConstraints(); _UpdateAreaConstraints();
_SolveLayout(); _SolveLayout();
if (fSolver->Result() != OPTIMAL) { if (fSolver->Result() != kOptimal) {
fSolver->Save("failed-layout.txt"); fSolver->Save("failed-layout.txt");
printf("Could not solve the layout specification (%d). " printf("Could not solve the layout specification (%d). "
"Saved specification in file failed-layout.txt", fSolver->Result()); "Saved specification in file failed-layout.txt", fSolver->Result());
-1
View File
@@ -9,7 +9,6 @@
#include "Column.h" #include "Column.h"
#include "ALMLayout.h" #include "ALMLayout.h"
#include "OperatorType.h"
#include "Tab.h" #include "Tab.h"
-1
View File
@@ -9,7 +9,6 @@
#include "Row.h" #include "Row.h"
#include "ALMLayout.h" #include "ALMLayout.h"
#include "OperatorType.h"
#include "Tab.h" #include "Tab.h"
#include <SupportDefs.h> #include <SupportDefs.h>
+9 -1
View File
@@ -1,3 +1,11 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Copyright 2010, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License.
*/
#include "LPSolveInterface.h" #include "LPSolveInterface.h"
@@ -160,7 +168,7 @@ LPSolveInterface::SetObjectiveFunction(int nElements, double* coefficients,
bool bool
LPSolveInterface::SetOptimization(OptimizationType value) LPSolveInterface::SetOptimization(OptimizationType value)
{ {
if (value == LinearProgramming::MINIMIZE) if (value == kMinimize)
set_minim(fLP); set_minim(fLP);
else else
set_maxim(fLP); set_maxim(fLP);
+4
View File
@@ -1,3 +1,7 @@
/*
* Copyright 2010, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License.
*/
#ifndef LP_SOLVE_INTERFACE_H #ifndef LP_SOLVE_INTERFACE_H
#define LP_SOLVE_INTERFACE_H #define LP_SOLVE_INTERFACE_H
+16 -16
View File
@@ -20,9 +20,9 @@
*/ */
LinearSpec::LinearSpec() LinearSpec::LinearSpec()
: :
fOptimization(MINIMIZE), fOptimization(kMinimize),
fObjFunction(new(std::nothrow) SummandList()), fObjFunction(new(std::nothrow) SummandList()),
fResult(ERROR), fResult(kError),
fObjectiveValue(NAN), fObjectiveValue(NAN),
fSolvingTime(NAN) fSolvingTime(NAN)
{ {
@@ -773,20 +773,20 @@ LinearSpec::GetString(BString& string) const
string << "\n"; string << "\n";
} }
string << "Result="; string << "Result=";
if (fResult==-1) if (fResult == kError)
string << "ERROR"; string << "kError";
else if (fResult==0) else if (fResult == kOptimal)
string << "OPTIMAL"; string << "kOptimal";
else if (fResult==1) else if (fResult == kSuboptimal)
string << "SUBOPTIMAL"; string << "kSuboptimal";
else if (fResult==2) else if (fResult == kInfeasible)
string << "INFEASIBLE"; string << "kInfeasible";
else if (fResult==3) else if (fResult == kUnbounded)
string << "UNBOUNDED"; string << "kUnbounded";
else if (fResult==4) else if (fResult == kDegenerate)
string << "DEGENERATE"; string << "kDegenerate";
else if (fResult==5) else if (fResult == kNumFailure)
string << "NUMFAILURE"; string << "kNumFailure";
else else
string << fResult; string << fResult;
string << " SolvingTime=" << (float)fSolvingTime << "ms"; string << " SolvingTime=" << (float)fSolvingTime << "ms";
-1
View File
@@ -11,7 +11,6 @@
#include "Constraint.h" #include "Constraint.h"
#include "LinearSpec.h" #include "LinearSpec.h"
#include "OperatorType.h"
#include "Summand.h" #include "Summand.h"
#include "Variable.h" #include "Variable.h"