Skip to content

Commit

Permalink
Merge pull request #1 from guykatzz/steepest-edge
Browse files Browse the repository at this point in the history
Steepest edge
  • Loading branch information
rachellim authored Jul 31, 2017
2 parents 8b9a128 + f286005 commit 4f384cd
Show file tree
Hide file tree
Showing 11 changed files with 729 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/reluplex/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Engine::Engine()
_tableau->setStatistics( &_statistics );

// _activeEntryStrategy = &_nestedDantzigsRule;
_activeEntryStrategy = &_dantzigsRule;
_activeEntryStrategy = &_steepestEdgeRule;
// _activeEntryStrategy = &_dantzigsRule;
// _activeEntryStrategy = &_blandsRule;
}

Expand Down Expand Up @@ -213,7 +214,7 @@ void Engine::processInputQuery( const InputQuery &inputQuery )
unsigned m = equations.size();
unsigned n = inputQuery.getNumberOfVariables();
_tableau->setDimensions( m, n );

// Current variables are [0,..,n-1], so the next variable is n.
FreshVariables::setNextVariable( n );

Expand Down
4 changes: 3 additions & 1 deletion src/reluplex/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "NestedDantzigsRule.h"
#include "SmtCore.h"
#include "Statistics.h"
#include "SteepestEdge.h"

class InputQuery;
class PiecewiseLinearConstraint;
Expand Down Expand Up @@ -68,7 +69,7 @@ class Engine : public IEngine
void storeTableauState( TableauState &state ) const;
void restoreTableauState( const TableauState &state );

private:
private:
/*
Collect and print various statistics.
*/
Expand Down Expand Up @@ -100,6 +101,7 @@ class Engine : public IEngine
BlandsRule _blandsRule;
DantzigsRule _dantzigsRule;
NestedDantzigsRule _nestedDantzigsRule;
SteepestEdgeRule _steepestEdgeRule;
EntrySelectionStrategy *_activeEntryStrategy;

/*
Expand Down
2 changes: 2 additions & 0 deletions src/reluplex/ITableau.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class ITableau
virtual void computeMultipliers() = 0;
virtual void computeReducedCost( unsigned nonBasic ) = 0;
virtual const double *getCostFunction() const = 0;
// TODO: not sure if i'm allowed to add to this virtual class?
virtual const double *getSteepestEdgeGamma() const = 0;
virtual void dumpCostFunction() const = 0;
virtual void computeD() = 0;
virtual void computeAssignment() = 0;
Expand Down
98 changes: 98 additions & 0 deletions src/reluplex/SteepestEdge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/********************* */
/*! \file SteepestEdge.cpp
** \verbatim
** Top contributors (to current version):
** Rachel Lim
** This file is part of the Marabou project.
** Copyright (c) 2016-2017 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**/

#include "FloatUtils.h"
#include "ITableau.h"
#include "ReluplexError.h"
#include "SteepestEdge.h"

bool SteepestEdgeRule::select( ITableau &tableau )
{
/***************************************************************
* Chooses most eligible nonbasic variable xN[q] according
* to steepest edge pivot selection rules.
*
* c[j]**2
* q = arg max -----------
* j in J gamma[j]
*
* where
* J = set of indices of eligible non-basic variables
* c[j] = reduced cost of nonbasic variable j
* gamma[j] = steepest edge weight
*
* Sets entering variable of the tableau to q.
***************************************************************/

// Calculate entire cost function
// TODO: integrate with Duligur's partial pricing?
tableau.computeCostFunction();

List<unsigned> candidates;
tableau.getEntryCandidates( candidates );

if ( candidates.empty() )
return false;

const double *costFunction = tableau.getCostFunction();
const double *gamma = tableau.getSteepestEdgeGamma();

List<unsigned>::const_iterator candidate = candidates.begin();
unsigned maxIndex = *candidate;
double maxValue = computeGradient( *candidate, costFunction, gamma );
++candidate;

while ( candidate != candidates.end() )
{
double contenderValue = computeGradient( *candidate, costFunction, gamma );
if ( FloatUtils::gt( contenderValue, maxValue ) )
{
maxIndex = *candidate;
maxValue = contenderValue;
}
++candidate;
}

tableau.setEnteringVariable( maxIndex );
return true;
}

double SteepestEdgeRule::computeGradient( const unsigned j, const double *c, const double *gamma )
{
/* Computes the (square of the) gradient in the step direction of the
* j-th nonbasic var.
*
* Step direction for candidate j,
* p[j] = [ -inv(B)*AN*e[j]; e[j] ]
* (where e[j] is the j-th standard unit vector)
*
* Let gamma[j] = || p[j] || ** 2
* c'*p[j] c[j]
* Gradient of cost function wrt p[j] = -------- = --------
* ||p[j]|| ||p[j]||
*
* This function returns c[j]**2 / gamma[j]
*
* Note: gamma[j] is costly to compute from scratch, but after each pivot operation, we
* can update gamma more cheaply using a recurrence relation. See Goldfarb and Reid (1977),
* Forrest and Goldfarb (1992).
*/
return (c[j] * c[j]) / gamma[j];
}

//
// Local Variables:
// compile-command: "make -C .. "
// tags-file-name: "../TAGS"
// c-basic-offset: 4
// End:
//
42 changes: 42 additions & 0 deletions src/reluplex/SteepestEdge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/********************* */
/*! \file SteepestEdge.h
** \verbatim
** Top contributors (to current version):
** Rachel Lim
** This file is part of the Marabou project.
** Copyright (c) 2016-2017 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**/

#ifndef __SteepestEdge_h__
#define __SteepestEdge_h__

#include "EntrySelectionStrategy.h"

class SteepestEdgeRule : public EntrySelectionStrategy
{
public:
/*
Apply steepest edge pivot selection rule: choose the candidate that maximizes the
magnitude of the gradient of the cost function with respect to the step direction.
*/
bool select( ITableau &tableau );

private:
/*
Helper function to compute gradient of cost function with respect to edge direction.
*/
double computeGradient( const unsigned j, const double *c, const double *gamma );
};

#endif // __SteepestEdge_h__

//
// Local Variables:
// compile-command: "make -C .. "
// tags-file-name: "../TAGS"
// c-basic-offset: 4
// End:
//
Loading

0 comments on commit 4f384cd

Please sign in to comment.