Skip to content

Commit

Permalink
fix several bugs #18
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Feb 27, 2012
1 parent 8465fd5 commit d207c6d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
3 changes: 0 additions & 3 deletions src/constraint_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
#include <constraint_generation.h>


bool generate_desagregate_constraints = true;
bool generate_agregate_constraints = false;

int new_var = 0;
CUDFcoefficient min_bandwidth = 0; //TODO set min_bandwidth to 1Ko

struct SetPathCoeff {

public:

SetPathCoeff(PSLProblem* problem, abstract_solver* solver) : problem(problem), solver(solver), stage(0) {
}

Expand Down
3 changes: 0 additions & 3 deletions src/constraint_generation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@



extern bool generate_desagregate_constraints;
extern bool generate_agregate_constraints;


extern int new_var;
extern CUDFcoefficient min_bandwidth;
Expand Down
18 changes: 9 additions & 9 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/stat.h>
#include <errno.h>
#include "abstract_solver.h"
#include "graphviz.hpp"

//Remove main
//#define main toto
Expand Down Expand Up @@ -553,14 +554,14 @@ int main(int argc, char *argv[]) {
} else if (strncmp(argv[i], "-v", 2) == 0) {
sscanf(argv[i]+2, "%u", &verbosity);
} else if (strcmp(argv[i], "-only-agregate-constraints") == 0) {
generate_agregate_constraints = true;
generate_desagregate_constraints = false;
//generate_agregate_constraints = true;
//generate_desagregate_constraints = false;
} else if (strcmp(argv[i], "-only-desagregate-constraints") == 0) {
generate_agregate_constraints = false;
generate_desagregate_constraints = true;
//generate_agregate_constraints = false;
//generate_desagregate_constraints = true;
} else if (strcmp(argv[i], "-all-constraints") == 0) {
generate_agregate_constraints = true;
generate_desagregate_constraints = true;
//generate_agregate_constraints = true;
//generate_desagregate_constraints = true;
} else if (strcmp(argv[i], "-cov") == 0) {
criteria_opt_var = true;
} else if (strcmp(argv[i], "-noreduce") == 0) {
Expand Down Expand Up @@ -706,8 +707,6 @@ int main(int argc, char *argv[]) {
print_problem(cout, the_problem);

fprintf(stdout, "================================================================\n");

fprintf(stdout, "================================================================\n");
}

// choose the solver
Expand Down Expand Up @@ -757,10 +756,11 @@ int main(int argc, char *argv[]) {
// printf("%s = "CUDFflags"\n", (*ipkg)->versioned_name, solver->get_solution(*ipkg));

fprintf(stdout, "================================================================\n");

fprintf(output_file, "\n");
//TODO set graphics of instance
}
//TODO set verbosity for solution graphics
solution2dotty(*problem, *solver);
// ofstream myfile;
// myfile.open ("solpbs.dot");
// myfile << "digraph G {" <<endl;
Expand Down
42 changes: 27 additions & 15 deletions src/graphviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ void node2dotty(ostream & out, FacilityNode* i,PSLProblem & problem, abstract_so
out << "];" << endl;
}

extern void flow2dotty(ostream & out, PSLProblem & problem, abstract_solver & solver, unsigned int stage)
void flow2dotty(ostream & out, PSLProblem & problem, abstract_solver & solver, unsigned int stage)
{
for(NodeIterator i = problem.nbegin() ; i!= problem.nend() ; i++) {
node2dotty(out, *i, problem, solver, stage);
}
for(LinkIterator l = problem.lbegin() ; l!= problem.lend() ; l++) {
CUDFcoefficient connections = solver.get_solution(problem.rankY(*l, stage));
out << l->getOrigin()->getID() << " . " << l->getDestination()->getID();
out << l->getOrigin()->getID() << " -> " << l->getDestination()->getID();
if(connections > 0) {
out << "[label=\"" << connections << "\"];\n";
} else {
Expand All @@ -64,13 +64,14 @@ extern void flow2dotty(ostream & out, PSLProblem & problem, abstract_solver & so



extern void flow2dotty(PSLProblem & problem, abstract_solver & solver)
void flow2dotty(PSLProblem & problem, abstract_solver & solver)
{
for (int i = 0; i < problem.stageCount(); ++i) {
ofstream myfile;
stringstream ss (stringstream::in);
stringstream ss (stringstream::in | stringstream::out);
ss << "flow-sol-" << i << ".dot";
myfile.open (ss.str().c_str());
//cout << "## " << ss.str() << endl;
myfile.open(ss.str().c_str());
myfile << "digraph F" << i << "{" <<endl;
flow2dotty(myfile, problem, solver, i);
myfile << endl << "}" << endl;
Expand All @@ -80,7 +81,7 @@ extern void flow2dotty(PSLProblem & problem, abstract_solver & solver)



extern void path2dotty(ostream& out, PSLProblem & problem, abstract_solver & solver, unsigned int stage)
void path2dotty(ostream& out, PSLProblem & problem, abstract_solver & solver, unsigned int stage)
{

for(NodeIterator i = problem.nbegin() ; i!= problem.nend() ; i++) {
Expand All @@ -90,35 +91,35 @@ extern void path2dotty(ostream& out, PSLProblem & problem, abstract_solver & sol
j++;
while(j != i->nend()) {
CUDFcoefficient connections = solver.get_solution(problem.rankZ(*i,*j, stage));
CUDFcoefficient bandwidth = solver.get_solution(problem.rankB(*i,*j, stage));
out << i->getID() << " . " << j->getID();
if(connections > 0) {
CUDFcoefficient bandwidth = solver.get_solution(problem.rankB(*i,*j, stage));
out << i->getID() << " -> " << j->getID();
out << "[label=\"" << connections <<
out<< "/" << (bandwidth) << "\"];\n";
//TODO convert bandwidth to Ko
"|" << bandwidth << "\"];" << endl;
}
j++;
}
}
}
//Add invisible arcs of the tree if needed
for(LinkIterator l = problem.lbegin() ; l!= problem.lend() ; l++) {
CUDFcoefficient connections = solver.get_solution(problem.rankZ(l->getOrigin(), l->getDestination(), stage));
if(connections == 0) {
out << l->getOrigin()->getID() << " . " << l->getDestination()->getID();
out << "[style=\"invis\"];\n";
out << l->getOrigin()->getID() << " -> " << l->getDestination()->getID();
out << "[style=\"invis\"];" <<endl;
}
}

}



extern void path2dotty(PSLProblem & problem, abstract_solver & solver)
void path2dotty(PSLProblem & problem, abstract_solver & solver)
{
for (int i = 1; i < problem.stageCount(); ++i) {
ofstream myfile;
stringstream ss (stringstream::in);
ss << "flow-sol-" << i << ".dot";
stringstream ss (stringstream::in | stringstream::out);
ss << "path-sol-" << i << ".dot";
myfile.open (ss.str().c_str());
myfile << "digraph P" << i << "{" <<endl;
path2dotty(myfile, problem, solver, i);
Expand All @@ -128,6 +129,17 @@ extern void path2dotty(PSLProblem & problem, abstract_solver & solver)
}


void inst2dotty(PSLProblem &problem) {
ofstream myfile;
myfile.open ("instance.dot");
problem.toDotty(myfile);
myfile.close();
}

void solution2dotty(PSLProblem &problem, abstract_solver& solver) {
flow2dotty(problem, solver);
path2dotty(problem, solver);
}



Expand Down
11 changes: 2 additions & 9 deletions src/graphviz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

using namespace std;


extern void inst2dotty(PSLProblem &problem);

extern void flow2dotty(ostream& out, PSLProblem& problem, abstract_solver& solver, unsigned int stage);

Expand All @@ -47,14 +47,7 @@ extern void path2dotty(ostream& out, PSLProblem &problem, abstract_solver& solve

extern void path2dotty(PSLProblem &problem, abstract_solver& solver);

void solution2dotty(PSLProblem &problem, abstract_solver& solver) {
ofstream myfile;
myfile.open ("instance.dot");
problem.toDotty(myfile);
myfile.close();
flow2dotty(problem, solver);
path2dotty(problem, solver);
}
extern void solution2dotty(PSLProblem &problem, abstract_solver& solver);


#endif /* GRAPHVIZ_HPP_ */

0 comments on commit d207c6d

Please sign in to comment.