2008-02-25 04:54:05 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
#ifndef LINEAR_SPEC_H
|
|
|
|
#define LINEAR_SPEC_H
|
|
|
|
|
2008-03-11 00:43:32 +03:00
|
|
|
#include "Variable.h"
|
|
|
|
#include "Constraint.h"
|
|
|
|
#include "Summand.h"
|
|
|
|
#include "PenaltyFunction.h"
|
2008-02-06 13:51:44 +03:00
|
|
|
#include "OperatorType.h"
|
|
|
|
#include "ResultType.h"
|
|
|
|
#include "OptimizationType.h"
|
|
|
|
|
|
|
|
#include "lp_lib.h"
|
|
|
|
|
|
|
|
#include <List.h>
|
|
|
|
#include <OS.h>
|
|
|
|
#include <SupportDefs.h>
|
2008-02-25 04:54:05 +03:00
|
|
|
#include <math.h>
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
namespace LinearProgramming {
|
|
|
|
|
|
|
|
class Constraint;
|
|
|
|
class ObjFunctionSummand;
|
|
|
|
class PenaltyFunction;
|
|
|
|
class Variable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specification of a linear programming problem.
|
|
|
|
*/
|
|
|
|
class LinearSpec {
|
|
|
|
|
|
|
|
public:
|
|
|
|
LinearSpec();
|
|
|
|
~LinearSpec();
|
2008-03-11 00:43:32 +03:00
|
|
|
|
2008-02-25 04:54:05 +03:00
|
|
|
Variable* AddVariable();
|
2008-02-06 13:51:44 +03:00
|
|
|
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(BList* summands,
|
2008-02-06 13:51:44 +03:00
|
|
|
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);
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
2008-02-06 13:51:44 +03:00
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3,
|
|
|
|
OperatorType op, double rightSide);
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
2008-02-06 13:51:44 +03:00
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3,
|
|
|
|
double coeff4, Variable* var4,
|
|
|
|
OperatorType op, double rightSide);
|
|
|
|
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(BList* summands,
|
2008-02-06 13:51:44 +03:00
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg, double penaltyPos);
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
2008-02-06 13:51:44 +03:00
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg, double penaltyPos);
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
2008-02-06 13:51:44 +03:00
|
|
|
double coeff2, Variable* var2,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg, double penaltyPos);
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
2008-02-06 13:51:44 +03:00
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg, double penaltyPos);
|
2008-02-25 04:54:05 +03:00
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
2008-02-06 13:51:44 +03:00
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3,
|
|
|
|
double coeff4, Variable* var4,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg, double penaltyPos);
|
|
|
|
|
2008-02-25 04:54:05 +03:00
|
|
|
PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
|
2008-03-11 00:43:32 +03:00
|
|
|
|
|
|
|
BList* ObjFunction();
|
|
|
|
void SetObjFunction(BList* summands);
|
|
|
|
void UpdateObjFunction();
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
ResultType Presolve();
|
2008-03-11 00:43:32 +03:00
|
|
|
void RemovePresolved();
|
2008-02-06 13:51:44 +03:00
|
|
|
ResultType Solve();
|
2008-02-25 04:54:05 +03:00
|
|
|
void Save(char* fname);
|
2008-02-06 13:51:44 +03:00
|
|
|
|
2008-03-11 00:43:32 +03:00
|
|
|
int32 CountColumns() const;
|
2008-02-25 04:54:05 +03:00
|
|
|
OptimizationType Optimization() const;
|
|
|
|
void SetOptimization(OptimizationType value);
|
2008-02-06 13:51:44 +03:00
|
|
|
BList* Variables() const;
|
|
|
|
BList* Constraints() const;
|
|
|
|
ResultType Result() const;
|
|
|
|
double ObjectiveValue() const;
|
|
|
|
double SolvingTime() const;
|
|
|
|
|
|
|
|
protected:
|
2008-03-11 00:43:32 +03:00
|
|
|
int32 fCountColumns;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
lprec* fLpPresolved;
|
2008-02-25 04:54:05 +03:00
|
|
|
OptimizationType fOptimization;
|
2008-02-06 13:51:44 +03:00
|
|
|
lprec* fLP;
|
2008-03-11 00:43:32 +03:00
|
|
|
BList* fObjFunction;
|
2008-02-06 13:51:44 +03:00
|
|
|
BList* fVariables;
|
|
|
|
BList* fConstraints;
|
|
|
|
ResultType fResult;
|
|
|
|
double fObjectiveValue;
|
2008-03-11 00:43:32 +03:00
|
|
|
double fSolvingTime;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
public:
|
2008-02-25 04:54:05 +03:00
|
|
|
friend class Constraint;
|
2008-03-11 00:43:32 +03:00
|
|
|
friend class Variable;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace LinearProgramming
|
|
|
|
|
|
|
|
using LinearProgramming::LinearSpec;
|
|
|
|
|
|
|
|
#endif // LINEAR_SPEC_H
|