mirror of
https://review.haiku-os.org/haiku
synced 2025-01-30 18:24:53 +01:00
0306945545
* copyright headers for the files of the libraries linprog and alm * new class Summand for representing summands in a linear constraint * merged class SoftConstraint into class Constraint; Constraint now supports both soft and hard constraint functionality * new AddConstraint methods in class LinearSpec for directly setting constraints with 1 to 4 summands * code cleanups by using aforementioned AddConstraint methods * a new very simple test application for alm * some style corrections git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24108 a95241bf-73f2-0310-859d-f6bbb57e9c96
131 lines
3.8 KiB
C++
131 lines
3.8 KiB
C++
/*
|
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
#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>
|
|
#include <math.h>
|
|
|
|
|
|
namespace LinearProgramming {
|
|
|
|
class Constraint;
|
|
class ObjFunctionSummand;
|
|
class PenaltyFunction;
|
|
class Variable;
|
|
|
|
/**
|
|
* Specification of a linear programming problem.
|
|
*/
|
|
class LinearSpec {
|
|
|
|
public:
|
|
LinearSpec();
|
|
~LinearSpec();
|
|
void UpdateObjFunction();
|
|
void SetObjFunction(BList* summands);
|
|
ObjFunctionSummand* AddObjFunctionSummand(double coeff, Variable* var);
|
|
Variable* AddVariable();
|
|
|
|
Constraint* AddConstraint(BList* summands,
|
|
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);
|
|
|
|
Constraint* AddConstraint(BList* summands,
|
|
OperatorType op, double rightSide,
|
|
double penaltyNeg, double penaltyPos);
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
OperatorType op, double rightSide,
|
|
double penaltyNeg, double penaltyPos);
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
double coeff2, Variable* var2,
|
|
OperatorType op, double rightSide,
|
|
double penaltyNeg, double penaltyPos);
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
double coeff2, Variable* var2,
|
|
double coeff3, Variable* var3,
|
|
OperatorType op, double rightSide,
|
|
double penaltyNeg, double penaltyPos);
|
|
Constraint* AddConstraint(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 Constraint;
|
|
|
|
};
|
|
|
|
} // namespace LinearProgramming
|
|
|
|
using LinearProgramming::LinearSpec;
|
|
|
|
#endif // LINEAR_SPEC_H
|