Skip to content

Commit

Permalink
Define time limit and add pserv-location graphics #27
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Jul 23, 2012
1 parent 69c5887 commit 673fb94
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/cplex_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ int cplex_solver::init_solver(PSLProblem *problem, int other_vars) {
exit(-1);
}

/* Set the value of the time limit*/
status = CPXsetdblparam (env, CPX_PARAM_TILIM, PSL_TILIM);
if ( status ) {
fprintf (stderr, "Failure to set the time limit, error %d.\n", status);
exit(-1);
}

/* Enhance EPGAP to handle big values correctly */
status = CPXsetdblparam (env, CPX_PARAM_EPGAP, 0.0);
Expand All @@ -60,9 +66,9 @@ int cplex_solver::init_solver(PSLProblem *problem, int other_vars) {
/* MIP node log display information */
int verb = verbosity >= SEARCH ? 5 : verbosity >= VERBOSE ? 2 : 1;
status = CPXsetintparam (env, CPX_PARAM_MIPDISPLAY, verb);
// int val = -1;
// CPXgetintparam (env, CPX_PARAM_MIPDISPLAY, &val);
// cerr << val << endl;
// int val = -1;
// CPXgetintparam (env, CPX_PARAM_MIPDISPLAY, &val);
// cerr << val << endl;
if ( status ) {
fprintf (stderr, "Failure to turn off presolve, error %d.\n", status);
exit(-1);
Expand Down
3 changes: 1 addition & 2 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ int main(int argc, char *argv[]) {
PSLProblem *problem;

vector<abstract_criteria *> criteria_with_property; //TODO Remove useless list ?
//TODO Add seed parameter and logging message
// parameter handling
if (argc > 1) {
for (int i = 1; i < argc; i++) {
Expand Down Expand Up @@ -786,7 +785,7 @@ void print_messages(ostream & out, PSLProblem *problem, abstract_solver *solver)
spare_capa[s] = (capa-clients)/capa;
avg_spare_capa +=spare_capa[s];
}
out.precision(2);
out.precision(3);
avg_spare_capa/= problem->stageCount()-1;
out << "d SPARE_CAPA " << fixed << avg_spare_capa <<endl;
if(problem->stageCount() > 2) {
Expand Down
1 change: 1 addition & 0 deletions src/cudf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

using namespace std;

#define PSL_TILIM 900
#define C_STR( text ) ((char*)std::string( text ).c_str())

// current CUDF problem
Expand Down
56 changes: 54 additions & 2 deletions src/graphviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@


#define INST "cplexpb"
#define PSERV "sol-pserv"
#define FLOW "sol-flow-"
#define PATH "sol-path-"
#define DOT ".dot"
Expand Down Expand Up @@ -65,6 +66,56 @@ void stylePServers(ostream & out, const int servers) {
}
}

bool pserv2dotty(ostream & out,PSLProblem & problem, abstract_solver & solver, FacilityNode* i) {
bool display = false;
for(LinkListIterator l = i->cbegin() ; l!= i->cend() ; l++) {
display |= pserv2dotty(out, problem, solver, (*l)->getDestination());
}
CUDFcoefficient servers = solver.get_solution(problem.rankX(i));
if(servers > 0) {
out << i->getID() << "[shape=record, label=\"{{" << i->getID() << "|" << servers << "}|";
if(problem.serverTypeCount() > 1) {
out << "{" << solver.get_solution(problem.rankX(i, 0));
for (int k = 1; k < problem.serverTypeCount(); ++k) {
out << "|" << solver.get_solution(problem.rankX(i, k));
}
out << "}";
}
out << "}\"";
stylePServers(out, servers);
out << "];" << endl;
if (! i->isRoot()) {
i->toFather()->toDotty(out);
}
} else if(display) {
out << i->getID() << "[shape=box];" << endl;
if (! i->isRoot()) {
i->toFather()->toDotty(out);
}
}




return servers > 0;
}


void pserv2dotty(PSLProblem &problem, abstract_solver& solver, char* title) {
ofstream myfile;
stringstream ss (stringstream::in | stringstream::out);
ss << PSERV << DOT;
//cout << "## " << ss.str() << endl;
myfile.open(ss.str().c_str());
myfile << "digraph P" << "{" <<endl;
gtitle(myfile, title, 0);
pserv2dotty(myfile, problem, solver, problem.getRoot());
myfile << endl << "}" << endl;
myfile.close();

}


void node2dotty(ostream & out, FacilityNode* i,PSLProblem & problem, abstract_solver & solver, unsigned int stage) {
CUDFcoefficient demand = stage == 0 ?
solver.get_solution(problem.rankX(i)) : i->getType()->getDemand(stage-1);
Expand All @@ -73,11 +124,11 @@ void node2dotty(ostream & out, FacilityNode* i,PSLProblem & problem, abstract_so
out << i->getID();
out << "[shape=record, label=\"{";
if(showID) {
out << "{" << i->getID() << "|" << demand <<"}";
out << "{" << i->getID() << "|" << demand <<"}";
} else {
out << demand ;
}
if(stage> 0 && servers > 0 ) {
if(stage> 0 && servers > 0 ) {
out << "|{"<< servers << "|" << connections << "}";
}
out << "}\"";
Expand Down Expand Up @@ -223,6 +274,7 @@ void path2dotty(PSLProblem & problem, abstract_solver & solver, char* title)


void solution2dotty(PSLProblem &problem, abstract_solver& solver, char* title) {
pserv2dotty(problem, solver, title);
flow2dotty(problem, solver, title);
path2dotty(problem, solver, title);
}
Expand Down
2 changes: 2 additions & 0 deletions src/graphviz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ using namespace std;

extern void inst2dotty(PSLProblem &problem);

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

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

extern void path2dotty(ostream& out, PSLProblem &problem, abstract_solver& solver, unsigned int stage);
Expand Down
2 changes: 1 addition & 1 deletion src/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ class PSLProblem {
friend istream& operator>>(istream& in, PSLProblem& problem);

//----------------------------------------
// Rank Mapper (associates each variable to an uniue index)
// Rank Mapper (associates each variable to an unique index)
//----------------------------------------
int rankX(FacilityNode *node) const {
return node->getID();
Expand Down

0 comments on commit 673fb94

Please sign in to comment.