Make kp_solve interface work again.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40384 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
#include "Tab.h"
|
#include "Tab.h"
|
||||||
|
|
||||||
|
|
||||||
#define USE_SCALE_VARIABLE 1
|
#define USE_SCALE_VARIABLE 0
|
||||||
|
|
||||||
|
|
||||||
class Constraint;
|
class Constraint;
|
||||||
@@ -131,7 +131,7 @@ private:
|
|||||||
BSize& preferred);
|
BSize& preferred);
|
||||||
void _UpdatePreferredHeightConstraint(
|
void _UpdatePreferredHeightConstraint(
|
||||||
BSize& preferred);
|
BSize& preferred);
|
||||||
|
void _SetupPreferredConstraints();
|
||||||
private:
|
private:
|
||||||
BLayoutItem* fLayoutItem;
|
BLayoutItem* fLayoutItem;
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public:
|
|||||||
bool RemoveVariable(Variable* variable,
|
bool RemoveVariable(Variable* variable,
|
||||||
bool deleteVariable = true);
|
bool deleteVariable = true);
|
||||||
int32 IndexOf(const Variable* variable) const;
|
int32 IndexOf(const Variable* variable) const;
|
||||||
|
int32 GlobalIndexOf(const Variable* variable) const;
|
||||||
bool UpdateRange(Variable* variable);
|
bool UpdateRange(Variable* variable);
|
||||||
|
|
||||||
bool AddConstraint(Constraint* constraint);
|
bool AddConstraint(Constraint* constraint);
|
||||||
@@ -132,7 +133,8 @@ public:
|
|||||||
void GetString(BString& string) const;
|
void GetString(BString& string) const;
|
||||||
|
|
||||||
const ConstraintList& Constraints() const;
|
const ConstraintList& Constraints() const;
|
||||||
const VariableList& Variables() const;
|
const VariableList& UsedVariables() const;
|
||||||
|
const VariableList& AllVariables() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Constraint;
|
friend class Constraint;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Summand;
|
|||||||
class Variable {
|
class Variable {
|
||||||
public:
|
public:
|
||||||
int32 Index() const;
|
int32 Index() const;
|
||||||
|
int32 GlobalIndex() const;
|
||||||
LinearSpec* LS() const;
|
LinearSpec* LS() const;
|
||||||
double Value() const;
|
double Value() const;
|
||||||
void SetValue(double value);
|
void SetValue(double value);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ LPSolveInterface::~LPSolveInterface()
|
|||||||
ResultType
|
ResultType
|
||||||
LPSolveInterface::Solve()
|
LPSolveInterface::Solve()
|
||||||
{
|
{
|
||||||
const VariableList& variables = fLinearSpec->Variables();
|
const VariableList& variables = fLinearSpec->AllVariables();
|
||||||
if (fLpPresolved != NULL)
|
if (fLpPresolved != NULL)
|
||||||
return _Presolve(variables);
|
return _Presolve(variables);
|
||||||
|
|
||||||
@@ -69,6 +69,7 @@ LPSolveInterface::Solve()
|
|||||||
|
|
||||||
for (int32 i = 0; i < size; i++)
|
for (int32 i = 0; i < size; i++)
|
||||||
variables.ItemAt(i)->SetValue(x[i]);
|
variables.ItemAt(i)->SetValue(x[i]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else if (result == kInfeasible)
|
} else if (result == kInfeasible)
|
||||||
break;
|
break;
|
||||||
@@ -93,7 +94,7 @@ LPSolveInterface::VariableAdded(Variable* variable)
|
|||||||
bool
|
bool
|
||||||
LPSolveInterface::VariableRemoved(Variable* variable)
|
LPSolveInterface::VariableRemoved(Variable* variable)
|
||||||
{
|
{
|
||||||
if (!del_column(fLP, variable->Index() + 1))
|
if (!del_column(fLP, variable->GlobalIndex() + 1))
|
||||||
return false;
|
return false;
|
||||||
_RemovePresolved();
|
_RemovePresolved();
|
||||||
return true;
|
return true;
|
||||||
@@ -105,7 +106,7 @@ LPSolveInterface::VariableRangeChanged(Variable* variable)
|
|||||||
{
|
{
|
||||||
double min = variable->Min();
|
double min = variable->Min();
|
||||||
double max = variable->Max();
|
double max = variable->Max();
|
||||||
if (!set_bounds(fLP, variable->Index() + 1, min, max))
|
if (!set_bounds(fLP, variable->GlobalIndex() + 1, min, max))
|
||||||
return false;
|
return false;
|
||||||
_RemovePresolved();
|
_RemovePresolved();
|
||||||
return true;
|
return true;
|
||||||
@@ -124,7 +125,7 @@ LPSolveInterface::ConstraintAdded(Constraint* constraint)
|
|||||||
for (; nCoefficient < summands->CountItems(); nCoefficient++) {
|
for (; nCoefficient < summands->CountItems(); nCoefficient++) {
|
||||||
Summand* s = summands->ItemAt(nCoefficient);
|
Summand* s = summands->ItemAt(nCoefficient);
|
||||||
coeffs[nCoefficient] = s->Coeff();
|
coeffs[nCoefficient] = s->Coeff();
|
||||||
variableIndices[nCoefficient] = s->Var()->Index() + 1;
|
variableIndices[nCoefficient] = s->Var()->GlobalIndex() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double penaltyNeg = constraint->PenaltyNeg();
|
double penaltyNeg = constraint->PenaltyNeg();
|
||||||
@@ -133,7 +134,7 @@ LPSolveInterface::ConstraintAdded(Constraint* constraint)
|
|||||||
constraint->PenaltyNeg(), fLinearSpec->AddVariable());
|
constraint->PenaltyNeg(), fLinearSpec->AddVariable());
|
||||||
fObjFunction->AddItem(constraint->fDNegObjSummand);
|
fObjFunction->AddItem(constraint->fDNegObjSummand);
|
||||||
variableIndices[nCoefficient]
|
variableIndices[nCoefficient]
|
||||||
= constraint->fDNegObjSummand->Var()->Index() + 1;
|
= constraint->fDNegObjSummand->Var()->GlobalIndex() + 1;
|
||||||
coeffs[nCoefficient] = 1.0;
|
coeffs[nCoefficient] = 1.0;
|
||||||
nCoefficient++;
|
nCoefficient++;
|
||||||
}
|
}
|
||||||
@@ -144,7 +145,7 @@ LPSolveInterface::ConstraintAdded(Constraint* constraint)
|
|||||||
constraint->PenaltyPos(), fLinearSpec->AddVariable());
|
constraint->PenaltyPos(), fLinearSpec->AddVariable());
|
||||||
fObjFunction->AddItem(constraint->fDPosObjSummand);
|
fObjFunction->AddItem(constraint->fDPosObjSummand);
|
||||||
variableIndices[nCoefficient]
|
variableIndices[nCoefficient]
|
||||||
= constraint->fDPosObjSummand->Var()->Index() + 1;
|
= constraint->fDPosObjSummand->Var()->GlobalIndex() + 1;
|
||||||
coeffs[nCoefficient] = -1.0;
|
coeffs[nCoefficient] = -1.0;
|
||||||
nCoefficient++;
|
nCoefficient++;
|
||||||
}
|
}
|
||||||
@@ -204,7 +205,7 @@ LPSolveInterface::LeftSideChanged(Constraint* constraint)
|
|||||||
for (i = 0; i < leftSide->CountItems(); i++) {
|
for (i = 0; i < leftSide->CountItems(); i++) {
|
||||||
Summand* s = leftSide->ItemAt(i);
|
Summand* s = leftSide->ItemAt(i);
|
||||||
coeffs[i] = s->Coeff();
|
coeffs[i] = s->Coeff();
|
||||||
variableIndices[i] = s->Var()->Index() + 1;
|
variableIndices[i] = s->Var()->GlobalIndex() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double penaltyNeg = constraint->PenaltyNeg();
|
double penaltyNeg = constraint->PenaltyNeg();
|
||||||
@@ -214,7 +215,7 @@ LPSolveInterface::LeftSideChanged(Constraint* constraint)
|
|||||||
constraint->PenaltyNeg(), fLinearSpec->AddVariable());
|
constraint->PenaltyNeg(), fLinearSpec->AddVariable());
|
||||||
fObjFunction->AddItem(constraint->fDNegObjSummand);
|
fObjFunction->AddItem(constraint->fDNegObjSummand);
|
||||||
}
|
}
|
||||||
variableIndices[i] = constraint->fDNegObjSummand->Var()->Index() + 1;
|
variableIndices[i] = constraint->fDNegObjSummand->Var()->GlobalIndex() + 1;
|
||||||
coeffs[i] = 1.0;
|
coeffs[i] = 1.0;
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
@@ -230,7 +231,7 @@ LPSolveInterface::LeftSideChanged(Constraint* constraint)
|
|||||||
fLinearSpec->AddVariable());
|
fLinearSpec->AddVariable());
|
||||||
fObjFunction->AddItem(constraint->fDPosObjSummand);
|
fObjFunction->AddItem(constraint->fDPosObjSummand);
|
||||||
}
|
}
|
||||||
variableIndices[i] = constraint->fDPosObjSummand->Var()->Index() + 1;
|
variableIndices[i] = constraint->fDPosObjSummand->Var()->GlobalIndex() + 1;
|
||||||
coeffs[i] = -1.0;
|
coeffs[i] = -1.0;
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
@@ -425,7 +426,7 @@ LPSolveInterface::_UpdateObjectiveFunction()
|
|||||||
for (int32 i = 0; i < size; i++) {
|
for (int32 i = 0; i < size; i++) {
|
||||||
current = (Summand*)fObjFunction->ItemAt(i);
|
current = (Summand*)fObjFunction->ItemAt(i);
|
||||||
coeffs[i] = current->Coeff();
|
coeffs[i] = current->Coeff();
|
||||||
varIndexes[i] = current->Var()->Index() + 1;
|
varIndexes[i] = current->Var()->GlobalIndex() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetObjectiveFunction(size, &coeffs[0], &varIndexes[0]))
|
if (!SetObjectiveFunction(size, &coeffs[0], &varIndexes[0]))
|
||||||
@@ -472,7 +473,7 @@ LPSolveInterface::_Presolve(const VariableList& variables)
|
|||||||
for (int32 i = 0; i < size; i++) {
|
for (int32 i = 0; i < size; i++) {
|
||||||
Variable* current = variables.ItemAt(i);
|
Variable* current = variables.ItemAt(i);
|
||||||
current->SetValue(get_var_primalresult(fLpPresolved,
|
current->SetValue(get_var_primalresult(fLpPresolved,
|
||||||
get_Norig_rows(fLpPresolved) + current->Index() + 1));
|
get_Norig_rows(fLpPresolved) + current->GlobalIndex() + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,17 +94,17 @@ LinearSpec::AddVariable(Variable* variable)
|
|||||||
|
|
||||||
if (!fVariables.AddItem(variable))
|
if (!fVariables.AddItem(variable))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!fSolver->VariableAdded(variable)) {
|
if (!fSolver->VariableAdded(variable)) {
|
||||||
fVariables.RemoveItem(variable);
|
fVariables.RemoveItem(variable);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
variable->fIsValid = true;
|
||||||
|
|
||||||
if (!UpdateRange(variable)) {
|
if (!UpdateRange(variable)) {
|
||||||
RemoveVariable(variable, false);
|
RemoveVariable(variable, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
variable->fIsValid = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +153,13 @@ LinearSpec::IndexOf(const Variable* variable) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
LinearSpec::GlobalIndexOf(const Variable* variable) const
|
||||||
|
{
|
||||||
|
return fVariables.IndexOf(variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LinearSpec::UpdateRange(Variable* variable)
|
LinearSpec::UpdateRange(Variable* variable)
|
||||||
{
|
{
|
||||||
@@ -574,12 +581,19 @@ LinearSpec::Constraints() const
|
|||||||
|
|
||||||
|
|
||||||
const VariableList&
|
const VariableList&
|
||||||
LinearSpec::Variables() const
|
LinearSpec::UsedVariables() const
|
||||||
{
|
{
|
||||||
return fUsedVariables;
|
return fUsedVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const VariableList&
|
||||||
|
LinearSpec::AllVariables() const
|
||||||
|
{
|
||||||
|
return fVariables;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the result type.
|
* Gets the result type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ Variable::Index() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
Variable::GlobalIndex() const
|
||||||
|
{
|
||||||
|
return fLS->GlobalIndexOf(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current linear specification.
|
* Gets the current linear specification.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user