GeneralConstraint Class Reference

#include <GeneralConstraint.hh>

List of all members.

Public Member Functions

 GeneralConstraint (ABA_MASTER *master, vector< int > *vertices, vector< int > *dualCoeff, int rhs, Graph *theGraph)
virtual ~GeneralConstraint ()
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

The class GeneralConstraint is derived from the abstract ABACUS constraint class ABA_CONSTRAINT. It stores a constraint comeing from a local cut.

Definition at line 38 of file GeneralConstraint.hh.


Constructor & Destructor Documentation

GeneralConstraint::GeneralConstraint ABA_MASTER *  master,
vector< int > *  vertices,
vector< int > *  dualCoeff,
int  rhs,
Graph theGraph
 

Constructor.

Parameters:
*master Pointer to the corresponding master of the optimization.
*vertices Pointer to a vector storing the nodes of the inequality.
*dualCoeff Pointer to a vector storing the coefficients for each node of the inequality.
rhs The ride hand side of the inequality.
*theGraph Pointer to the object storing the graph corresponding to the problem.

Definition at line 49 of file GeneralConstraint.cpp.

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

00051                                                      :
00052     ABA_CONSTRAINT(master, NULL, ABA_CSENSE::Less, rhs, true, false, false),
00053     nodes(vertices->size()),
00054     coefficients(vertices->size()),
00055     itsRhs(rhs),
00056     itsGraph(theGraph)
00057 {
00058     // Store this inequality that it can be checked.
00059     ofstream fout(theGraph->getFileName(), ios::app);
00060 
00061     // Save the inequality.
00062     for (int i=0; i<vertices->size(); i++) {
00063         nodes[i] = (*vertices)[i];
00064         coefficients[i] = (*dualCoeff)[i];
00065         fout << "  " << coefficients[i] << " x_";
00066         fout << itsGraph->translateNode(nodes[i]);
00067     }
00068     fout << "  <  " << itsRhs << endl;
00069     fout.close();
00070 
00071     // Calculate the key.
00072     calculateHashKey();
00073 }

GeneralConstraint::~GeneralConstraint  )  [virtual]
 

Destructor.

Definition at line 79 of file GeneralConstraint.cpp.

00079                                       {
00080 }


Member Function Documentation

double GeneralConstraint::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 111 of file GeneralConstraint.cpp.

References Node::nodeNumber().

00111                                                  {
00112 
00113     // Cast ABA_VARIABLE* to NODE*.
00114     Node *node = (Node *) var;
00115 
00116     // Search for this variable in vector nodes.
00117     // This vector is sorted.
00118     int i = 0;
00119     int vertex = node->nodeNumber();
00120 
00121     while (vertex > nodes[i]) {
00122         i++;
00123         if (i == nodes.size()) {
00124             return 0.0;
00125         }
00126     }
00127     if (vertex == nodes[i]) {
00128         return coefficients[i];
00129     }
00130     return 0.0;
00131 }

bool GeneralConstraint::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 171 of file GeneralConstraint.cpp.

References hashKey().

00171                                             {
00172 
00173     bool isEqual = true;
00174     if (thisHashKey != ((GeneralConstraint *)cv)->hashKey()) {
00175         isEqual = false;
00176     }
00177     if (nodes.size() != ((GeneralConstraint *)cv)->getSize()) {
00178         isEqual = false;
00179     }
00180 
00181     for(int i=0; i<nodes.size(); i++) {
00182         if (!((GeneralConstraint *)cv)->isInConstraint(nodes[i])) {
00183             isEqual = false;
00184         }
00185     }
00186 
00187     return isEqual;
00188 }

int GeneralConstraint::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 89 of file GeneralConstraint.cpp.

00091 {
00092 
00093     for (int i=0; i<nodes.size(); i++) {
00094         row.insert(nodes[i],coefficients[i]);
00095     }
00096     row.rhs(itsRhs);
00097     row.sense(ABA_CSENSE::Less);
00098 
00099     return row.nnz();
00100 }

int GeneralConstraint::getSize  ) 
 

Get number of nodes part of this constraint.

Returns:
Size of vector nodes.

Definition at line 139 of file GeneralConstraint.cpp.

00139                                {
00140     return nodes.size();
00141 }

unsigned GeneralConstraint::hashKey  )  [virtual]
 

This method returns the hashkey of the constraint.

Returns:
The hashkey of the constraint.

Definition at line 210 of file GeneralConstraint.cpp.

Referenced by equal().

00210                                     {
00211     return thisHashKey;
00212 }

bool GeneralConstraint::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 151 of file GeneralConstraint.cpp.

00151                                                {
00152 
00153     for(int i=0; i<nodes.size(); i++) {
00154         if (nodes[i] == node) {
00155             return true;
00156         }
00157     }
00158 
00159     return false;
00160 }

const char * GeneralConstraint::name  )  [virtual]
 

This method returns the name of this constraint.

Returns:
Pointer to the name of this constraint

Definition at line 197 of file GeneralConstraint.cpp.

00197                                     {
00198     return "GeneralConstraint";
00199 }


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