Some clean up.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39643 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler 2010-11-26 04:23:52 +00:00
parent 81c40be9fc
commit 5cfaa5ee78
2 changed files with 21 additions and 19 deletions

View File

@ -491,39 +491,36 @@ Constraint::Constraint(LinearSpec* ls, SummandList* summands, OperatorType op,
{ {
double coeffs[summands->CountItems() + 2]; double coeffs[summands->CountItems() + 2];
int varIndexes[summands->CountItems() + 2]; int varIndexes[summands->CountItems() + 2];
int32 i; int32 nCoefficient = 0;
for (i = 0; i < summands->CountItems(); i++) { for (; nCoefficient < summands->CountItems(); nCoefficient++) {
Summand* s = summands->ItemAt(i); Summand* s = summands->ItemAt(nCoefficient);
coeffs[i] = s->Coeff(); coeffs[nCoefficient] = s->Coeff();
varIndexes[i] = s->Var()->Index(); varIndexes[nCoefficient] = s->Var()->Index();
} }
if (penaltyNeg != INFINITY if (penaltyNeg != INFINITY && penaltyNeg != 0. && fOp != OperatorType(LE)) {
&& fOp != OperatorType(LE)) {
fDNegObjSummand = new Summand(penaltyNeg, ls->AddVariable()); fDNegObjSummand = new Summand(penaltyNeg, ls->AddVariable());
fLS->fObjFunction->AddItem(fDNegObjSummand); fLS->fObjFunction->AddItem(fDNegObjSummand);
varIndexes[i] = fDNegObjSummand->Var()->Index(); varIndexes[nCoefficient] = fDNegObjSummand->Var()->Index();
coeffs[i] = 1.0; coeffs[nCoefficient] = 1.0;
i++; nCoefficient++;
} }
else else
fDNegObjSummand = NULL; fDNegObjSummand = NULL;
if (penaltyPos != INFINITY if (penaltyPos != INFINITY && penaltyPos != 0. && fOp != OperatorType(GE)) {
&& fOp != OperatorType(GE)) {
fDPosObjSummand = new Summand(penaltyPos, ls->AddVariable()); fDPosObjSummand = new Summand(penaltyPos, ls->AddVariable());
fLS->fObjFunction->AddItem(fDPosObjSummand); fLS->fObjFunction->AddItem(fDPosObjSummand);
varIndexes[i] = fDPosObjSummand->Var()->Index(); varIndexes[nCoefficient] = fDPosObjSummand->Var()->Index();
coeffs[i] = -1.0; coeffs[nCoefficient] = -1.0;
i++; nCoefficient++;
} }
else else
fDPosObjSummand = NULL; fDPosObjSummand = NULL;
if (!add_constraintex(fLS->fLP, i, &coeffs[0], &varIndexes[0], if (!add_constraintex(fLS->fLP, nCoefficient, &coeffs[0], &varIndexes[0],
((fOp == OperatorType(EQ)) ? EQ (fOp == OperatorType(EQ) ? EQ : (fOp == OperatorType(GE)) ? GE
: (fOp == OperatorType(GE)) ? GE : LE), rightSide))
: LE), rightSide))
STRACE(("Error in add_constraintex.")); STRACE(("Error in add_constraintex."));
fLS->UpdateObjectiveFunction(); fLS->UpdateObjectiveFunction();

View File

@ -25,6 +25,11 @@ LinearSpec::LinearSpec()
fLP = make_lp(0, 0); fLP = make_lp(0, 0);
if (fLP == NULL) if (fLP == NULL)
printf("Couldn't construct a new model."); printf("Couldn't construct a new model.");
// minimize the objective functions, this is the default of lp_solve so we
// don't have to do it here:
// set_minim(fLP);
set_verbose(fLP, 1); set_verbose(fLP, 1);
} }