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:
+15
-10
@@ -32,6 +32,7 @@ class Area {
|
||||
public:
|
||||
bool AutoPrefContentSize() const;
|
||||
void SetAutoPrefContentSize(bool value);
|
||||
|
||||
XTab* Left() const;
|
||||
void SetLeft(XTab* left);
|
||||
XTab* Right() const;
|
||||
@@ -40,10 +41,12 @@ public:
|
||||
void SetTop(YTab* top);
|
||||
YTab* Bottom() const;
|
||||
void SetBottom(YTab* bottom);
|
||||
|
||||
Row* GetRow() const;
|
||||
void SetRow(Row* row);
|
||||
Column* GetColumn() const;
|
||||
void SetColumn(Column* column);
|
||||
|
||||
BView* Content() const;
|
||||
void SetContent(BView* content);
|
||||
XTab* ContentLeft() const;
|
||||
@@ -76,6 +79,7 @@ public:
|
||||
void SetBottomInset(int32 bottom);
|
||||
void SetDefaultPrefContentSize();
|
||||
//~ string ToString();
|
||||
|
||||
Constraint* HasSameWidthAs(Area* area);
|
||||
Constraint* HasSameHeightAs(Area* area);
|
||||
BList* HasSameSizetAs(Area* area);
|
||||
@@ -92,18 +96,18 @@ protected:
|
||||
void DoLayout();
|
||||
|
||||
private:
|
||||
void InitChildArea();
|
||||
void UpdateHorizontal();
|
||||
void UpdateVertical();
|
||||
void Init(BALMLayout* ls, XTab* left, YTab* top,
|
||||
XTab* right, YTab* bottom,
|
||||
BView* content,
|
||||
BSize minContentSize);
|
||||
void InitChildArea();
|
||||
void UpdateHorizontal();
|
||||
void UpdateVertical();
|
||||
void Init(BALMLayout* ls, XTab* left, YTab* top,
|
||||
XTab* right, YTab* bottom,
|
||||
BView* content,
|
||||
BSize minContentSize);
|
||||
|
||||
public:
|
||||
static BSize kMaxSize;
|
||||
static BSize kMinSize;
|
||||
static BSize kUndefinedSize;
|
||||
static BSize kMaxSize;
|
||||
static BSize kMinSize;
|
||||
static BSize kUndefinedSize;
|
||||
|
||||
protected:
|
||||
BView* fContent;
|
||||
@@ -152,3 +156,4 @@ public:
|
||||
using BALM::Area;
|
||||
|
||||
#endif // AREA_H
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class BALMLayout : public BLayout, public LinearSpec {
|
||||
|
||||
public:
|
||||
BALMLayout();
|
||||
void SolveLayout();
|
||||
void SolveLayout();
|
||||
|
||||
XTab* AddXTab();
|
||||
YTab* AddYTab();
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
Row* AddRow(YTab* top, YTab* bottom);
|
||||
Column* AddColumn();
|
||||
Column* AddColumn(XTab* left, XTab* right);
|
||||
|
||||
Area* AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
|
||||
BView* content, BSize minContentSize);
|
||||
Area* AddArea(Row* row, Column* column, BView* content,
|
||||
@@ -50,40 +51,37 @@ public:
|
||||
Area* AddArea(Row* row, Column* column, BView* content);
|
||||
Area* AreaOf(BView* control);
|
||||
BList* Areas() const;
|
||||
void SetAreas(BList* areas);
|
||||
XTab* Left() const;
|
||||
void SetLeft(XTab* left);
|
||||
XTab* Right() const;
|
||||
void SetRight(XTab* right);
|
||||
YTab* Top() const;
|
||||
void SetTop(YTab* top);
|
||||
YTab* Bottom() const;
|
||||
void SetBottom(YTab* bottom);
|
||||
|
||||
void RecoverLayout(BView* parent);
|
||||
LayoutStyleType LayoutStyle() const;
|
||||
void SetLayoutStyle(LayoutStyleType style);
|
||||
|
||||
BLayoutItem* AddView(BView* child);
|
||||
BLayoutItem* AddView(int32 index, BView* child);
|
||||
XTab* Left() const;
|
||||
XTab* Right() const;
|
||||
YTab* Top() const;
|
||||
YTab* Bottom() const;
|
||||
|
||||
void RecoverLayout(BView* parent);
|
||||
|
||||
LayoutStyleType LayoutStyle() const;
|
||||
void SetLayoutStyle(LayoutStyleType style);
|
||||
|
||||
BLayoutItem* AddView(BView* child);
|
||||
BLayoutItem* AddView(int32 index, BView* child);
|
||||
bool AddItem(BLayoutItem* item);
|
||||
bool AddItem(int32 index, BLayoutItem* item);
|
||||
bool RemoveView(BView* child);
|
||||
bool RemoveItem(BLayoutItem* item);
|
||||
BLayoutItem* RemoveItem(int32 index);
|
||||
BLayoutItem* RemoveItem(int32 index);
|
||||
|
||||
BSize MinSize();
|
||||
BSize MaxSize();
|
||||
BSize PreferredSize();
|
||||
BAlignment Alignment();
|
||||
bool HasHeightForWidth();
|
||||
void GetHeightForWidth(float width, float* min,
|
||||
void GetHeightForWidth(float width, float* min,
|
||||
float* max, float* preferred);
|
||||
void InvalidateLayout();
|
||||
void LayoutView();
|
||||
void InvalidateLayout();
|
||||
void LayoutView();
|
||||
|
||||
char* PerformancePath() const;
|
||||
void SetPerformancePath(char* path);
|
||||
void SetPerformancePath(char* path);
|
||||
|
||||
private:
|
||||
BSize CalculateMinSize();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -37,3 +37,4 @@ private:
|
||||
using LinearProgramming::Summand;
|
||||
|
||||
#endif // OBJ_FUNCTION_SUMMAND_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user