Skip to content
Snippets Groups Projects
Commit 2ad2b850 authored by Jeremy Omer's avatar Jeremy Omer
Browse files

A bunch of cpplint errors

parent 4d0fd549
No related branches found
No related tags found
No related merge requests found
...@@ -2,3 +2,7 @@ bin/ ...@@ -2,3 +2,7 @@ bin/
.lastrunsuccess .lastrunsuccess
*.tex *.tex
*.o *.o
.idea/min-revorder.iml
.idea/modules.xml
.idea/vcs.xml
.idea/workspace.xml
This diff is collapsed.
...@@ -11,149 +11,154 @@ ...@@ -11,149 +11,154 @@
// Search for all the cycles in the digraph described by the input adjacency // Search for all the cycles in the digraph described by the input adjacency
// list and root vertex // list and root vertex
bool DiscretizationSolver::enumeratecycles(std::map<Vertex*, std::vector<Vertex*> >& adjlist, Vertex* root, bool DiscretizationSolver::enumeratecycles(
std::vector<std::vector<Vertex*> >& cycles) { std::map<Vertex*,
std::vector<Vertex*> >& adjlist,
Vertex* root,
std::vector<std::vector<Vertex*> >& cycles) {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "revorder: enumeration of the cycles" << std::endl; std::cout << "revorder: enumeration of the cycles" << std::endl;
#endif #endif
// Search for a topological order that will be valid only if the digraph is // Search for a topological order that will be valid only if the digraph is
// acyclic // acyclic
std::vector<Vertex*> reverseorder; std::vector<Vertex*> reverseorder;
std::map<Vertex*, int> rank; std::map<Vertex*, int> rank;
topologicalorder(root, adjlist, reverseorder, rank); topologicalorder(root, adjlist, reverseorder, rank);
// Search for a set of arc-disjoint cycles // Search for a set of arc-disjoint cycles
// //
std::vector<std::pair<Vertex*, Vertex*> > reverseedges; std::vector<std::pair<Vertex*, Vertex*> > reverseedges;
if(!this->getreverseedges(adjlist, reverseorder, rank, reverseedges)) { if (!this->getreverseedges(adjlist, reverseorder, rank, reverseedges)) {
return false; return false;
} }
// //
// otherwise, for all reverse arcs search the shortest path from one end point // otherwise, for all reverse arcs search the shortest path from one end point
// to the other following the topological order // to the other following the topological order
int nbcycles = 0; int nbcycles = 0;
for(std::pair<Vertex*, Vertex*> a : reverseedges) { for (std::pair<Vertex*, Vertex*> a : reverseedges) {
Vertex* v1 = a.first; Vertex* v1 = a.first;
Vertex* v2 = a.second; Vertex* v2 = a.second;
std::vector<Vertex*> shortestpath; std::vector<Vertex*> shortestpath;
dijkstra_unitcost(v2, v1, adjlist, rank, shortestpath); dijkstra_unitcost(v2, v1, adjlist, rank, shortestpath);
cycles.push_back(shortestpath); cycles.push_back(shortestpath);
nbcycles += 1; nbcycles += 1;
// if (nbcycles >= 10) return true; // if (nbcycles >= 10) return true;
// if (this->modeltype_==WITNESS) return true; // if (this->modeltype_==WITNESS) return true;
} }
return true; return true;
} }
// //
// search for a topological order compatible with the current integer solution // search for a topological order compatible with the current integer solution
// of the integer program // of the integer program if the graph is not acyclic, the order will be used
// if the graph is not acyclic, the order will be used to identify cycles // to identify cycles
void DiscretizationSolver::topologicalorder(Vertex* root, void DiscretizationSolver::topologicalorder(
const std::map<Vertex*, std::vector<Vertex*> >& adjlist, Vertex* root,
std::vector<Vertex*>& reverseorder, std::map<Vertex*, int>& rank) { const std::map<Vertex*, std::vector<Vertex*>>& adjlist,
// Call a depth first search recursively from the root to get a topological std::vector<Vertex*>& reverseorder,
// order that will be valid only if the solution describes an acyclic digraph std::map<Vertex*, int>& rank) {
// // Call a depth first search recursively from the root to get a topological
// call the recursive function from the root // order that will be valid only if the solution describes an acyclic digraph
std::map<Vertex*, int> color; //
for (Vertex* v : this->inst_->vertices_) color[v] = 0; // call the recursive function from the root
while (true) { std::map<Vertex*, int> color;
depthfirstsearch(root, adjlist, color, reverseorder); for (Vertex* v : this->inst_->vertices_) color[v] = 0;
if (reverseorder.size() < this->inst_->nbvertices_) { while (true) {
for (Vertex* v : this->inst_->vertices_) { depthfirstsearch(root, adjlist, color, reverseorder);
if (color[v] == 0) root = v; if (reverseorder.size() < this->inst_->nbvertices_) {
} for (Vertex* v : this->inst_->vertices_) {
} if (color[v] == 0) root = v;
else break; }
} }
// else break;
// recover the rank of each vertex }
for (Vertex* v : this->inst_->vertices_) rank[v] = -1; //
int currentrank = this->inst_->nbvertices_; // recover the rank of each vertex
for (Vertex* v : reverseorder) { for (Vertex* v : this->inst_->vertices_) rank[v] = -1;
rank[v] = currentrank--; int currentrank = this->inst_->nbvertices_;
} for (Vertex* v : reverseorder) {
rank[v] = currentrank--;
}
} }
// //
// get all the edges that go against the topological order described by the // get all the edges that go against the topological order described by the
// inputs rank and reverseorder // inputs rank and reverseorder
// return false if there is none (i.e. if the graph is acyclic) // return false if there is none (i.e. if the graph is acyclic)
bool DiscretizationSolver::getreverseedges(std::map<Vertex*, std::vector<Vertex*> >& adjlist, bool DiscretizationSolver::getreverseedges(std::map<Vertex*, std::vector<Vertex*> >& adjlist,
std::vector<Vertex*>& reverseorder, std::map<Vertex*, int>& rank, std::vector<Vertex*>& reverseorder, std::map<Vertex*, int>& rank,
std::vector<std::pair<Vertex*, Vertex*> >& reverseedges){ std::vector<std::pair<Vertex*, Vertex*> >& reverseedges){
// //
// first, collect all the "reverse" arcs, i.e. the arcs that go against the // first, collect all the "reverse" arcs, i.e. the arcs that go against the
// topological order, and delete them from the adjacency lists // topological order, and delete them from the adjacency lists
for (Vertex* v1 : reverseorder) { for (Vertex* v1 : reverseorder) {
std::vector<Vertex*>::iterator itv2 = adjlist[v1].begin(); std::vector<Vertex*>::iterator itv2 = adjlist[v1].begin();
while (itv2 != adjlist[v1].end()) { while (itv2 != adjlist[v1].end()) {
Vertex* v2 = *itv2; Vertex* v2 = *itv2;
if (rank[v2] < rank[v1]) { if (rank[v2] < rank[v1]) {
reverseedges.push_back(std::pair<Vertex*, Vertex*>(v1, v2)); reverseedges.push_back(std::pair<Vertex*, Vertex*>(v1, v2));
adjlist[v1].erase(itv2); adjlist[v1].erase(itv2);
// //
// separate only one cycle in witness decomposition (as described in the article) // separate only one cycle in witness decomposition (as described in the article)
// if (this->modeltype_ == WITNESS) return true; // if (this->modeltype_ == WITNESS) return true;
} }
else itv2++; else itv2++;
} }
} }
// //
// if there is no reverse arc, stop the digraph is acyclic // if there is no reverse arc, stop the digraph is acyclic
if (reverseedges.empty()) return false; if (reverseedges.empty()) return false;
return true; return true;
} }
// //
// perform a depth-first search to compute a topological order of the digraph // perform a depth-first search to compute a topological order of the digraph
// described by the adjacency list // described by the adjacency list
void DiscretizationSolver::depthfirstsearch(Vertex* u, void DiscretizationSolver::depthfirstsearch(Vertex* u,
const std::map<Vertex*, std::vector<Vertex*> >& adjlist, const std::map<Vertex*, std::vector<Vertex*> >& adjlist,
std::map<Vertex*, int>& color, std::vector<Vertex*>& inverseorder) { std::map<Vertex*, int>& color, std::vector<Vertex*>& inverseorder) {
// //
color[u] = 1; color[u] = 1;
for (Vertex* v: adjlist.at(u)) { for (Vertex* v: adjlist.at(u)) {
if (color[v] == 0) { if (color[v] == 0) {
depthfirstsearch(v, adjlist, color, inverseorder); depthfirstsearch(v, adjlist, color, inverseorder);
} }
} }
color[u] = 2; color[u] = 2;
inverseorder.push_back(u); inverseorder.push_back(u);
} }
// //
// apply dijskstra algorithm to find a shortest path from o to d in the unit // apply dijskstra algorithm to find a shortest path from o to d in the unit
// cost digraph described by the input adjacency list // cost digraph described by the input adjacency list
void DiscretizationSolver::dijkstra_unitcost(Vertex* o, Vertex* d, const std::map<Vertex*, std::vector<Vertex*> >& adjlist, std::map<Vertex*, int>& rank, std::vector<Vertex*>& shortestpath) { void DiscretizationSolver::dijkstra_unitcost(Vertex* o, Vertex* d, const std::map<Vertex*, std::vector<Vertex*> >& adjlist, std::map<Vertex*, int>& rank, std::vector<Vertex*>& shortestpath) {
// //
// perform a breadth-first search from the origin vertex until the destination // perform a breadth-first search from the origin vertex until the destination
// is encountered // is encountered
std::vector<Vertex*> queue; std::vector<Vertex*> queue;
queue.push_back(o); queue.push_back(o);
std::map<Vertex*, bool> istreated; std::map<Vertex*, bool> istreated;
for (Vertex* v : this->inst_->vertices_) istreated[v] = false; for (Vertex* v : this->inst_->vertices_) istreated[v] = false;
std::map<Vertex*, Vertex*> predecessor; std::map<Vertex*, Vertex*> predecessor;
while (!queue.empty()) { while (!queue.empty()) {
Vertex* v1 = queue.front(); Vertex* v1 = queue.front();
queue.erase(queue.begin()); queue.erase(queue.begin());
for (Vertex* v2 : adjlist.at(v1)) { for (Vertex* v2 : adjlist.at(v1)) {
if (!istreated[v2] && rank[v2] <= rank[d]) { if (!istreated[v2] && rank[v2] <= rank[d]) {
predecessor[v2] = v1; predecessor[v2] = v1;
queue.push_back(v2); queue.push_back(v2);
istreated[v2] = true; istreated[v2] = true;
if (v2 == d) goto cyclefound; if (v2 == d) goto cyclefound;
} }
} }
} }
// //
// if a path has been found store it as the shortest path // if a path has been found store it as the shortest path
// this is guaranteed by the unit cost and the breadth-first search // this is guaranteed by the unit cost and the breadth-first search
cyclefound: cyclefound:
shortestpath.push_back(d); shortestpath.push_back(d);
Vertex* pred = d; Vertex* pred = d;
while (pred != o) { while (pred != o) {
pred = predecessor[pred]; pred = predecessor[pred];
shortestpath.insert(shortestpath.begin(), pred); shortestpath.insert(shortestpath.begin(), pred);
}; };
} }
This diff is collapsed.
...@@ -178,16 +178,20 @@ protected: ...@@ -178,16 +178,20 @@ protected:
std::map<Clique*, int> nbpartialinclique_; std::map<Clique*, int> nbpartialinclique_;
// //
// option of the solver // option of the solver
bool decomposecomponents_; // if true, regularly identify connected components of unordered vertices and decompose the problem accordingly bool decomposecomponents_; // if true, regularly identify connected
int initialcyclesize_; // size of the cycle cuts initially included in CCG and WITNESS (default is 3) // components of unordered vertices and decompose the problem accordingly
int cliquecutsmaxsize_; // maximum size of cliques in clique cuts (default is 6) int initialcyclesize_; // size of the cycle cuts initially included in
// CCG and WITNESS (default is 3)
int cliquecutsmaxsize_; // maximum size of cliques in clique cuts
// (default is 6)
public: public:
// //
// cplex variables // cplex variables
// //
// variables that represent the order relations between the vertices // variables that represent the order relations between the vertices
// - In CCG, isbefore[i,j] = 1 if vertex i is before j in the order // - In CCG, isbefore[i,j] = 1 if vertex i is before j in the order
// - in WITNESS, isbefore[i,j] = 1 if and only if i is a witness of j (see Bodur and MacNeil 2019 for description) // - in WITNESS, isbefore[i,j] = 1 if and only if i is a witness of j
// (see Bodur and MacNeil 2019 for description)
BoolVarVertexMapMatrix isbefore_; BoolVarVertexMapMatrix isbefore_;
// isfullref[v] =1 if vertex v is fully-referenced and 0 otherwise // isfullref[v] =1 if vertex v is fully-referenced and 0 otherwise
...@@ -200,8 +204,10 @@ public: ...@@ -200,8 +204,10 @@ public:
IntVarVertexMap rank_; IntVarVertexMap rank_;
// //
// - variables that set the initial clique // - variables that set the initial clique
IloBoolVarArray isclique_; // after enumeration of all potential cliques, =1 for the chosen clique, 0 otherwise IloBoolVarArray isclique_; // after enumeration of all potential cliques,
BoolVarVertexMap isvertexinclique_; // when no enumeration, =1 if a vertex is in the initial clique, 0 otherwise // =1 for the chosen clique, 0 otherwise
BoolVarVertexMap isvertexinclique_; // when no enumeration, =1 if a
// vertex is in the initial clique, 0 otherwise
public: public:
// //
// Problem solved // Problem solved
...@@ -215,7 +221,7 @@ public: ...@@ -215,7 +221,7 @@ public:
// Description of the instance // Description of the instance
// //
Instance* inst_; // instance solved by the solver Instance* inst_; // instance solved by the solver
std::vector<Clique*> cliques_; // list of the potential intial cliques std::vector<Clique*> cliques_; // list of the potential intial cliques
// //
// Result of preprocessing // Result of preprocessing
// //
...@@ -226,22 +232,31 @@ public: ...@@ -226,22 +232,31 @@ public:
std::vector<int> greedynbfullrefperclique_; std::vector<int> greedynbfullrefperclique_;
// //
// list of cliques and current best initial clique // list of cliques and current best initial clique
std::map<Vertex*, std::vector<Clique*> > cliqueslist_; // list of the cliques a vertex belongs to std::map<Vertex*, std::vector<Clique*> > cliqueslist_; // list of the
std::map<Vertex*, std::vector<int> > cliqueidslist_; // list of the cliques ids a vertex belongs to // cliques a vertex belongs to
std::map<Vertex*, std::vector<int> > cliqueidslist_; // list of the
// cliques ids a vertex belongs to
// //
// list of cycles composed of low degree (<=U+1) vertices // list of cycles composed of low degree (<=U+1) vertices
int nblowdegreecycles_; // number of low degree cycles int nblowdegreecycles_; // number of low degree cycles
std::vector<std::vector<Vertex*>> lowdegreecycles_; std::vector<std::vector<Vertex*>> lowdegreecycles_;
std::vector<int> nbpartialsincycle_; std::vector<int> nbpartialsincycle_;
std::map<Vertex*,bool> isvertexinlowdegreecycles_; // list of all the vertices included in at least one low degree cycle std::map<Vertex*,bool> isvertexinlowdegreecycles_; // list of all the
// // vertices included in at least one low degree cycle
// Record the current best solution, it is first updated after solving the greedy algorithm //
std::map<Vertex*,int> bestrank_; //rank of each vertex in the current best revorder // Record the current best solution, it is first updated after solving
int bestcliqueid_; // index of the initial in current best revorder // the greedy algorithm
std::map<Vertex*,bool> bestisfullref_; // indicator of fully-referenced vertices in the current best revorder std::map<Vertex*,int> bestrank_; //rank of each vertex in the current
std::vector<Vertex*> bestfullref_; // the fully-referenced vertices in the current best revorder // best revorder
std::map<Vertex*,int> bestnbrefs_; // number of references of each vertex in the current best revorder int bestcliqueid_; // index of the initial in current best revorder
int bestnbfullref_; // number of fully-referenced vertices in the best solution std::map<Vertex*,bool> bestisfullref_; // indicator of fully-referenced
// vertices in the current best revorder
std::vector<Vertex*> bestfullref_; // the fully-referenced vertices in
// the current best revorder
std::map<Vertex*,int> bestnbrefs_; // number of references of each vertex
// in the current best revorder
int bestnbfullref_; // number of fully-referenced vertices in the best
// solution
public: public:
// Public methods // Public methods
...@@ -381,15 +396,21 @@ public: ...@@ -381,15 +396,21 @@ public:
// get all the edges that go against the topological order described by the // get all the edges that go against the topological order described by the
// inputs rank and reverseorder // inputs rank and reverseorder
// return false if there is none (i.e. if the graph is acyclic) // return false if there is none (i.e. if the graph is acyclic)
bool getreverseedges(std::map<Vertex*, std::vector<Vertex*> >& adjlist, bool getreverseedges(
std::vector<Vertex*>& reverseorder, std::map<Vertex*, int>& rank, std::map<Vertex*, std::vector<Vertex*> >& adjlist,
std::vector<std::pair<Vertex*, Vertex*> >& reverseedges); std::vector<Vertex*>& reverseorder,
// std::map<Vertex*, int>& rank,
// search for a topological order compatible with the current integer solution std::vector<std::pair<Vertex*, Vertex*> >& reverseedges);
// of the integer program //
// search for a topological order compatible with the current integer
// solution of the integer program
// if the graph is not acyclic, the order will be used to identify cycles // if the graph is not acyclic, the order will be used to identify cycles
void topologicalorder(Vertex* root, const std::map<Vertex*, std::vector<Vertex*> >& adjlist, std::vector<Vertex*>& reverseorder, std::map<Vertex*, int>& rank); void topologicalorder(
// Vertex* root,
const std::map<Vertex*, std::vector<Vertex*> >& adjlist,
std::vector<Vertex*>& reverseorder,
std::map<Vertex*, int>& rank);
// perform a depth first search on the subgraph induced by the input vertex v // perform a depth first search on the subgraph induced by the input vertex v
// the graph is described by an adjacency list and vertices are marked with // the graph is described by an adjacency list and vertices are marked with
// colors when they are treated // colors when they are treated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment