Clean up.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38737 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,19 +3,19 @@
|
|||||||
* Copyright 2007-2008, James Kim, [email protected]
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CONSTRAINT_H
|
#ifndef CONSTRAINT_H
|
||||||
#define CONSTRAINT_H
|
#define CONSTRAINT_H
|
||||||
|
|
||||||
#include "OperatorType.h"
|
#include <math.h>
|
||||||
#include "Variable.h"
|
|
||||||
#include "Summand.h"
|
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <math.h>
|
|
||||||
|
#include "OperatorType.h"
|
||||||
|
#include "Summand.h"
|
||||||
|
#include "Variable.h"
|
||||||
|
|
||||||
|
|
||||||
namespace LinearProgramming {
|
namespace LinearProgramming {
|
||||||
@@ -29,66 +29,66 @@ class LinearSpec;
|
|||||||
class Constraint {
|
class Constraint {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int32 Index() const;
|
int32 Index() const;
|
||||||
|
|
||||||
BList* LeftSide();
|
BList* LeftSide();
|
||||||
void SetLeftSide(BList* summands);
|
void SetLeftSide(BList* summands);
|
||||||
void UpdateLeftSide();
|
void UpdateLeftSide();
|
||||||
void SetLeftSide(double coeff1, Variable* var1);
|
void SetLeftSide(double coeff1, Variable* var1);
|
||||||
void SetLeftSide(double coeff1, Variable* var1,
|
void SetLeftSide(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2);
|
double coeff2, Variable* var2);
|
||||||
void SetLeftSide(double coeff1, Variable* var1,
|
void SetLeftSide(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
double coeff3, Variable* var3);
|
double coeff3, Variable* var3);
|
||||||
void SetLeftSide(double coeff1, Variable* var1,
|
void SetLeftSide(double coeff1, Variable* var1,
|
||||||
double coeff2, Variable* var2,
|
double coeff2, Variable* var2,
|
||||||
double coeff3, Variable* var3,
|
double coeff3, Variable* var3,
|
||||||
double coeff4, Variable* var4);
|
double coeff4, Variable* var4);
|
||||||
|
|
||||||
OperatorType Op();
|
OperatorType Op();
|
||||||
void SetOp(OperatorType value);
|
void SetOp(OperatorType value);
|
||||||
double RightSide() const;
|
double RightSide() const;
|
||||||
void SetRightSide(double value);
|
void SetRightSide(double value);
|
||||||
double PenaltyNeg() const;
|
double PenaltyNeg() const;
|
||||||
void SetPenaltyNeg(double value);
|
void SetPenaltyNeg(double value);
|
||||||
double PenaltyPos() const;
|
double PenaltyPos() const;
|
||||||
void SetPenaltyPos(double value);
|
void SetPenaltyPos(double value);
|
||||||
|
|
||||||
const char* Label();
|
const char* Label();
|
||||||
void SetLabel(const char* label);
|
void SetLabel(const char* label);
|
||||||
|
|
||||||
void WriteXML(BFile* file);
|
void WriteXML(BFile* file);
|
||||||
|
|
||||||
Variable* DNeg() const;
|
Variable* DNeg() const;
|
||||||
Variable* DPos() const;
|
Variable* DPos() const;
|
||||||
|
|
||||||
void SetOwner(void* owner);
|
void SetOwner(void* owner);
|
||||||
void* Owner() const;
|
void* Owner() const;
|
||||||
|
|
||||||
bool IsValid();
|
bool IsValid();
|
||||||
void Invalidate();
|
void Invalidate();
|
||||||
|
|
||||||
operator BString() const;
|
operator BString() const;
|
||||||
void GetString(BString& string) const;
|
void GetString(BString& string) const;
|
||||||
|
|
||||||
~Constraint();
|
~Constraint();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Constraint(LinearSpec* ls, BList* summands,
|
Constraint(LinearSpec* ls, BList* summands,
|
||||||
OperatorType op, double rightSide,
|
OperatorType op, double rightSide,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinearSpec* fLS;
|
LinearSpec* fLS;
|
||||||
BList* fLeftSide;
|
BList* fLeftSide;
|
||||||
OperatorType fOp;
|
OperatorType fOp;
|
||||||
double fRightSide;
|
double fRightSide;
|
||||||
Summand* fDNegObjSummand;
|
Summand* fDNegObjSummand;
|
||||||
Summand* fDPosObjSummand;
|
Summand* fDPosObjSummand;
|
||||||
void* fOwner;
|
void* fOwner;
|
||||||
char* fLabel;
|
BString fLabel;
|
||||||
|
|
||||||
bool fIsValid;
|
bool fIsValid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class LinearSpec;
|
friend class LinearSpec;
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Copyright 2007-2008, James Kim, [email protected]
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef VARIABLE_H
|
#ifndef VARIABLE_H
|
||||||
#define VARIABLE_H
|
#define VARIABLE_H
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <SupportDefs.h>
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
namespace LinearProgramming {
|
namespace LinearProgramming {
|
||||||
@@ -22,52 +22,52 @@ class Summand;
|
|||||||
* Contains minimum and maximum values.
|
* Contains minimum and maximum values.
|
||||||
*/
|
*/
|
||||||
class Variable {
|
class Variable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int32 Index() const;
|
int32 Index() const;
|
||||||
LinearSpec* LS() const;
|
LinearSpec* LS() const;
|
||||||
double Value() const;
|
double Value() const;
|
||||||
void SetValue(double value);
|
void SetValue(double value);
|
||||||
double Min() const;
|
double Min() const;
|
||||||
void SetMin(double min);
|
void SetMin(double min);
|
||||||
double Max() const;
|
double Max() const;
|
||||||
void SetMax(double max);
|
void SetMax(double max);
|
||||||
void SetRange(double min, double max);
|
void SetRange(double min, double max);
|
||||||
|
|
||||||
const char* Label();
|
const char* Label();
|
||||||
void SetLabel(const char* label);
|
void SetLabel(const char* label);
|
||||||
|
|
||||||
operator BString() const;
|
operator BString() const;
|
||||||
void GetString(BString& string) const;
|
void GetString(BString& string) const;
|
||||||
|
|
||||||
Constraint* IsEqual(Variable* var);
|
Constraint* IsEqual(Variable* var);
|
||||||
Constraint* IsSmallerOrEqual(Variable* var);
|
Constraint* IsSmallerOrEqual(Variable* var);
|
||||||
Constraint* IsGreaterOrEqual(Variable* var);
|
Constraint* IsGreaterOrEqual(Variable* var);
|
||||||
|
|
||||||
Constraint* IsEqual(Variable* var,
|
Constraint* IsEqual(Variable* var,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
Constraint* IsSmallerOrEqual(Variable* var,
|
Constraint* IsSmallerOrEqual(Variable* var,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
Constraint* IsGreaterOrEqual(Variable* var,
|
Constraint* IsGreaterOrEqual(Variable* var,
|
||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
|
|
||||||
bool IsValid();
|
bool IsValid();
|
||||||
void Invalidate();
|
void Invalidate();
|
||||||
|
|
||||||
virtual ~Variable();
|
virtual ~Variable();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Variable(LinearSpec* ls);
|
Variable(LinearSpec* ls);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinearSpec* fLS;
|
LinearSpec* fLS;
|
||||||
BList* fUsingSummands; // All Summands that link to this Variable
|
BList* fUsingSummands;
|
||||||
double fValue;
|
// All Summands that link to this Variable
|
||||||
double fMin;
|
double fValue;
|
||||||
double fMax;
|
double fMin;
|
||||||
char* fLabel;
|
double fMax;
|
||||||
|
BString fLabel;
|
||||||
|
|
||||||
bool fIsValid;
|
bool fIsValid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class LinearSpec;
|
friend class LinearSpec;
|
||||||
|
|||||||
@@ -325,15 +325,14 @@ Constraint::SetPenaltyPos(double value)
|
|||||||
const char*
|
const char*
|
||||||
Constraint::Label()
|
Constraint::Label()
|
||||||
{
|
{
|
||||||
return fLabel;
|
return fLabel.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Constraint::SetLabel(const char* label)
|
Constraint::SetLabel(const char* label)
|
||||||
{
|
{
|
||||||
fLabel = (char*) malloc(strlen(label) + 1);
|
fLabel = label;
|
||||||
strcpy(fLabel, label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -471,8 +470,7 @@ void
|
|||||||
Constraint::GetString(BString& string) const
|
Constraint::GetString(BString& string) const
|
||||||
{
|
{
|
||||||
string << "Constraint ";
|
string << "Constraint ";
|
||||||
if (fLabel)
|
string << fLabel;
|
||||||
string << fLabel;
|
|
||||||
string << "(" << (int32)this << "): ";
|
string << "(" << (int32)this << "): ";
|
||||||
|
|
||||||
if (fIsValid) {
|
if (fIsValid) {
|
||||||
@@ -504,7 +502,6 @@ Constraint::Constraint(LinearSpec* ls, BList* summands, OperatorType op,
|
|||||||
fOp(op),
|
fOp(op),
|
||||||
fRightSide(rightSide),
|
fRightSide(rightSide),
|
||||||
fOwner(NULL),
|
fOwner(NULL),
|
||||||
fLabel(NULL),
|
|
||||||
fIsValid(true)
|
fIsValid(true)
|
||||||
{
|
{
|
||||||
double coeffs[summands->CountItems() + 2];
|
double coeffs[summands->CountItems() + 2];
|
||||||
|
|||||||
@@ -154,15 +154,14 @@ Variable::SetRange(double min, double max)
|
|||||||
const char*
|
const char*
|
||||||
Variable::Label()
|
Variable::Label()
|
||||||
{
|
{
|
||||||
return fLabel;
|
return fLabel.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Variable::SetLabel(const char* label)
|
Variable::SetLabel(const char* label)
|
||||||
{
|
{
|
||||||
fLabel = (char*) malloc(strlen(label) + 1);
|
fLabel = label;
|
||||||
strcpy(fLabel, label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -298,7 +297,7 @@ Variable::Invalidate()
|
|||||||
fLS->Variables()->RemoveItem(this);
|
fLS->Variables()->RemoveItem(this);
|
||||||
|
|
||||||
// invalidate all constraints that use this variable
|
// invalidate all constraints that use this variable
|
||||||
BList* markedForInvalidation = new BList();
|
BList markedForInvalidation;
|
||||||
BList* constraints = fLS->Constraints();
|
BList* constraints = fLS->Constraints();
|
||||||
for (int i = 0; i < constraints->CountItems(); i++) {
|
for (int i = 0; i < constraints->CountItems(); i++) {
|
||||||
Constraint* constraint = static_cast<Constraint*>(
|
Constraint* constraint = static_cast<Constraint*>(
|
||||||
@@ -311,15 +310,14 @@ Variable::Invalidate()
|
|||||||
for (int j = 0; j < summands->CountItems(); j++) {
|
for (int j = 0; j < summands->CountItems(); j++) {
|
||||||
Summand* summand = static_cast<Summand*>(summands->ItemAt(j));
|
Summand* summand = static_cast<Summand*>(summands->ItemAt(j));
|
||||||
if (summand->Var() == this) {
|
if (summand->Var() == this) {
|
||||||
markedForInvalidation->AddItem(constraint);
|
markedForInvalidation.AddItem(constraint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < markedForInvalidation->CountItems(); i++)
|
for (int i = 0; i < markedForInvalidation.CountItems(); i++)
|
||||||
static_cast<Constraint*>(markedForInvalidation->ItemAt(i))
|
static_cast<Constraint*>(markedForInvalidation.ItemAt(i))
|
||||||
->Invalidate();
|
->Invalidate();
|
||||||
delete markedForInvalidation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -355,7 +353,6 @@ Variable::Variable(LinearSpec* ls)
|
|||||||
Variable::~Variable()
|
Variable::~Variable()
|
||||||
{
|
{
|
||||||
Invalidate();
|
Invalidate();
|
||||||
free(fLabel);
|
|
||||||
delete fUsingSummands;
|
delete fUsingSummands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user