Skip to content

Commit

Permalink
add graph decorations #18
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Jun 8, 2012
1 parent 06add63 commit 10d7c42
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 15 deletions.
2 changes: 1 addition & 1 deletion benchmarks/instances/sample-server.dat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
4
2 20 100 1000
2000 20000 100000 1000000
1
500 1
1
Expand Down
2 changes: 1 addition & 1 deletion src/constraint_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


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

struct SetPathCoeff {

Expand Down
2 changes: 1 addition & 1 deletion src/cplex_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
int first_objective;

double *cplex_coeff; // cplex coefficients are doubles ...
//TODO pourquoi des double et pas des CUDFcoefficient ? Pour cplex ...
//pourquoi des double et pas des CUDFcoefficient ? toujours pour cplex ...
double *lb; // array of lower bounds
double *ub; // array of upper bounds
char *vartype; // array of variable types
Expand Down
6 changes: 3 additions & 3 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ int main(int argc, char *argv[]) {

PSLProblem* current_problem = NULL;
PSLProblem* the_problem = NULL;
int verbosity = 5; //TODO initialize verbosity
int verbosity = 5;

int parse_pslp(istream& in)
{
Expand All @@ -791,8 +791,8 @@ int parse_pslp(istream& in)
in >> *the_problem;
//TODO add option for the_problem->setSeed(seed);
//TODO add option for hierarchical network
bool hierarchical=true;
the_problem->generateNetwork(hierarchical);
bool hierarchic=true;
the_problem->generateNetwork(hierarchic);
return 0;
}

Expand Down
83 changes: 77 additions & 6 deletions src/graphviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@

#include "graphviz.hpp"

void stylePServers(ostream & out, const int servers) {
switch (servers) {
case 0: out << ",style=dashed"; break;
case 1:break;
case 2: out << ",style=filled,fillcolor=lightgoldenrod";break;
case 3: out << ",style=filled,fillcolor=palegreen";break;
case 4: out << ",style=filled,fillcolor=lightseagreen";break;
default:
out << ",style=filled,fillcolor=salmon";break;
break;
}
}

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 @@ -43,12 +56,28 @@ void node2dotty(ostream & out, FacilityNode* i,PSLProblem & problem, abstract_so
out << "{" << demand << "|" << servers << "|" << connections << "}";
}
out << "}\"";
if(connections > 0) {
out << ",style=filled";
}
stylePServers(out, servers);
out << "];" << endl;
}

void colorConnection(ostream & out, const int connections) {
if(connections >= 50) {
if(connections >= 1000) {
out << ",color=firebrick";
} else if(connections >= 500) {
out << ",color=salmon";
} else if(connections >= 250) {

out << ",color=midnightblue";
//out << ",color=seagreen";
}else if(connections >= 100) {
out << ",color=seagreen";
} else {
out << ",color=darkgoldenrod";
}
}
}

void flow2dotty(ostream & out, PSLProblem & problem, abstract_solver & solver, unsigned int stage)
{
for(NodeIterator i = problem.nbegin() ; i!= problem.nend() ; i++) {
Expand All @@ -58,7 +87,12 @@ void flow2dotty(ostream & out, PSLProblem & problem, abstract_solver & solver, u
CUDFcoefficient connections = solver.get_solution(problem.rankY(*l, stage));
out << l->getOrigin()->getID() << " -> " << l->getDestination()->getID();
if(connections > 0) {
out << "[label=\"" << connections << "\"];\n";
out << "[label=\"" << connections << "\"";
colorConnection(out, connections);
if (l->isReliable()) {
out << ", style=bold ";
}
out <<"];" << endl;
} else {
out << "[style=\"invis\"];\n";
}
Expand All @@ -83,6 +117,35 @@ void flow2dotty(PSLProblem & problem, abstract_solver & solver)
}


void colorUnitBandwidth(ostream & out, const double unitBandwidth) {
if(unitBandwidth >= 10) {
if(unitBandwidth >= 1000) {
out << ",color=firebrick";
} else if(unitBandwidth >= 250) {
out << ",color=salmon";
} else if(unitBandwidth >= 100) {

out << ",color=midnightblue";
//out << ",color=seagreen";
}else if(unitBandwidth >= 50) {
out << ",color=seagreen";
} else {
out << ",color=darkgoldenrod";
}
}
}

bool isReliablePath(const FacilityNode* origin, FacilityNode* destination) {
while(destination != origin) {
if(destination->toFather()->isReliable()) {
destination = destination->getFather();
if(!destination) {
return false;
}
}else return false;
}
return true;
}

void path2dotty(ostream& out, PSLProblem & problem, abstract_solver & solver, unsigned int stage)
{
Expand All @@ -95,10 +158,17 @@ void path2dotty(ostream& out, PSLProblem & problem, abstract_solver & solver, un
while(j != i->nend()) {
CUDFcoefficient connections = solver.get_solution(problem.rankZ(*i,*j, stage));
if(connections > 0) {
CUDFcoefficient bandwidth = solver.get_solution(problem.rankB(*i,*j, stage));
double bandwidth = solver.get_solution(problem.rankB(*i,*j, stage));
bandwidth/=connections;
out.precision(1);
out << i->getID() << " -> " << j->getID();
out << "[label=\"" << connections <<
"|" << bandwidth << "\"];" << endl;
"\\n" << scientific << bandwidth << "\"";
colorUnitBandwidth(out, bandwidth);
if (isReliablePath(*i, *j)) {
out << ", style=bold ";
}
out << "];" << endl;
}
j++;
}
Expand Down Expand Up @@ -147,3 +217,4 @@ void solution2dotty(PSLProblem &problem, abstract_solver& solver) {




3 changes: 2 additions & 1 deletion src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ NetworkLink::NetworkLink(unsigned int id, FacilityNode* father,
}

ostream& NetworkLink::toDotty(ostream & out) {
out.precision(1);
out << origin->getID() << " -> " << destination->getID();
out << "[label=\"" << getBandwidth() << "\"";
out << "[label=\"" << scientific << double(getBandwidth()) << "\"";
if (isReliable()) {
out << ", style=bold ";
}
Expand Down
2 changes: 0 additions & 2 deletions src/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,13 @@ class PSLProblem {
inline unsigned int levelCount() const {
return levelNodeCounts.size();
}
//TODO inline bool isValid();

void setSeed(const unsigned int seed);
FacilityNode* generateNetwork();

//generate Breadth-First Numbered Tree
FacilityNode* generateNetwork(bool hierarchic);

//TODO change visibility to network
bool checkNetwork();
bool checkNetworkHierarchy();
inline FacilityNode* getRoot() const {
Expand Down

0 comments on commit 10d7c42

Please sign in to comment.