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 CONSTRAINT_H
|
|
|
|
#define CONSTRAINT_H
|
|
|
|
|
2010-09-20 08:34:38 +04:00
|
|
|
#include <math.h>
|
2008-02-06 13:51:44 +03:00
|
|
|
|
2009-10-16 16:13:07 +04:00
|
|
|
#include <File.h>
|
2010-09-20 10:09:19 +04:00
|
|
|
#include <ObjectList.h>
|
2008-02-06 13:51:44 +03:00
|
|
|
#include <String.h>
|
|
|
|
#include <SupportDefs.h>
|
2010-09-20 08:34:38 +04:00
|
|
|
|
2010-12-13 22:23:33 +03:00
|
|
|
#include "LinearProgrammingTypes.h"
|
2010-09-20 08:34:38 +04:00
|
|
|
#include "Summand.h"
|
|
|
|
#include "Variable.h"
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
namespace LinearProgramming {
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
class LinearSpec;
|
|
|
|
|
|
|
|
/**
|
2009-12-06 16:14:45 +03:00
|
|
|
* Hard linear constraint, i.e. one that must be satisfied.
|
2008-02-06 13:51:44 +03:00
|
|
|
* May render a specification infeasible.
|
|
|
|
*/
|
|
|
|
class Constraint {
|
|
|
|
public:
|
2010-09-20 08:34:38 +04:00
|
|
|
int32 Index() const;
|
|
|
|
|
2010-09-20 10:09:19 +04:00
|
|
|
SummandList* LeftSide();
|
2011-06-18 05:29:27 +04:00
|
|
|
/*! This just overwrites the current list. The caller has to take
|
|
|
|
care about the old left side, i.e. delete it. */
|
2010-09-20 10:09:19 +04:00
|
|
|
void SetLeftSide(SummandList* summands);
|
2010-11-30 05:08:10 +03:00
|
|
|
|
2010-09-20 08:34:38 +04:00
|
|
|
void SetLeftSide(double coeff1, Variable* var1);
|
|
|
|
void SetLeftSide(double coeff1, Variable* var1,
|
|
|
|
double coeff2, Variable* var2);
|
|
|
|
void SetLeftSide(double coeff1, Variable* var1,
|
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3);
|
|
|
|
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() const;
|
|
|
|
void SetRightSide(double value);
|
|
|
|
double PenaltyNeg() const;
|
|
|
|
void SetPenaltyNeg(double value);
|
|
|
|
double PenaltyPos() const;
|
|
|
|
void SetPenaltyPos(double value);
|
|
|
|
|
|
|
|
const char* Label();
|
|
|
|
void SetLabel(const char* label);
|
|
|
|
|
|
|
|
Variable* DNeg() const;
|
|
|
|
Variable* DPos() const;
|
|
|
|
|
2011-01-25 07:59:40 +03:00
|
|
|
bool IsSoft() const;
|
|
|
|
|
2010-09-20 08:34:38 +04:00
|
|
|
bool IsValid();
|
|
|
|
void Invalidate();
|
|
|
|
|
2011-03-14 03:24:12 +03:00
|
|
|
BString ToString() const;
|
2011-01-25 07:59:40 +03:00
|
|
|
void PrintToStream();
|
2010-09-20 08:34:38 +04:00
|
|
|
|
|
|
|
~Constraint();
|
2008-02-25 04:54:05 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
protected:
|
2010-09-20 10:09:19 +04:00
|
|
|
Constraint(LinearSpec* ls,
|
|
|
|
SummandList* summands, OperatorType op,
|
2011-01-25 07:59:40 +03:00
|
|
|
double rightSide,
|
|
|
|
double penaltyNeg = -1,
|
|
|
|
double penaltyPos = -1);
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
private:
|
2010-09-20 08:34:38 +04:00
|
|
|
LinearSpec* fLS;
|
2010-09-20 10:09:19 +04:00
|
|
|
SummandList* fLeftSide;
|
2010-09-20 08:34:38 +04:00
|
|
|
OperatorType fOp;
|
|
|
|
double fRightSide;
|
2010-11-30 05:08:10 +03:00
|
|
|
|
|
|
|
double fPenaltyNeg;
|
|
|
|
double fPenaltyPos;
|
2010-09-20 08:34:38 +04:00
|
|
|
Summand* fDNegObjSummand;
|
|
|
|
Summand* fDPosObjSummand;
|
|
|
|
BString fLabel;
|
|
|
|
|
|
|
|
bool fIsValid;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
public:
|
2008-02-25 04:54:05 +03:00
|
|
|
friend class LinearSpec;
|
2011-01-25 07:59:40 +03:00
|
|
|
friend class LPSolveInterface;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-09-20 10:09:19 +04:00
|
|
|
|
|
|
|
typedef BObjectList<Constraint> ConstraintList;
|
|
|
|
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
} // namespace LinearProgramming
|
|
|
|
|
|
|
|
using LinearProgramming::Constraint;
|
2010-09-20 10:26:32 +04:00
|
|
|
using LinearProgramming::ConstraintList;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
#endif // CONSTRAINT_H
|
2008-03-11 00:43:32 +03:00
|
|
|
|