Added libalm.so and its dependency liblinprog.so. libalm.so provides a
BLayout implementation (BALMLayout) using the Auckland Layout Model (ALM). The original ALM was implemented by Christof Lutteroth, the Haiku/C++ version by James Kim. The code needs some review, but the test programs seem to work fine. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23889 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#ifndef CONSTRAINT_H
|
||||
#define CONSTRAINT_H
|
||||
|
||||
#include "OperatorType.h"
|
||||
|
||||
#include <List.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
class LinearSpec;
|
||||
|
||||
/**
|
||||
* Hard linear constraint, i.e. one that must be satisfied.
|
||||
* May render a specification infeasible.
|
||||
*/
|
||||
class Constraint {
|
||||
|
||||
public:
|
||||
int32 Index();
|
||||
BList* Coeffs();
|
||||
BList* Vars();
|
||||
virtual void ChangeLeftSide(BList* coeffs, BList* vars);
|
||||
virtual OperatorType Op();
|
||||
virtual void SetOp(OperatorType value);
|
||||
double RightSide();
|
||||
void SetRightSide(double value);
|
||||
BString ToString();
|
||||
virtual ~Constraint();
|
||||
|
||||
protected:
|
||||
Constraint();
|
||||
|
||||
private:
|
||||
Constraint(LinearSpec* ls, BList* coeffs, BList* vars,
|
||||
OperatorType op, double rightSide);
|
||||
|
||||
protected:
|
||||
LinearSpec* fLS;
|
||||
BList* fCoeffs;
|
||||
BList* fVars;
|
||||
OperatorType fOp;
|
||||
double fRightSide;
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::Constraint;
|
||||
|
||||
#endif // CONSTRAINT_H
|
||||
@@ -0,0 +1,124 @@
|
||||
#ifndef LINEAR_SPEC_H
|
||||
#define LINEAR_SPEC_H
|
||||
|
||||
#include "OperatorType.h"
|
||||
#include "ResultType.h"
|
||||
#include "OptimizationType.h"
|
||||
|
||||
#include "lp_lib.h"
|
||||
|
||||
#include <List.h>
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
class Constraint;
|
||||
class ObjFunctionSummand;
|
||||
class PenaltyFunction;
|
||||
class SoftConstraint;
|
||||
class Variable;
|
||||
|
||||
/**
|
||||
* Specification of a linear programming problem.
|
||||
*/
|
||||
class LinearSpec {
|
||||
|
||||
public:
|
||||
LinearSpec();
|
||||
~LinearSpec();
|
||||
void UpdateObjFunction();
|
||||
void SetObjFunction(BList* coeffs, BList* vars);
|
||||
ObjFunctionSummand* AddObjFunctionSummand(double coeff, Variable* var);
|
||||
Variable* AddVariable();
|
||||
|
||||
Constraint* AddConstraint(BList* coeffs, BList* vars,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
OperatorType op, double rightSide);
|
||||
Constraint* AddConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
double coeff4, Variable* var4,
|
||||
OperatorType op, double rightSide);
|
||||
|
||||
SoftConstraint* AddSoftConstraint(BList* coeffs, BList* vars,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
SoftConstraint* AddSoftConstraint(double coeff1, Variable* var1,
|
||||
double coeff2, Variable* var2,
|
||||
double coeff3, Variable* var3,
|
||||
double coeff4, Variable* var4,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
|
||||
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
|
||||
void RemovePresolved();
|
||||
ResultType Presolve();
|
||||
ResultType Solve();
|
||||
void Save(char* fname);
|
||||
|
||||
int32 Columns() const;
|
||||
void SetColumns(int32 value);
|
||||
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;
|
||||
|
||||
private:
|
||||
lprec* fLpPresolved;
|
||||
OptimizationType fOptimization;
|
||||
lprec* fLP;
|
||||
BList* fObjFunctionSummands;
|
||||
BList* fVariables;
|
||||
BList* fConstraints;
|
||||
ResultType fResult;
|
||||
double fObjectiveValue;
|
||||
double fSolvingTime; // = Double.Nan
|
||||
|
||||
public:
|
||||
friend class ObjFunctionSummand;
|
||||
friend class SoftConstraint;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::LinearSpec;
|
||||
|
||||
#endif // LINEAR_SPEC_H
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef OBJ_FUNCTION_SUMMAND_H
|
||||
#define OBJ_FUNCTION_SUMMAND_H
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
class LinearSpec;
|
||||
class Variable;
|
||||
|
||||
/**
|
||||
* A summand of the objective function.
|
||||
*/
|
||||
class ObjFunctionSummand {
|
||||
|
||||
public:
|
||||
double Coeff();
|
||||
void SetCoeff(double coeff);
|
||||
Variable* Var();
|
||||
void SetVar(Variable* var);
|
||||
~ObjFunctionSummand();
|
||||
|
||||
protected:
|
||||
ObjFunctionSummand(LinearSpec* ls, double coeff, Variable* var);
|
||||
|
||||
private:
|
||||
LinearSpec* fLS;
|
||||
double fCoeff;
|
||||
Variable* fVar;
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::ObjFunctionSummand;
|
||||
|
||||
#endif // OBJ_FUNCTION_SUMMAND_H
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef OPERATOR_TYPE_H
|
||||
#define OPERATOR_TYPE_H
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
/**
|
||||
* Possible operators for linear constraints.
|
||||
*/
|
||||
enum OperatorType {
|
||||
EQ, LE, GE
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::OperatorType;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef OPTIMIZATION_TYPE_H
|
||||
#define OPTIMIZATION_TYPE_H
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
/**
|
||||
* The two possibilities for optimizing the objective function.
|
||||
*/
|
||||
enum OptimizationType {
|
||||
MINIMIZE, MAXIMIZE
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::OptimizationType;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef PENALTY_FUNCTION_H
|
||||
#define PENALTY_FUNCTION_H
|
||||
|
||||
#include <List.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
class LinearSpec;
|
||||
class Variable;
|
||||
|
||||
/**
|
||||
* Penalty function.
|
||||
*/
|
||||
class PenaltyFunction {
|
||||
|
||||
protected:
|
||||
PenaltyFunction(LinearSpec* ls, Variable* var, BList* xs, BList* gs);
|
||||
|
||||
public:
|
||||
~PenaltyFunction();
|
||||
const Variable* Var() const;
|
||||
const BList* Xs() const;
|
||||
const BList* Gs() const;
|
||||
|
||||
private:
|
||||
LinearSpec* fLS;
|
||||
Variable* fVar;
|
||||
BList* fXs; // double
|
||||
BList* fGs; // double
|
||||
BList* fConstraints;
|
||||
BList* fObjFunctionSummands;
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::PenaltyFunction;
|
||||
|
||||
#endif // PENALTY_FUNCTION_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef RESULT_TYPE_H
|
||||
#define RESULT_TYPE_H
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
/**
|
||||
* The possible results of a solving attempt.
|
||||
*/
|
||||
enum ResultType {
|
||||
NOMEMORY = -2, ERROR = -1, OPTIMAL = 0, SUBOPTIMAL = 1, INFEASIBLE = 2, UNBOUNDED = 3,
|
||||
DEGENERATE = 4, NUMFAILURE = 5, USERABORT = 6, TIMEOUT = 7, PRESOLVED = 9, PROCFAIL = 10,
|
||||
PROCBREAK = 11, FEASFOUND = 12, NOFEASFOUND = 13
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::ResultType;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef SOFT_CONSTRAINT_H
|
||||
#define SOFT_CONSTRAINT_H
|
||||
|
||||
#include "Constraint.h"
|
||||
|
||||
#include <List.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
class LinearSpec;
|
||||
class ObjFunctionSummand;
|
||||
class Variable;
|
||||
|
||||
/**
|
||||
* Soft constraint, i.e. one that does not necessarily have to be satisfied.
|
||||
* Use this instead of hard constraints to avoid over-constrained specifications.
|
||||
*/
|
||||
class SoftConstraint : public Constraint {
|
||||
|
||||
public:
|
||||
void ChangeLeftSide(BList* coeffs, BList* vars);
|
||||
OperatorType Op();
|
||||
void SetOp(OperatorType value);
|
||||
double PenaltyNeg();
|
||||
void SetPenaltyNeg(double value);
|
||||
double PenaltyPos();
|
||||
void SetPenaltyPos(double value);
|
||||
//~ string ToString();
|
||||
Variable* DNeg() const;
|
||||
Variable* DPos() const;
|
||||
~SoftConstraint();
|
||||
|
||||
protected:
|
||||
SoftConstraint(LinearSpec* ls, BList* coeffs, BList* vars,
|
||||
OperatorType op, double rightSide,
|
||||
double penaltyNeg, double penaltyPos);
|
||||
|
||||
private:
|
||||
Variable* fDNeg;
|
||||
Variable* fDPos;
|
||||
ObjFunctionSummand* fDNegSummand;
|
||||
ObjFunctionSummand* fDPosSummand;
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::SoftConstraint;
|
||||
|
||||
#endif // SOFT_CONSTRAINT_H
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef VARIABLE_H
|
||||
#define VARIABLE_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace LinearProgramming {
|
||||
|
||||
class Constraint;
|
||||
class LinearSpec;
|
||||
|
||||
/**
|
||||
* Contains minimum and maximum values.
|
||||
*/
|
||||
class Variable {
|
||||
|
||||
public:
|
||||
int32 Index();
|
||||
LinearSpec* LS() const;
|
||||
void SetLS(LinearSpec* value);
|
||||
double Value() const;
|
||||
void SetValue(double value);
|
||||
double Min() const;
|
||||
void SetMin(double min);
|
||||
double Max() const;
|
||||
void SetMax(double max);
|
||||
void SetRange(double min, double max);
|
||||
//~ string ToString();
|
||||
Constraint* IsEqual(Variable* var);
|
||||
Constraint* IsSmallerOrEqual(Variable* var);
|
||||
Constraint* IsGreaterorEqual(Variable* var);
|
||||
|
||||
protected:
|
||||
Variable(LinearSpec* ls);
|
||||
~Variable();
|
||||
|
||||
private:
|
||||
LinearSpec* fLS;
|
||||
double fValue;
|
||||
double fMin;
|
||||
double fMax;
|
||||
|
||||
public:
|
||||
friend class LinearSpec;
|
||||
friend class SoftConstraint;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LinearProgramming
|
||||
|
||||
using LinearProgramming::Variable;
|
||||
|
||||
#endif // VARIABLE_H
|
||||
Reference in New Issue
Block a user