Fix some memory leaks.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38735 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -112,8 +112,8 @@ private:
|
|||||||
OptimizationType fOptimization;
|
OptimizationType fOptimization;
|
||||||
lprec* fLP;
|
lprec* fLP;
|
||||||
BList* fObjFunction;
|
BList* fObjFunction;
|
||||||
BList* fVariables;
|
BList fVariables;
|
||||||
BList* fConstraints;
|
BList fConstraints;
|
||||||
ResultType fResult;
|
ResultType fResult;
|
||||||
double fObjectiveValue;
|
double fObjectiveValue;
|
||||||
double fSolvingTime;
|
double fSolvingTime;
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ LinearSpec::LinearSpec()
|
|||||||
fLpPresolved(NULL),
|
fLpPresolved(NULL),
|
||||||
fOptimization(MINIMIZE),
|
fOptimization(MINIMIZE),
|
||||||
fObjFunction(new BList()),
|
fObjFunction(new BList()),
|
||||||
fVariables(new BList()),
|
|
||||||
fConstraints(new BList()),
|
|
||||||
fResult(ERROR),
|
fResult(ERROR),
|
||||||
fObjectiveValue(NAN),
|
fObjectiveValue(NAN),
|
||||||
fSolvingTime(NAN)
|
fSolvingTime(NAN)
|
||||||
@@ -37,13 +35,15 @@ LinearSpec::LinearSpec()
|
|||||||
LinearSpec::~LinearSpec()
|
LinearSpec::~LinearSpec()
|
||||||
{
|
{
|
||||||
RemovePresolved();
|
RemovePresolved();
|
||||||
for (int32 i=0; i<fConstraints->CountItems(); i++)
|
for (int32 i = 0; i < fConstraints.CountItems(); i++)
|
||||||
delete (Constraint*)fConstraints->ItemAt(i);
|
delete (Constraint*)fConstraints.ItemAt(i);
|
||||||
for (int32 i=0; i<fObjFunction->CountItems(); i++)
|
for (int32 i = 0; i < fObjFunction->CountItems(); i++)
|
||||||
delete (Summand*)fObjFunction->ItemAt(i);
|
delete (Summand*)fObjFunction->ItemAt(i);
|
||||||
for (int32 i=0; i<fVariables->CountItems(); i++)
|
for (int32 i = 0; i < fVariables.CountItems(); i++)
|
||||||
delete (Variable*)fVariables->ItemAt(i);
|
delete (Variable*)fVariables.ItemAt(i);
|
||||||
delete_lp(fLP);
|
delete_lp(fLP);
|
||||||
|
|
||||||
|
delete fObjFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -426,9 +426,9 @@ LinearSpec::Presolve()
|
|||||||
fObjectiveValue = get_objective(fLpPresolved);
|
fObjectiveValue = get_objective(fLpPresolved);
|
||||||
|
|
||||||
if (fResult == OPTIMAL) {
|
if (fResult == OPTIMAL) {
|
||||||
int32 size = fVariables->CountItems();
|
int32 size = fVariables.CountItems();
|
||||||
for (int32 i = 0; i < size; i++) {
|
for (int32 i = 0; i < size; i++) {
|
||||||
Variable* current = (Variable*)fVariables->ItemAt(i);
|
Variable* current = (Variable*)fVariables.ItemAt(i);
|
||||||
current->SetValue(get_var_primalresult(fLpPresolved,
|
current->SetValue(get_var_primalresult(fLpPresolved,
|
||||||
get_Norig_rows(fLpPresolved) + current->Index()));
|
get_Norig_rows(fLpPresolved) + current->Index()));
|
||||||
}
|
}
|
||||||
@@ -460,14 +460,14 @@ LinearSpec::Solve()
|
|||||||
fObjectiveValue = get_objective(fLP);
|
fObjectiveValue = get_objective(fLP);
|
||||||
|
|
||||||
if (fResult == OPTIMAL) {
|
if (fResult == OPTIMAL) {
|
||||||
int32 size = fVariables->CountItems();
|
int32 size = fVariables.CountItems();
|
||||||
double x[size];
|
double x[size];
|
||||||
if (!get_variables(fLP, &x[0]))
|
if (!get_variables(fLP, &x[0]))
|
||||||
printf("Error in get_variables.");
|
printf("Error in get_variables.");
|
||||||
|
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
while (i < size) {
|
while (i < size) {
|
||||||
((Variable*)fVariables->ItemAt(i))->SetValue(x[i]);
|
((Variable*)fVariables.ItemAt(i))->SetValue(x[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,7 +543,7 @@ LinearSpec::SetOptimization(OptimizationType value)
|
|||||||
BList*
|
BList*
|
||||||
LinearSpec::Variables() const
|
LinearSpec::Variables() const
|
||||||
{
|
{
|
||||||
return fVariables;
|
return const_cast<BList*>(&fVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ LinearSpec::Variables() const
|
|||||||
BList*
|
BList*
|
||||||
LinearSpec::Constraints() const
|
LinearSpec::Constraints() const
|
||||||
{
|
{
|
||||||
return fConstraints;
|
return const_cast<BList*>(&fConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -607,14 +607,14 @@ void
|
|||||||
LinearSpec::GetString(BString& string) const
|
LinearSpec::GetString(BString& string) const
|
||||||
{
|
{
|
||||||
string << "LinearSpec " << (int32)this << ":\n";
|
string << "LinearSpec " << (int32)this << ":\n";
|
||||||
for (int i = 0; i < fVariables->CountItems(); i++) {
|
for (int i = 0; i < fVariables.CountItems(); i++) {
|
||||||
Variable* variable = static_cast<Variable*>(fVariables->ItemAt(i));
|
Variable* variable = static_cast<Variable*>(fVariables.ItemAt(i));
|
||||||
variable->GetString(string);
|
variable->GetString(string);
|
||||||
string << "=" << (float)variable->Value() << " ";
|
string << "=" << (float)variable->Value() << " ";
|
||||||
}
|
}
|
||||||
string << "\n";
|
string << "\n";
|
||||||
for (int i = 0; i < fConstraints->CountItems(); i++) {
|
for (int i = 0; i < fConstraints.CountItems(); i++) {
|
||||||
Constraint* c = static_cast<Constraint*>(fConstraints->ItemAt(i));
|
Constraint* c = static_cast<Constraint*>(fConstraints.ItemAt(i));
|
||||||
string << i << ": ";
|
string << i << ": ";
|
||||||
c->GetString(string);
|
c->GetString(string);
|
||||||
string << "\n";
|
string << "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user