ALM/linprog patch by Christof Lutteroth:

* Got rid of class ObjFunctionSummand. Both the constraint summands and
  the objective function summands are now stored using class Summand.
* Some method names are more BeOS compliant now: SetX instead of ChangeX.
* linprog test code now uses new AddConstraint methods.
* CalculateMinSize and CalculateMaxSize did not free the memory they
  allocated.
* Removed inappropriate setter and getter methods.
* Memory allocated in class Constraint is freed now.
* Other small changes.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24351 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-03-10 21:43:32 +00:00
parent 0bc0282224
commit 5bced18eab
16 changed files with 361 additions and 665 deletions
+16 -15
View File
@@ -9,7 +9,7 @@
#include "OperatorType.h"
#include "Variable.h"
#include "ObjFunctionSummand.h"
#include "Summand.h"
#include <List.h>
#include <String.h>
@@ -29,18 +29,21 @@ class Constraint {
public:
int32 Index();
BList* Summands();
void ChangeLeftSide(BList* summands);
void ChangeLeftSide(double coeff1, Variable* var1);
void ChangeLeftSide(double coeff1, Variable* var1,
BList* LeftSide();
void SetLeftSide(BList* summands);
void UpdateLeftSide();
void SetLeftSide(double coeff1, Variable* var1);
void SetLeftSide(double coeff1, Variable* var1,
double coeff2, Variable* var2);
void ChangeLeftSide(double coeff1, Variable* var1,
void SetLeftSide(double coeff1, Variable* var1,
double coeff2, Variable* var2,
double coeff3, Variable* var3);
void ChangeLeftSide(double coeff1, Variable* var1,
void SetLeftSide(double coeff1, Variable* var1,
double coeff2, Variable* var2,
double coeff3, Variable* var3,
double coeff4, Variable* var4);
OperatorType Op();
void SetOp(OperatorType value);
double RightSide();
@@ -49,6 +52,7 @@ public:
void SetPenaltyNeg(double value);
double PenaltyPos();
void SetPenaltyPos(double value);
Variable* DNeg() const;
Variable* DPos() const;
@@ -56,21 +60,17 @@ public:
~Constraint();
protected:
Constraint(LinearSpec* ls, BList* summands,
Constraint(LinearSpec* ls, BList* summands,
OperatorType op, double rightSide,
double penaltyNeg, double penaltyPos);
private:
LinearSpec* fLS;
BList* fSummands;
BList* fLeftSide;
OperatorType fOp;
double fRightSide;
Variable* fDNeg;
Variable* fDPos;
ObjFunctionSummand* fDNegSummand;
ObjFunctionSummand* fDPosSummand;
void _UpdateLeftSide();
Summand* fDNegObjSummand;
Summand* fDPosObjSummand;
public:
friend class LinearSpec;
@@ -82,3 +82,4 @@ public:
using LinearProgramming::Constraint;
#endif // CONSTRAINT_H
+16 -19
View File
@@ -7,6 +7,10 @@
#ifndef LINEAR_SPEC_H
#define LINEAR_SPEC_H
#include "Variable.h"
#include "Constraint.h"
#include "Summand.h"
#include "PenaltyFunction.h"
#include "OperatorType.h"
#include "ResultType.h"
#include "OptimizationType.h"
@@ -34,9 +38,7 @@ class LinearSpec {
public:
LinearSpec();
~LinearSpec();
void UpdateObjFunction();
void SetObjFunction(BList* summands);
ObjFunctionSummand* AddObjFunctionSummand(double coeff, Variable* var);
Variable* AddVariable();
Constraint* AddConstraint(BList* summands,
@@ -79,47 +81,42 @@ public:
double penaltyNeg, double penaltyPos);
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
void RemovePresolved();
BList* ObjFunction();
void SetObjFunction(BList* summands);
void UpdateObjFunction();
ResultType Presolve();
void RemovePresolved();
ResultType Solve();
void Save(char* fname);
int32 Columns() const;
void SetColumns(int32 value);
int32 CountColumns() const;
OptimizationType Optimization() const;
void SetOptimization(OptimizationType value);
lprec* LP() const;
void SetLP(lprec* value);
BList* ObjFunctionSummands() const;
void SetObjFunctionSummands(BList* value);
BList* Variables() const;
void SetVariables(BList* value);
BList* Constraints() const;
void SetConstraints(BList* value);
ResultType Result() const;
void SetResult(ResultType value);
double ObjectiveValue() const;
void SetObjectiveValue(double value);
double SolvingTime() const;
void SetSolvingTime(double value);
protected:
int32 fColumns;
int32 fCountColumns;
private:
lprec* fLpPresolved;
OptimizationType fOptimization;
lprec* fLP;
BList* fObjFunctionSummands;
BList* fObjFunction;
BList* fVariables;
BList* fConstraints;
ResultType fResult;
double fObjectiveValue;
double fSolvingTime; // = Double.Nan
double fSolvingTime;
public:
friend class ObjFunctionSummand;
friend class Constraint;
friend class Variable;
};
-43
View File
@@ -1,43 +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 OBJ_FUNCTION_SUMMAND_H
#define OBJ_FUNCTION_SUMMAND_H
#include "Summand.h"
namespace LinearProgramming {
class LinearSpec;
class Variable;
/**
* A summand of the objective function.
*/
class ObjFunctionSummand : public Summand {
public:
void SetCoeff(double coeff);
void SetVar(Variable* var);
~ObjFunctionSummand();
protected:
ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var);
private:
LinearSpec* fLS;
public:
friend class LinearSpec;
};
} // namespace LinearProgramming
using LinearProgramming::ObjFunctionSummand;
#endif // OBJ_FUNCTION_SUMMAND_H
+4 -3
View File
@@ -26,12 +26,12 @@ protected:
public:
~PenaltyFunction();
const Variable* Var() const;
const BList* Xs() const;
const BList* Gs() const;
const BList* Xs() const;
const BList* Gs() const;
private:
LinearSpec* fLS;
Variable* fVar;
Variable* fVar;
BList* fXs; // double
BList* fGs; // double
BList* fConstraints;
@@ -47,3 +47,4 @@ public:
using LinearProgramming::PenaltyFunction;
#endif // PENALTY_FUNCTION_H
+1
View File
@@ -37,3 +37,4 @@ private:
using LinearProgramming::Summand;
#endif // OBJ_FUNCTION_SUMMAND_H