#include <GeneralConstraint.hh>
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 () |
Definition at line 38 of file GeneralConstraint.hh.
|
Constructor.
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 }
|
|
Destructor. Definition at line 79 of file GeneralConstraint.cpp.
|
|
Get coefficient of a variable.
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 }
|
|
Compare if constraint cv is equal to this constraint.
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 }
|
|
Get constraint in sparse format.
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 }
|
|
Get number of nodes part of this constraint.
Definition at line 139 of file GeneralConstraint.cpp.
|
|
This method returns the hashkey of the constraint.
Definition at line 210 of file GeneralConstraint.cpp. Referenced by equal().
|
|
Checks if node is member of this constraint.
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 }
|
|
This method returns the name of this constraint.
Definition at line 197 of file GeneralConstraint.cpp.
|