Add missing export.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include "mapstorage.h"
20 #include "gui_writer.h"
21 #include "gui_reader.h"
27 const double a_d=0.05;
28 const double p_d=40000;
30 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d)
32 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
33 coords.setXMap(*nodemap_storage["coordinates_x"]);
34 nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
35 coords.setYMap(*nodemap_storage["coordinates_y"]);
37 edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
38 arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
39 edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
40 arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
42 nodemap_storage["label"] = new Graph::NodeMap<double>(graph);
43 edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
45 nodemap_default["label"] = 1.0;
46 edgemap_default["label"] = 1.0;
48 active_nodemaps.resize(NODE_PROPERTY_NUM);
49 for(int i=0;i<NODE_PROPERTY_NUM;i++)
51 active_nodemaps[i]="";
54 active_edgemaps.resize(EDGE_PROPERTY_NUM);
55 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
57 active_edgemaps[i]="";
61 MapStorage::~MapStorage()
63 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
64 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
68 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
69 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
75 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
77 if( nodemap_storage.find(name) == nodemap_storage.end() )
79 nodemap_storage[name]=nodemap;
80 // set the maps default value
81 nodemap_default[name] = default_value;
83 //announce changement in maps
84 signal_node_map.emit(name);
90 void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname)
94 active_edgemaps[prop]=mapname;
98 active_nodemaps[prop]=mapname;
100 signal_prop.emit(itisedge, prop);
103 void MapStorage::broadcastActiveMaps()
105 for(int i=0;i<NODE_PROPERTY_NUM;i++)
107 signal_map_win.emit(false, i, active_nodemaps[i]);
110 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
112 signal_map_win.emit(true, i, active_edgemaps[i]);
117 std::string MapStorage::getActiveEdgeMap(int prop)
119 return active_edgemaps[prop];
122 std::string MapStorage::getActiveNodeMap(int prop)
124 return active_nodemaps[prop];
127 std::vector<std::string> MapStorage::getEdgeMapList()
129 std::vector<std::string> eml;
130 eml.resize(edgemap_storage.size());
132 std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps();
133 for(;emsi!=endOfEdgeMaps();emsi++)
135 eml[i]=(emsi->first);
141 std::vector<std::string> MapStorage::getNodeMapList()
143 std::vector<std::string> nml;
144 nml.resize(nodemap_storage.size());
146 std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps();
147 for(;nmsi!=endOfNodeMaps();nmsi++)
149 nml[i]=(nmsi->first);
155 sigc::signal<void, bool, int> MapStorage::signal_prop_ch()
160 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value)
162 if( edgemap_storage.find(name) == edgemap_storage.end() )
164 edgemap_storage[name]=edgemap;
165 // set the maps default value
166 edgemap_default[name] = default_value;
168 //announce changement in maps
169 signal_edge_map.emit(name);
175 double MapStorage::maxOfNodeMap(const std::string & name)
178 for (NodeIt j(graph); j!=INVALID; ++j)
180 if( (*nodemap_storage[name])[j]>max )
182 max=(*nodemap_storage[name])[j];
188 double MapStorage::maxOfEdgeMap(const std::string & name)
191 for (EdgeIt j(graph); j!=INVALID; ++j)
193 if( (*edgemap_storage[name])[j]>max )
195 max=(*edgemap_storage[name])[j];
201 double MapStorage::minOfNodeMap(const std::string & name)
207 min=(*nodemap_storage[name])[j];
213 for (; j!=INVALID; ++j)
215 if( (*nodemap_storage[name])[j]<min )
217 min=(*nodemap_storage[name])[j];
223 double MapStorage::minOfEdgeMap(const std::string & name)
229 min=(*edgemap_storage[name])[j];
235 for (EdgeIt j(graph); j!=INVALID; ++j)
237 if( (*edgemap_storage[name])[j]<min )
239 min=(*edgemap_storage[name])[j];
245 int MapStorage::readFromFile(const std::string &filename)
249 bool read_edge_id = false;
252 LemonReader lreader(filename);
253 ContentReader content(lreader);
256 if (content.nodeSetNum() < 1)
258 Gtk::MessageDialog mdialog("No nodeset found in file.");
264 if (content.edgeSetNum() < 1)
266 Gtk::MessageDialog mdialog("No edgeset found in file.");
272 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
273 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
275 GraphReader<Graph> greader(filename, graph);
276 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
277 it != nodeMapNames.end(); ++it)
279 if (*it == "coordinates_x")
282 //std::cout << "read X nodemap" << std::endl;
284 else if (*it == "coordinates_y")
287 //std::cout << "read Y nodemap" << std::endl;
289 else if (*it == "label")
291 //std::cout << "read id nodemap" << std::endl;
295 nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
296 //std::cout << "read " << *it << " nodemap" << std::endl;
298 greader.readNodeMap(*it, *nodemap_storage[*it]);
300 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
301 it != edgeMapNames.end(); ++it)
305 //std::cout << "read id edgemap" << std::endl;
310 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
311 //std::cout << "read " << *it << " edgemap" << std::endl;
313 greader.readEdgeMap(*it, *edgemap_storage[*it]);
315 GuiReader gui_reader(greader, this);
317 } catch (Exception& error) {
318 Gtk::MessageDialog mdialog(error.what());
326 edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
328 for (EdgeIt e(graph); e != INVALID; ++e)
330 (*edgemap_storage["label"])[e] = i++;
334 if (!read_x || !read_y)
337 for (NodeIt n(graph); n != INVALID; ++n)
341 const double pi = 3.142;
342 double step = 2 * pi / (double) node_num;
344 for (NodeIt n(graph); n != INVALID; ++n)
346 nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
347 nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
352 if (!arrow_pos_read_ok)
354 arrow_pos_read_ok = false;
355 for (EdgeIt e(graph); e != INVALID; ++e)
357 if (graph.source(e) == graph.target(e))
359 arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0));
363 arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
368 // fill in the default values for the maps
369 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
370 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
372 if ((it->first != "label") &&
373 (it->first != "coordiantes_x") &&
374 (it->first != "coordinates_y"))
376 nodemap_default[it->first] = 0.0;
378 else if (it->first == "label")
381 double max = (*nodemap_storage["label"])[n];
382 for (; n != INVALID; ++n)
384 if ((*nodemap_storage["label"])[n] > max)
385 max = (*nodemap_storage["label"])[n];
387 nodemap_default["label"] = max + 1.0;
390 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
391 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
393 if (it->first != "label")
395 edgemap_default[it->first] = 0.0;
399 double max = std::numeric_limits<double>::min();
400 for (EdgeIt e(graph); e != INVALID; ++e)
402 if ((*edgemap_storage["label"])[e] > max)
403 max = (*edgemap_storage["label"])[e];
405 if (max > std::numeric_limits<double>::min())
406 edgemap_default["label"] = max + 1.0;
408 edgemap_default["label"] = 1.0;
415 void MapStorage::writeToFile(const std::string &filename)
417 GraphWriter<Graph> gwriter(filename, graph);
419 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
420 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
422 gwriter.writeNodeMap(it->first, *(it->second));
424 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
425 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
427 if ((it->first != "arrow_pos_x") &&
428 (it->first != "arrow_pos_y"))
430 gwriter.writeEdgeMap(it->first, *(it->second));
434 GuiWriter gui_writer(gwriter, this);
439 void MapStorage::clear()
441 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
442 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
444 if ((it->first != "coordinates_x") &&
445 (it->first != "coordinates_y") &&
446 (it->first != "label"))
449 nodemap_storage.erase(it);
452 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
453 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
455 if ((it->first != "label") &&
456 (it->first != "arrow_pos_x") &&
457 (it->first != "arrow_pos_y"))
460 edgemap_storage.erase(it);
463 for (std::map<std::string, double>::iterator it =
464 nodemap_default.begin(); it != nodemap_default.end(); ++it)
466 if (it->first != "label")
467 nodemap_default.erase(it);
469 for (std::map<std::string, double>::iterator it =
470 edgemap_default.begin(); it != edgemap_default.end(); ++it)
472 if (it->first != "label")
473 edgemap_default.erase(it);
479 arrow_pos_read_ok = false;
481 for(int i=0;i<NODE_PROPERTY_NUM;i++)
483 changeActiveMap(false, i, "");
484 signal_map_win.emit(false, i, "");
487 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
489 changeActiveMap(true, i, "");
490 signal_map_win.emit(true, i, "");
497 signal_design_win.emit(attraction, propulsation, iterations);
500 void MapStorage::ArrowPosReadOK()
502 arrow_pos_read_ok = true;
505 void MapStorage::mapChanged(bool itisedge, std::string mapname)
509 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
511 if(active_edgemaps[i]==mapname)
513 signal_prop.emit(itisedge, i);
519 for(int i=0;i<NODE_PROPERTY_NUM;i++)
521 if(active_nodemaps[i]==mapname)
523 signal_prop.emit(itisedge, i);
529 void MapStorage::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p)
531 attraction_p=attraction;
532 propulsation_p=propulsation;
533 iterations_p=iterations;
536 void MapStorage::set_attraction(double attraction_p)
538 attraction=attraction_p;
541 void MapStorage::set_propulsation(double propulsation_p)
543 propulsation=propulsation_p;
546 void MapStorage::set_iteration(int iterations_p)
548 iterations=iterations_p;
551 void MapStorage::redesign_data_changed()
553 signal_design_win.emit(attraction, propulsation, iterations);