diff --git a/build/pl_rubberband.o b/build/pl_rubberband.o index 76387bb57ebd898ff65982d14db317b27a290352..c0db8b4816f3ce79f0d279d2df15e3b25980fc4a 100644 Binary files a/build/pl_rubberband.o and b/build/pl_rubberband.o differ diff --git a/data/graph_2 b/data/graph_2 index a80a2517d060db1a88f61ea252aecc9fd1653325..9c8ec7f2dcc10250610ef0034acb67f95136c325 100644 --- a/data/graph_2 +++ b/data/graph_2 @@ -31,5 +31,4 @@ 7 8 1.0 8 9 1.0 9 10 1.0 -10 11 1.0 - +10 11 1.0 \ No newline at end of file diff --git a/debug.lp.lp b/debug.lp.lp index fae2f9ed6a3070ee47a3d46824fc78be90fbae13..62d98d8949a80da244581af753d262fb9873e7ff 100644 --- a/debug.lp.lp +++ b/debug.lp.lp @@ -10013,9 +10013,23 @@ Bounds 0.58700 <= x2 <= 0.58700 -0.58700 <= x3 <= -0.58700 -0.95100 <= x4 <= -0.95100 + x5 Free + x6 Free + x7 Free + x8 Free + x9 Free + x10 Free + x11 Free 1 <= x12 <= 1 0.30900 <= x13 <= 0.30900 -0.80900 <= x14 <= -0.80900 -0.80900 <= x15 <= -0.80900 0.30900 <= x16 <= 0.30900 + x17 Free + x18 Free + x19 Free + x20 Free + x21 Free + x22 Free + x23 Free End diff --git a/graph.eps b/graph.eps index 058271a2a1e517f3a5011c65f574f6b52799b17a..99c3c1fe2877c3748d5c0051fe481bc7ebedd99d 100644 --- a/graph.eps +++ b/graph.eps @@ -1,6 +1,6 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Creator: LEMON, graphToEps() -%%CreationDate: Thu Dec 5 03:39:26 2019 +%%CreationDate: Thu Dec 5 15:07:12 2019 %%BoundingBox: -108 -94 108 113 %%EndComments /lb { setlinewidth setrgbcolor newpath moveto @@ -68,41 +68,41 @@ gsave 100 dup scale %Arcs: gsave -0 0 0 0.0680909 0 0 0 0.00787469 l -0.310636 0 0 0 0 0 0 0.00787469 l -0.457636 0.290727 0.310636 0 0 0 0 0.00787469 l -0.402 0.491727 0.457636 0.290727 0 0 0 0.00787469 l -0.201 0.382091 0 0.0680909 0 0 0 0.00787469 l -0.201 0.382091 0.310636 0 0 0 0 0.00787469 l -0.201 0.382091 0.457636 0.290727 0 0 0 0.00787469 l -0.201 0.382091 0.402 0.491727 0 0 0 0.00787469 l -0 0.436909 0 0.0680909 0 0 0 0.00787469 l -0 0.436909 0.201 0.382091 0 0 0 0.00787469 l --0.951 0.309 0 0.0680909 0 0 0 0.00787469 l --0.951 0.309 0 0.436909 0 0 0 0.00787469 l --0.587 -0.809 0 0.0680909 0 0 0 0.00787469 l --0.587 -0.809 0 0 0 0 0 0.00787469 l +-0.276364 -0.330545 -0.422545 -0.0199091 0 0 0 0.00787469 l +0.166727 -0.147818 -0.276364 -0.330545 0 0 0 0.00787469 l +0.366273 0.235909 0.166727 -0.147818 0 0 0 0.00787469 l +0.329727 0.473455 0.366273 0.235909 0 0 0 0.00787469 l +0.0190909 0.327273 -0.422545 -0.0199091 0 0 0 0.00787469 l +0.0190909 0.327273 0.166727 -0.147818 0 0 0 0.00787469 l +0.0190909 0.327273 0.366273 0.235909 0 0 0 0.00787469 l +0.0190909 0.327273 0.329727 0.473455 0 0 0 0.00787469 l +-0.331182 0.400364 -0.422545 -0.0199091 0 0 0 0.00787469 l +-0.331182 0.400364 0.0190909 0.327273 0 0 0 0.00787469 l +-0.951 0.309 -0.422545 -0.0199091 0 0 0 0.00787469 l +-0.951 0.309 -0.331182 0.400364 0 0 0 0.00787469 l +-0.587 -0.809 -0.422545 -0.0199091 0 0 0 0.00787469 l +-0.587 -0.809 -0.276364 -0.330545 0 0 0 0.00787469 l -0.587 -0.809 -0.951 0.309 0 0 0 0.00787469 l -0.587 -0.809 0.310636 0 0 0 0 0.00787469 l +0.587 -0.809 0.166727 -0.147818 0 0 0 0.00787469 l 0.587 -0.809 -0.587 -0.809 0 0 0 0.00787469 l -0.951 0.309 0.457636 0.290727 0 0 0 0.00787469 l -0.951 0.309 0.402 0.491727 0 0 0 0.00787469 l +0.951 0.309 0.366273 0.235909 0 0 0 0.00787469 l +0.951 0.309 0.329727 0.473455 0 0 0 0.00787469 l 0.951 0.309 0.587 -0.809 0 0 0 0.00787469 l -0 1 0.402 0.491727 0 0 0 0.00787469 l -0 1 0.201 0.382091 0 0 0 0.00787469 l -0 1 0 0.436909 0 0 0 0.00787469 l +0 1 0.329727 0.473455 0 0 0 0.00787469 l +0 1 0.0190909 0.327273 0 0 0 0.00787469 l +0 1 -0.331182 0.400364 0 0 0 0.00787469 l 0 1 -0.951 0.309 0 0 0 0.00787469 l 0 1 0.951 0.309 0 0 0 0.00787469 l grestore %Nodes: gsave -0 0.0680909 0.026249 1 1 1 nc -0 0 0.026249 1 1 1 nc -0.310636 0 0.026249 1 1 1 nc -0.457636 0.290727 0.026249 1 1 1 nc -0.402 0.491727 0.026249 1 1 1 nc -0.201 0.382091 0.026249 1 1 1 nc -0 0.436909 0.026249 1 1 1 nc +-0.422545 -0.0199091 0.026249 1 1 1 nc +-0.276364 -0.330545 0.026249 1 1 1 nc +0.166727 -0.147818 0.026249 1 1 1 nc +0.366273 0.235909 0.026249 1 1 1 nc +0.329727 0.473455 0.026249 1 1 1 nc +0.0190909 0.327273 0.026249 1 1 1 nc +-0.331182 0.400364 0.026249 1 1 1 nc -0.951 0.309 0.026249 1 1 1 nc -0.587 -0.809 0.026249 1 1 1 nc 0.587 -0.809 0.026249 1 1 1 nc diff --git a/output/graph_2.eps b/output/graph_2.eps new file mode 100644 index 0000000000000000000000000000000000000000..d1d42f3b8b76a028290b4ab9843cac4dcd090b11 --- /dev/null +++ b/output/graph_2.eps @@ -0,0 +1,113 @@ +%!PS-Adobe-2.0 EPSF-2.0 +%%Creator: LEMON, graphToEps() +%%CreationDate: Thu Dec 5 16:13:00 2019 +%%BoundingBox: -108 -94 108 113 +%%EndComments +/lb { setlinewidth setrgbcolor newpath moveto + 4 2 roll 1 index 1 index curveto stroke } bind def +/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def +/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def +/sq { newpath 2 index 1 index add 2 index 2 index add moveto + 2 index 1 index sub 2 index 2 index add lineto + 2 index 1 index sub 2 index 2 index sub lineto + 2 index 1 index add 2 index 2 index sub lineto + closepath pop pop pop} bind def +/di { newpath 2 index 1 index add 2 index moveto + 2 index 2 index 2 index add lineto + 2 index 1 index sub 2 index lineto + 2 index 2 index 2 index sub lineto + closepath pop pop pop} bind def +/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill + setrgbcolor 1.1 div c fill + } bind def +/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill + setrgbcolor 1.1 div sq fill + } bind def +/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill + setrgbcolor 1.1 div di fill + } bind def +/nfemale { 0 0 0 setrgbcolor 3 index 0.0909091 1.5 mul mul setlinewidth + newpath 5 index 5 index moveto 5 index 5 index 5 index 3.01 mul sub + lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub moveto + 5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto stroke + 5 index 5 index 5 index c fill + setrgbcolor 1.1 div c fill + } bind def +/nmale { + 0 0 0 setrgbcolor 3 index 0.0909091 1.5 mul mul setlinewidth + newpath 5 index 5 index moveto + 5 index 4 index 1 mul 1.5 mul add + 5 index 5 index 3 sqrt 1.5 mul mul add + 1 index 1 index lineto + 1 index 1 index 7 index sub moveto + 1 index 1 index lineto + exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub lineto + stroke + 5 index 5 index 5 index c fill + setrgbcolor 1.1 div c fill + } bind def +/arrl 1 def +/arrw 0.3 def +/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def +/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def + /w exch def /len exch def + newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto + len w sub arrl sub dx dy lrl + arrw dy dx neg lrl + dx arrl w add mul dy w 2 div arrw add mul sub + dy arrl w add mul dx w 2 div arrw add mul add rlineto + dx arrl w add mul neg dy w 2 div arrw add mul sub + dy arrl w add mul neg dx w 2 div arrw add mul add rlineto + arrw dy dx neg lrl + len w sub arrl sub neg dx dy lrl + closepath fill } bind def +/cshow { 2 index 2 index moveto dup stringwidth pop + neg 2 div fosi .35 mul neg rmoveto show pop pop} def + +gsave +100 dup scale +%Arcs: +gsave +-0.280883 -0.323493 -0.42839 -0.018524 0 0 0 0.00787469 l +0.173856 -0.141598 -0.280883 -0.323493 0 0 0 0.00787469 l +0.369568 0.240292 0.173856 -0.141598 0 0 0 0.00787469 l +0.33518 0.46834 0.369568 0.240292 0 0 0 0.00787469 l +0.018099 0.325358 -0.42839 -0.018524 0 0 0 0.00787469 l +0.018099 0.325358 0.173856 -0.141598 0 0 0 0.00787469 l +0.018099 0.325358 0.369568 0.240292 0 0 0 0.00787469 l +0.018099 0.325358 0.33518 0.46834 0 0 0 0.00787469 l +-0.33981 0.404089 -0.42839 -0.018524 0 0 0 0.00787469 l +-0.33981 0.404089 0.018099 0.325358 0 0 0 0.00787469 l +-0.951 0.309 -0.42839 -0.018524 0 0 0 0.00787469 l +-0.951 0.309 -0.33981 0.404089 0 0 0 0.00787469 l +-0.587 -0.809 -0.42839 -0.018524 0 0 0 0.00787469 l +-0.587 -0.809 -0.280883 -0.323493 0 0 0 0.00787469 l +-0.587 -0.809 -0.951 0.309 0 0 0 0.00787469 l +0.587 -0.809 0.173856 -0.141598 0 0 0 0.00787469 l +0.587 -0.809 -0.587 -0.809 0 0 0 0.00787469 l +0.951 0.309 0.369568 0.240292 0 0 0 0.00787469 l +0.951 0.309 0.33518 0.46834 0 0 0 0.00787469 l +0.951 0.309 0.587 -0.809 0 0 0 0.00787469 l +0 1 0.33518 0.46834 0 0 0 0.00787469 l +0 1 0.018099 0.325358 0 0 0 0.00787469 l +0 1 -0.33981 0.404089 0 0 0 0.00787469 l +0 1 -0.951 0.309 0 0 0 0.00787469 l +0 1 0.951 0.309 0 0 0 0.00787469 l +grestore +%Nodes: +gsave +-0.42839 -0.018524 0.026249 1 1 1 nc +-0.280883 -0.323493 0.026249 1 1 1 nc +0.173856 -0.141598 0.026249 1 1 1 nc +0.369568 0.240292 0.026249 1 1 1 nc +0.33518 0.46834 0.026249 1 1 1 nc +0.018099 0.325358 0.026249 1 1 1 nc +-0.33981 0.404089 0.026249 1 1 1 nc +-0.951 0.309 0.026249 1 1 1 nc +-0.587 -0.809 0.026249 1 1 1 nc +0.587 -0.809 0.026249 1 1 1 nc +0.951 0.309 0.026249 1 1 1 nc +0 1 0.026249 1 1 1 nc +grestore +grestore +showpage diff --git a/pl_rubberband.out b/pl_rubberband.out index e879d13d69e39f761a6066b99d4ac257a5a1746e..a19bd6fbcd7fbbe073d07440378c2a9706c3e34f 100755 Binary files a/pl_rubberband.out and b/pl_rubberband.out differ diff --git a/src/pl_rubberband.cpp b/src/pl_rubberband.cpp index bc2236f12e4d7610a1832bdc9ddb593b25be1592..0408bf906434d12037cdb02ba2e09b62c04fa6a6 100644 --- a/src/pl_rubberband.cpp +++ b/src/pl_rubberband.cpp @@ -35,6 +35,9 @@ void parse(std::string & file_name) { std::ifstream in(file_name); int s; in >> n >> m >> s; + + assert(n > s && m > 1 && s > 2); + create_nodes(n); for(int i=0; i<s; i++) { int v; @@ -49,6 +52,14 @@ void parse(std::string & file_name) { create_edge(u, v, strength); } } +std::string getFileName(const std::string& s) { + char sep = '/'; + size_t i = s.rfind(sep, s.length()); + if (i != std::string::npos) { + return(s.substr(i+1, s.length() - i)); + } + return(""); +} int main (int argc, const char *argv[]) { if(argc < 3) { @@ -58,7 +69,7 @@ int main (int argc, const char *argv[]) { std::string file_name = argv[1]; const int g = std::atoi(argv[2]); - parse(file_name); + parse(file_name); double max_d2 = 0; for( auto const& [_, p1] : nailed_nodes ) { @@ -109,8 +120,8 @@ int main (int argc, const char *argv[]) { OsiClpSolver_Builder * solver_builder = new OsiClpSolver_Builder(); - solver_builder->addVarType(x_var_number, NULL, NULL, 0, solver_builder->infty()); - solver_builder->addVarType(y_var_number, NULL, NULL, 0, solver_builder->infty()); + solver_builder->addVarType(x_var_number, NULL, NULL, -solver_builder->infty(), solver_builder->infty()); + solver_builder->addVarType(y_var_number, NULL, NULL, -solver_builder->infty(), solver_builder->infty()); solver_builder->addVarType(x2_var_number, NULL, NULL, 0, solver_builder->infty()); solver_builder->addVarType(y2_var_number, NULL, NULL, 0, solver_builder->infty()); solver_builder->init(); @@ -166,7 +177,7 @@ int main (int argc, const char *argv[]) { OsiClpSolverInterface * solver = solver_builder->buildSolver(OsiClpSolver_Builder::MIN); - solver->writeLp("debug.lp"); + // solver->writeLp("debug.lp"); solver->resolve(); const double * solution = solver->getColSolution(); @@ -179,8 +190,15 @@ int main (int argc, const char *argv[]) { coordsMap[u] = Point_t(x_u, y_u); } - lemon::graphToEps(graph, "graph.eps").coords(coordsMap).run(); + // eps output + std::string output = "output/" + getFileName(file_name) + ".eps"; + lemon::graphToEps(graph, output).coords(coordsMap).run(); + // open eps file + std::string command = "xdg-open " + output; + if(std::system(command.c_str()) != 0) + std::cerr << "failed to launch \"" << command << "\" , open it manually, cheers." << std::endl; + // python output std::cout << "["; Graph_t::NodeIt u(graph); Point_t & p = coordsMap[u]; @@ -191,7 +209,7 @@ int main (int argc, const char *argv[]) { } std::cout << "]" << std::endl << "["; Graph_t::EdgeIt e(graph); - std::cout << "(" << graph.id(graph.u(e)) << ", " << graph.id(graph.v(e)) << ")"; + std::cout << "(" << graph.id(graph.u(e)) << ", " << graph.id(graph.v(e)) << ")"; for(++e; e != lemon::INVALID; ++e) { std::cout << ", (" << graph.id(graph.u(e)) << ", " << graph.id(graph.v(e)) << ")"; } diff --git a/tmp.py b/tmp.py index 0857179ece40c1edfe44fa97353d3f928c73d791..2a8674fef19e0b0dbc6e1950623f858d473df71a 100644 --- a/tmp.py +++ b/tmp.py @@ -3,10 +3,9 @@ import math center_x = 0 center_y = 0 radius = 1 - nb_vertices = 5 - angle = 2 * math.pi / nb_vertices + for i in range(nb_vertices): x = center_x + radius * math.sin(i * angle) y = center_y + radius * math.cos(i * angle)