Fix min/ max calculation by removing all soft constraints before doing so. Smaller fixes.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40297 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -148,6 +148,7 @@ private:
|
|||||||
double penaltyNeg, double penaltyPos);
|
double penaltyNeg, double penaltyPos);
|
||||||
|
|
||||||
VariableList fVariables;
|
VariableList fVariables;
|
||||||
|
VariableList fUsedVariables;
|
||||||
ConstraintList fConstraints;
|
ConstraintList fConstraints;
|
||||||
ResultType fResult;
|
ResultType fResult;
|
||||||
bigtime_t fSolvingTime;
|
bigtime_t fSolvingTime;
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
Variable(LinearSpec* ls);
|
Variable(LinearSpec* ls);
|
||||||
|
|
||||||
|
//! returns the ref count
|
||||||
|
int32 AddReference();
|
||||||
|
int32 RemoveReference();
|
||||||
private:
|
private:
|
||||||
LinearSpec* fLS;
|
LinearSpec* fLS;
|
||||||
|
|
||||||
@@ -68,6 +71,7 @@ private:
|
|||||||
|
|
||||||
bool fIsValid;
|
bool fIsValid;
|
||||||
|
|
||||||
|
int32 fReferenceCount;
|
||||||
public:
|
public:
|
||||||
friend class LinearSpec;
|
friend class LinearSpec;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -635,15 +635,16 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom)
|
|||||||
fScaleHeight, kEQ, 0, fShrinkPenalties.Height(),
|
fScaleHeight, kEQ, 0, fShrinkPenalties.Height(),
|
||||||
fGrowPenalties.Height());
|
fGrowPenalties.Height());
|
||||||
#else
|
#else
|
||||||
BSize preferredSize = fLayoutItem->PreferredSize();
|
|
||||||
fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, kEQ,
|
fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, kEQ,
|
||||||
0, fShrinkPenalties.Width(), fGrowPenalties.Width());
|
0, fShrinkPenalties.Width(), fGrowPenalties.Width());
|
||||||
_UpdatePreferredWidthConstraint(preferredSize);
|
|
||||||
fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, kEQ,
|
fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, kEQ,
|
||||||
0, fShrinkPenalties.Height(), fGrowPenalties.Height());
|
0, fShrinkPenalties.Height(), fGrowPenalties.Height());
|
||||||
_UpdatePreferredHeightConstraint(preferredSize);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
BSize preferredSize = fLayoutItem->PreferredSize();
|
||||||
|
_UpdatePreferredWidthConstraint(preferredSize);
|
||||||
|
_UpdatePreferredHeightConstraint(preferredSize);
|
||||||
|
|
||||||
fConstraints.AddItem(fPreferredContentWidth);
|
fConstraints.AddItem(fPreferredContentWidth);
|
||||||
fConstraints.AddItem(fPreferredContentHeight);
|
fConstraints.AddItem(fPreferredContentHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -504,6 +504,9 @@ ActiveSetSolver::SaveModel(const char* fileName)
|
|||||||
BSize
|
BSize
|
||||||
ActiveSetSolver::MinSize(Variable* width, Variable* height)
|
ActiveSetSolver::MinSize(Variable* width, Variable* height)
|
||||||
{
|
{
|
||||||
|
ConstraintList softConstraints;
|
||||||
|
_RemoveSoftConstraint(softConstraints);
|
||||||
|
|
||||||
Constraint* heightConstraint = fLinearSpec->AddConstraint(1, height,
|
Constraint* heightConstraint = fLinearSpec->AddConstraint(1, height,
|
||||||
kEQ, 0, 5, 5);
|
kEQ, 0, 5, 5);
|
||||||
Constraint* widthConstraint = fLinearSpec->AddConstraint(1, width,
|
Constraint* widthConstraint = fLinearSpec->AddConstraint(1, width,
|
||||||
@@ -512,6 +515,8 @@ ActiveSetSolver::MinSize(Variable* width, Variable* height)
|
|||||||
fLinearSpec->RemoveConstraint(heightConstraint);
|
fLinearSpec->RemoveConstraint(heightConstraint);
|
||||||
fLinearSpec->RemoveConstraint(widthConstraint);
|
fLinearSpec->RemoveConstraint(widthConstraint);
|
||||||
|
|
||||||
|
_AddSoftConstraint(softConstraints);
|
||||||
|
|
||||||
if (result == kUnbounded)
|
if (result == kUnbounded)
|
||||||
return kMinSize;
|
return kMinSize;
|
||||||
if (result != kOptimal)
|
if (result != kOptimal)
|
||||||
@@ -524,6 +529,9 @@ ActiveSetSolver::MinSize(Variable* width, Variable* height)
|
|||||||
BSize
|
BSize
|
||||||
ActiveSetSolver::MaxSize(Variable* width, Variable* height)
|
ActiveSetSolver::MaxSize(Variable* width, Variable* height)
|
||||||
{
|
{
|
||||||
|
ConstraintList softConstraints;
|
||||||
|
_RemoveSoftConstraint(softConstraints);
|
||||||
|
|
||||||
const double kHugeValue = 32000;
|
const double kHugeValue = 32000;
|
||||||
Constraint* heightConstraint = fLinearSpec->AddConstraint(1, height,
|
Constraint* heightConstraint = fLinearSpec->AddConstraint(1, height,
|
||||||
kEQ, kHugeValue, 5, 5);
|
kEQ, kHugeValue, 5, 5);
|
||||||
@@ -533,10 +541,40 @@ ActiveSetSolver::MaxSize(Variable* width, Variable* height)
|
|||||||
fLinearSpec->RemoveConstraint(heightConstraint);
|
fLinearSpec->RemoveConstraint(heightConstraint);
|
||||||
fLinearSpec->RemoveConstraint(widthConstraint);
|
fLinearSpec->RemoveConstraint(widthConstraint);
|
||||||
|
|
||||||
|
_AddSoftConstraint(softConstraints);
|
||||||
|
|
||||||
if (result == kUnbounded)
|
if (result == kUnbounded)
|
||||||
return kMinSize;
|
return kMaxSize;
|
||||||
if (result != kOptimal)
|
if (result != kOptimal)
|
||||||
printf("Could not solve the layout specification (%d). ", result);
|
printf("Could not solve the layout specification (%d). ", result);
|
||||||
|
|
||||||
return BSize(width->Value(), height->Value());
|
return BSize(width->Value(), height->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ActiveSetSolver::_RemoveSoftConstraint(ConstraintList& list)
|
||||||
|
{
|
||||||
|
ConstraintList allConstraints = fLinearSpec->Constraints();
|
||||||
|
for (int i = 0; i < allConstraints.CountItems(); i++) {
|
||||||
|
Constraint* constraint = allConstraints.ItemAt(i);
|
||||||
|
if (!constraint->IsSoft())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (fLinearSpec->RemoveConstraint(constraint, false) == true)
|
||||||
|
list.AddItem(constraint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ActiveSetSolver::_AddSoftConstraint(const ConstraintList& list)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < list.CountItems(); i++) {
|
||||||
|
Constraint* constraint = list.ItemAt(i);
|
||||||
|
// at least don't leak it
|
||||||
|
if (fLinearSpec->AddConstraint(constraint) == false)
|
||||||
|
delete constraint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ public:
|
|||||||
BSize MaxSize(Variable* width, Variable* height);
|
BSize MaxSize(Variable* width, Variable* height);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void _RemoveSoftConstraint(ConstraintList& list);
|
||||||
|
void _AddSoftConstraint(const ConstraintList& list);
|
||||||
|
|
||||||
const VariableList& fVariables;
|
const VariableList& fVariables;
|
||||||
const ConstraintList& fConstraints;
|
const ConstraintList& fConstraints;
|
||||||
|
|
||||||
|
|||||||
@@ -914,7 +914,6 @@ LayoutOptimizer::_SolveSubProblem(const double* d, int am, double* p)
|
|||||||
negate_vector(pz, zn);
|
negate_vector(pz, zn);
|
||||||
|
|
||||||
// fTemp2 = Ztrans * G * Z
|
// fTemp2 = Ztrans * G * Z
|
||||||
//multiply_optimization_matrix_matrix(Z, an, zn, fTemp1);
|
|
||||||
multiply_matrices(fG, Z, fTemp1, zm, fVariableCount, zn);
|
multiply_matrices(fG, Z, fTemp1, zm, fVariableCount, zn);
|
||||||
multiply_matrices(fZtrans, fTemp1, fTemp2, zn, zm, zn);
|
multiply_matrices(fZtrans, fTemp1, fTemp2, zn, zm, zn);
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ LinearSpec::RemoveVariable(Variable* variable, bool deleteVariable)
|
|||||||
int32
|
int32
|
||||||
LinearSpec::IndexOf(const Variable* variable) const
|
LinearSpec::IndexOf(const Variable* variable) const
|
||||||
{
|
{
|
||||||
return fVariables.IndexOf(variable);
|
return fUsedVariables.IndexOf(variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,10 +168,20 @@ LinearSpec::AddConstraint(Constraint* constraint)
|
|||||||
if (!fConstraints.AddItem(constraint))
|
if (!fConstraints.AddItem(constraint))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// ref count the used variables
|
||||||
|
SummandList* leftSide = constraint->LeftSide();
|
||||||
|
for (int i = 0; i < leftSide->CountItems(); i++) {
|
||||||
|
Variable* var = leftSide->ItemAt(i)->Var();
|
||||||
|
if (var->AddReference() == 1)
|
||||||
|
fUsedVariables.AddItem(var);
|
||||||
|
}
|
||||||
|
|
||||||
if (!fSolver->ConstraintAdded(constraint)) {
|
if (!fSolver->ConstraintAdded(constraint)) {
|
||||||
fConstraints.RemoveItem(constraint);
|
RemoveConstraint(constraint, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constraint->fIsValid = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +193,13 @@ LinearSpec::RemoveConstraint(Constraint* constraint, bool deleteConstraint)
|
|||||||
fConstraints.RemoveItem(constraint);
|
fConstraints.RemoveItem(constraint);
|
||||||
constraint->fIsValid = false;
|
constraint->fIsValid = false;
|
||||||
|
|
||||||
|
SummandList* leftSide = constraint->LeftSide();
|
||||||
|
for (int i = 0; i < leftSide->CountItems(); i++) {
|
||||||
|
Variable* var = leftSide->ItemAt(i)->Var();
|
||||||
|
if (var->RemoveReference() == 0)
|
||||||
|
fUsedVariables.RemoveItem(var);
|
||||||
|
}
|
||||||
|
|
||||||
if (deleteConstraint)
|
if (deleteConstraint)
|
||||||
delete constraint;
|
delete constraint;
|
||||||
return true;
|
return true;
|
||||||
@@ -559,7 +576,7 @@ LinearSpec::Constraints() const
|
|||||||
const VariableList&
|
const VariableList&
|
||||||
LinearSpec::Variables() const
|
LinearSpec::Variables() const
|
||||||
{
|
{
|
||||||
return fVariables;
|
return fUsedVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -295,12 +295,29 @@ Variable::Variable(LinearSpec* ls)
|
|||||||
fMin(-20000),
|
fMin(-20000),
|
||||||
fMax(20000),
|
fMax(20000),
|
||||||
fLabel(NULL),
|
fLabel(NULL),
|
||||||
fIsValid(false)
|
fIsValid(false),
|
||||||
|
fReferenceCount(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
Variable::AddReference()
|
||||||
|
{
|
||||||
|
fReferenceCount++;
|
||||||
|
return fReferenceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
Variable::RemoveReference()
|
||||||
|
{
|
||||||
|
fReferenceCount--;
|
||||||
|
return fReferenceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
* Removes the variable from its specification.
|
* Removes the variable from its specification.
|
||||||
|
|||||||
Reference in New Issue
Block a user