* Applied patch by Hong Yul Yang to update linprog.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33609 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-10-16 12:13:07 +00:00
parent 98b4079944
commit 676ef01ba7
8 changed files with 511 additions and 90 deletions
+65 -15
View File
@@ -12,21 +12,20 @@
* Creates a new specification for a linear programming problem.
*/
LinearSpec::LinearSpec()
: fCountColumns(0),
fLpPresolved(NULL),
fOptimization(MINIMIZE),
fObjFunction(new BList()),
fVariables(new BList()),
fConstraints(new BList()),
fResult(ERROR),
fObjectiveValue(NAN),
fSolvingTime(NAN)
{
fLP = make_lp(0, 0);
if (fLP == NULL)
printf("Couldn't construct a new model.");
set_verbose(fLP, 1);
fObjFunction = new BList();
fVariables = new BList();
fConstraints = new BList();
fCountColumns = 0;
fLpPresolved = NULL;
fOptimization = MINIMIZE;
fResult = ERROR;
fObjectiveValue = NAN;
fSolvingTime = NAN;
}
@@ -38,12 +37,11 @@ LinearSpec::LinearSpec()
LinearSpec::~LinearSpec()
{
RemovePresolved();
int i;
for (i=0; i<fConstraints->CountItems(); i++)
for (int32 i=0; i<fConstraints->CountItems(); i++)
delete (Constraint*)fConstraints->ItemAt(i);
for (i=0; i<fObjFunction->CountItems(); i++)
for (int32 i=0; i<fObjFunction->CountItems(); i++)
delete (Summand*)fObjFunction->ItemAt(i);
for (i=0; i<fVariables->CountItems(); i++)
for (int32 i=0; i<fVariables->CountItems(); i++)
delete (Variable*)fVariables->ItemAt(i);
delete_lp(fLP);
}
@@ -496,7 +494,7 @@ LinearSpec::Save(char* fname)
/**
* Gets the number of columns.
*
*
* @return the number of columns
*/
int32
@@ -595,3 +593,55 @@ LinearSpec::SolvingTime() const
return fSolvingTime;
}
BString*
LinearSpec::ToBString()
{
BString* str = new BString();
*str << "LinearSpec " << (int32)this << ":\n";
for (int i = 0; i < fVariables->CountItems(); i++) {
Variable* variable = static_cast<Variable*>(fVariables->ItemAt(i));
BString* vStr = variable->ToBString();
*str << *vStr << "=" << (float)variable->Value() << " ";
delete vStr;
}
*str << "\n";
for (int i = 0; i < fConstraints->CountItems(); i++) {
Constraint* c = static_cast<Constraint*>(fConstraints->ItemAt(i));
BString* cStr = c->ToBString();
*str << i << ": " << *cStr;
delete cStr;
*str << "\n";
}
*str << "Result=";
if (fResult==-1)
*str << "ERROR";
else if (fResult==0)
*str << "OPTIMAL";
else if (fResult==1)
*str << "SUBOPTIMAL";
else if (fResult==2)
*str << "INFEASIBLE";
else if (fResult==3)
*str << "UNBOUNDED";
else if (fResult==4)
*str << "DEGENERATE";
else if (fResult==5)
*str << "NUMFAILURE";
else
*str << fResult;
*str << " SolvingTime=" << (float)fSolvingTime << "ms";
return str;
}
const char*
LinearSpec::ToString()
{
BString* str = ToBString();
char* result = (char*) malloc(str->Length() + 1);
str->CopyInto(result, 0, str->Length());
delete str;
return result;
}