Simplify code and clean up.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38738 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-09-20 04:52:30 +00:00
parent b329767e2f
commit 43b24b87de
5 changed files with 20 additions and 30 deletions
+10 -12
View File
@@ -3,7 +3,6 @@
* Copyright 2007-2008, James Kim, [email protected] * Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef SUMMAND_H #ifndef SUMMAND_H
#define SUMMAND_H #define SUMMAND_H
@@ -17,20 +16,19 @@ class Variable;
* A summand of a linear term. * A summand of a linear term.
*/ */
class Summand { class Summand {
public: public:
double Coeff(); Summand(double coeff, Variable* var);
void SetCoeff(double coeff); ~Summand();
Variable* Var();
void SetVar(Variable* var); double Coeff();
Summand(double coeff, Variable* var); void SetCoeff(double coeff);
~Summand(); Variable* Var();
void SetVar(Variable* var);
private: private:
double fCoeff; double fCoeff;
Variable* fVar; Variable* fVar;
bool fUsedInPenaltyFunction; //not set yet bool fUsedInPenaltyFunction; //not set yet
}; };
} // namespace LinearProgramming } // namespace LinearProgramming
+2 -2
View File
@@ -7,7 +7,7 @@
#define VARIABLE_H #define VARIABLE_H
#include <File.h> #include <File.h>
#include <List.h> #include <ObjectList.h>
#include <String.h> #include <String.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -60,7 +60,7 @@ protected:
private: private:
LinearSpec* fLS; LinearSpec* fLS;
BList* fUsingSummands; BObjectList<Summand> fUsingSummands;
// All Summands that link to this Variable // All Summands that link to this Variable
double fValue; double fValue;
double fMin; double fMin;
+1
View File
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src libs linprog ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
UseLibraryHeaders lp_solve linprog ; UseLibraryHeaders lp_solve linprog ;
UsePrivateHeaders shared ;
SharedLibrary liblinprog.so : SharedLibrary liblinprog.so :
Constraint.cpp Constraint.cpp
+2 -3
View File
@@ -62,7 +62,7 @@ Summand::SetVar(Variable* var)
*/ */
Summand::~Summand() Summand::~Summand()
{ {
fVar->fUsingSummands->RemoveItem(this); fVar->fUsingSummands.RemoveItem(this);
} }
@@ -74,7 +74,6 @@ Summand::Summand(double coeff, Variable* var)
fCoeff = coeff; fCoeff = coeff;
fVar = var; fVar = var;
fUsedInPenaltyFunction = false; fUsedInPenaltyFunction = false;
fVar->fUsingSummands->AddItem(this); fVar->fUsingSummands.AddItem(this);
} }
+5 -13
View File
@@ -97,11 +97,7 @@ Variable::Min() const
void void
Variable::SetMin(double min) Variable::SetMin(double min)
{ {
if (!fIsValid) SetRange(min, fMax);
return;
fMin = min;
set_bounds(fLS->fLP, this->Index(), fMin, fMax);
} }
@@ -125,11 +121,7 @@ Variable::Max() const
void void
Variable::SetMax(double max) Variable::SetMax(double max)
{ {
if (!fIsValid) SetRange(fMin, max);
return;
fMax = max;
set_bounds(fLS->fLP, this->Index(), fMin, fMax);
} }
@@ -325,8 +317,9 @@ Variable::Invalidate()
* Constructor. * Constructor.
*/ */
Variable::Variable(LinearSpec* ls) Variable::Variable(LinearSpec* ls)
: fLS(ls), :
fUsingSummands(new BList()), fLS(ls),
fValue(NAN), fValue(NAN),
fMin(0), fMin(0),
fMax(DBL_MAX), fMax(DBL_MAX),
@@ -353,6 +346,5 @@ Variable::Variable(LinearSpec* ls)
Variable::~Variable() Variable::~Variable()
{ {
Invalidate(); Invalidate();
delete fUsingSummands;
} }