Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent cycling #60

Merged
merged 4 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void Engine::performSimplexStep()
unsigned tries = GlobalConfiguration::MAX_SIMPLEX_PIVOT_SEARCH_ITERATIONS;
Set<unsigned> excludedEnteringVariables;
unsigned bestLeaving = 0;
double bestChangeRatio = 0.0;

while ( tries > 0 )
{
Expand Down Expand Up @@ -340,6 +341,7 @@ void Engine::performSimplexStep()
{
bestEntering = _tableau->getEnteringVariableIndex();
bestLeaving = _tableau->getLeavingVariableIndex();
bestChangeRatio = _tableau->getChangeRatio();
memcpy( _work, _tableau->getChangeColumn(), sizeof(double) * _tableau->getM() );
break;
}
Expand All @@ -352,6 +354,7 @@ void Engine::performSimplexStep()
bestEntering = _tableau->getEnteringVariableIndex();
bestPivotEntry = pivotEntry;
bestLeaving = leavingIndex;
bestChangeRatio = _tableau->getChangeRatio();
memcpy( _work, _tableau->getChangeColumn(), sizeof(double) * _tableau->getM() );
}

Expand Down Expand Up @@ -397,6 +400,7 @@ void Engine::performSimplexStep()
_tableau->setEnteringVariableIndex( bestEntering );
_tableau->setLeavingVariableIndex( bestLeaving );
_tableau->setChangeColumn( _work );
_tableau->setChangeRatio( bestChangeRatio );

bool fakePivot = _tableau->performingFakePivot();

Expand Down
1 change: 1 addition & 0 deletions src/engine/ITableau.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ITableau
virtual unsigned getLeavingVariable() const = 0;
virtual unsigned getLeavingVariableIndex() const = 0;
virtual double getChangeRatio() const = 0;
virtual void setChangeRatio( double changeRatio ) = 0;
virtual bool performingFakePivot() const = 0;
virtual void performPivot() = 0;
virtual double ratioConstraintPerBasic( unsigned basicIndex, double coefficient, bool decrease ) = 0;
Expand Down
28 changes: 27 additions & 1 deletion src/engine/Tableau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ double Tableau::getChangeRatio() const
return _changeRatio;
}

void Tableau::setChangeRatio( double changeRatio )
{
_changeRatio = changeRatio;
}

void Tableau::computeChangeColumn()
{
// _a gets the entering variable's column in A
Expand Down Expand Up @@ -1694,9 +1699,30 @@ void Tableau::updateAssignmentForPivot()
// If the change ratio is 0, just maintain the current assignment
if ( FloatUtils::isZero( _changeRatio ) )
{
ASSERT( !performingFakePivot() );

DEBUG({
// This should only happen when the basic variable is pressed against
// one of its bounds
if ( !( _basicStatus[_leavingVariable] == Tableau::AT_UB ||
_basicStatus[_leavingVariable] == Tableau::AT_LB ||
_basicStatus[_leavingVariable] == Tableau::BETWEEN
) )
{
printf( "Assertion violation!\n" );
printf( "Basic (leaving) variable is: %u\n", _basicIndexToVariable[_leavingVariable] );
printf( "Basic assignment: %.10lf. Bounds: [%.10lf, %.10lf]\n",
_basicAssignment[_leavingVariable],
_lowerBounds[_basicIndexToVariable[_leavingVariable]],
_upperBounds[_basicIndexToVariable[_leavingVariable]] );
printf( "Basic status: %u\n", _basicStatus[_leavingVariable] );
printf( "leavingVariableIncreases = %s", _leavingVariableIncreases ? "yes" : "no" );
exit( 1 );
}
});

double basicAssignment = _basicAssignment[_leavingVariable];
double nonBasicAssignment = _nonBasicAssignment[_enteringVariable];

_basicAssignment[_leavingVariable] = nonBasicAssignment;
_nonBasicAssignment[_enteringVariable] = basicAssignment;
return;
Expand Down
1 change: 1 addition & 0 deletions src/engine/Tableau.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class Tableau : public ITableau, public IBasisFactorization::BasisColumnOracle
unsigned getLeavingVariable() const;
unsigned getLeavingVariableIndex() const;
double getChangeRatio() const;
void setChangeRatio( double changeRatio );

/*
Returns true iff the current iteration is a fake pivot, i.e. the
Expand Down
2 changes: 2 additions & 0 deletions src/engine/tests/MockTableau.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class MockTableau : public ITableau
}

double getChangeRatio() const { return 0; }
void setChangeRatio( double /* changeRatio */ ) {}

void performPivot() {}
bool performingFakePivot() const
{
Expand Down