RankConstraint Class Reference

#include <RankConstraint.hh>

List of all members.

Public Member Functions

 RankConstraint (ABA_MASTER *master, vector< int > *nodes, int rhs, Graph *theGraph)
 RankConstraint (ABA_MASTER *master, vector< int > *nodes, int rhs, bool dynamic, Graph *theGraph)
virtual ~RankConstraint ()
int genRow (ABA_ACTIVE< ABA_VARIABLE, ABA_CONSTRAINT > *var, ABA_ROW &row)
virtual double coeff (ABA_VARIABLE *var)
int getSize ()
bool isInConstraint (int node)
virtual bool equal (ABA_CONVAR *cv)
virtual const char * name ()
virtual unsigned hashKey ()


Detailed Description

This class is derived from the abstract ABACUS constraint class ABA_CONSTRAINT. It stores a rank inequality and computes the corresponding constraint.

Definition at line 39 of file RankConstraint.hh.


Constructor & Destructor Documentation

RankConstraint::RankConstraint ABA_MASTER *  master,
vector< int > *  nodes,
int  rhs,
Graph theGraph
 

Constructor.

Parameters:
*master Pointer to the corresponding master of the optimization.
*nodes Pointer to a vector which stores the nodes.
rhs Ride hand side of the constraint.
*theGraph Pointer to the object representing the graph of the problem.

Definition at line 46 of file RankConstraint.cpp.

References Graph::getFileName(), and Graph::translateNode().

00047                                                :
00048     ABA_CONSTRAINT(master, NULL, ABA_CSENSE::Less, rhs, true, false, false),
00049     itsNodes(nodes->size()),
00050     itsGraph(theGraph),
00051     itsRhs(rhs)
00052 {
00053     // Store this inequality that it can be checked.
00054     ofstream fout(theGraph->getFileName(), ios::app);
00055 
00056     for (int i=0; i<nodes->size(); i++) {
00057         itsNodes[i] = (*nodes)[i];
00058         fout << "  1 x_" << itsGraph->translateNode(itsNodes[i]);
00059     }
00060     fout << "  <  " << itsRhs << endl;
00061     fout.close();
00062 
00063     // Calculate the key.
00064     calculateHashKey();
00065 }

RankConstraint::RankConstraint ABA_MASTER *  master,
vector< int > *  nodes,
int  rhs,
bool  dynamic,
Graph theGraph
 

Constructor.

Parameters:
*master Pointer to the corresponding master of the optimization.
*nodes Pointer to a vector which stores the nodes.
rhs Ride hand side of the constraint.
dynamic Indicate if that inequality can be removed from the pool or not.
*theGraph Pointer to the object representing the graph of the problem.

Definition at line 76 of file RankConstraint.cpp.

References Graph::getFileName(), and Graph::translateNode().

00077                                                              :
00078     ABA_CONSTRAINT(master, NULL, ABA_CSENSE::Less, rhs, dynamic, false, false),
00079     itsNodes(nodes->size()),
00080     itsGraph(theGraph),
00081     itsRhs(rhs)
00082 {
00083     // Store this inequality that it can be checked.
00084     ofstream fout(theGraph->getFileName(), ios::app);
00085 
00086     for (int i=0; i<nodes->size(); i++) {
00087         itsNodes[i] = (*nodes)[i];
00088         fout << "  1 x_" << itsGraph->translateNode(itsNodes[i]);
00089     }
00090     fout << "  <  " << itsRhs << endl;
00091     fout.close();
00092 
00093     // Calculate the key.
00094     calculateHashKey();
00095 }

RankConstraint::~RankConstraint  )  [virtual]
 

Destructor.

Definition at line 101 of file RankConstraint.cpp.

00101                                 {
00102 }


Member Function Documentation

double RankConstraint::coeff ABA_VARIABLE *  var  )  [virtual]
 

Get coefficient of a variable.

Parameters:
*var Pointer to a variable.
Returns:
The coefficient of the variable var in this clique constraint.

Definition at line 133 of file RankConstraint.cpp.

References Node::nodeNumber().

00133                                               {
00134 
00135     // Cast ABA_VARIABLE* to NODE*.
00136     Node *node = (Node *) var;
00137     // search for this variable in the clique
00138     for (int i=0; i<itsNodes.size(); i++) {
00139         if (node->nodeNumber() == itsNodes[i]) {
00140             return 1.0;
00141         }
00142     }
00143     return 0.0;
00144 }

bool RankConstraint::equal ABA_CONVAR *  cv  )  [virtual]
 

Compare if constraint cv is equal to this constraint.

Parameters:
*cv Pointer to the constraint to be compared with this one.
Returns:
true If both constraints are equal.

false Otherwise.

Definition at line 182 of file RankConstraint.cpp.

References hashKey().

00182                                          {
00183 
00184     bool isEqual = true;
00185     if (thisHashKey != ((RankConstraint *)cv)->hashKey()) {
00186         isEqual = false;
00187     }
00188     if (itsNodes.size() != ((RankConstraint *)cv)->getSize()) {
00189         isEqual = false;
00190     }
00191 
00192     for(int i=0; i<itsNodes.size(); i++) {
00193         if (!((RankConstraint *)cv)->isInConstraint(itsNodes[i])) {
00194             isEqual = false;
00195         }
00196     }
00197 
00198     return isEqual;
00199 }

int RankConstraint::genRow ABA_ACTIVE< ABA_VARIABLE, ABA_CONSTRAINT > *  var,
ABA_ROW &  row
 

Get constraint in sparse format.

Parameters:
*var Pointer to a variable set.
&row Reference to abacus object storing the inequality.
Returns:
Number of non-zeros in the inequality.

Definition at line 111 of file RankConstraint.cpp.

00113 {
00114 
00115     for (int i=0; i<itsNodes.size(); i++) {
00116         row.insert(itsNodes[i],1.0);
00117     }
00118     row.rhs(itsRhs);
00119     row.sense(ABA_CSENSE::Less);
00120 
00121     return row.nnz();
00122 }

int RankConstraint::getSize  ) 
 

Get size of clique.

Parameters:
void 
Returns:
Size of vector nodesOfClique.

Definition at line 150 of file RankConstraint.cpp.

00150                             {
00151     return itsNodes.size();
00152 }

unsigned RankConstraint::hashKey  )  [virtual]
 

This method returns the hashkey of the constraint.

Parameters:
void 
Returns:
The hashkey of the constraint.

Definition at line 221 of file RankConstraint.cpp.

Referenced by equal().

00221                                  {
00222     return thisHashKey;
00223 }

bool RankConstraint::isInConstraint int  node  ) 
 

Checks if node is member of this constraint.

Parameters:
node A node.
Returns:
true Node is member of this constraint.

false Otherwise.

Definition at line 162 of file RankConstraint.cpp.

00162                                             {
00163 
00164     for(int i=0; i<itsNodes.size(); i++) {
00165         if (itsNodes[i] == node) {
00166             return true;
00167         }
00168     }
00169 
00170     return false;
00171 }

const char * RankConstraint::name  )  [virtual]
 

This method returns the name of this constraint.

Parameters:
void 
Returns:
Pointer to the name of this constraint

Definition at line 208 of file RankConstraint.cpp.

00208                                  {
00209     return "RankConstraint";
00210 }


The documentation for this class was generated from the following files:
Generated on Fri Apr 28 15:50:01 2006 for Branch and Cut algorithm for the Maximum Stable Set Problem by  doxygen 1.4.6-NO