-
Notifications
You must be signed in to change notification settings - Fork 93
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
Steepest edge #1
Changes from 28 commits
ff0520a
73f5f74
8c82523
0e5ff0c
f27acfc
e50b626
49086e4
7dcaa4c
0e7c5ba
6d1715c
ce1d86a
1bf3749
225d546
49e6be8
184017f
af17332
7bef25b
d8839d6
d5908f9
0badbd5
b6444d5
18cdea7
e8d3268
3c77698
8b15840
4c69ef9
5bfb1ed
cdb3177
a3772c2
05f42cc
0554d5b
f286005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure gamma[j] isn't zero? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't be, because it's the weight of the vector p[j] (the direction the variable x moves in if you increment nonbasic variable Xj). We can add an ASSERT to be sure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, let's add an assert |
||
} | ||
|
||
// | ||
// Local Variables: | ||
// compile-command: "make -C .. " | ||
// tags-file-name: "../TAGS" | ||
// c-basic-offset: 4 | ||
// End: | ||
// |
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: | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine