[174] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 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. |
---|
| 12 | * |
---|
| 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 |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[201] | 19 | #include "gui_writer.h" |
---|
| 20 | #include "io_helper.h" |
---|
| 21 | #include "mapstorage.h" |
---|
| 22 | #include "xml.h" |
---|
[150] | 23 | #include <lemon/dim2.h> |
---|
[98] | 24 | #include <vector> |
---|
| 25 | |
---|
[194] | 26 | #include <gui_writer.h> |
---|
| 27 | #include <mapstorage.h> |
---|
| 28 | |
---|
[98] | 29 | std::string GuiWriter::header() |
---|
| 30 | { |
---|
| 31 | return "@gui"; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void GuiWriter::write(std::ostream& os) |
---|
| 35 | { |
---|
[201] | 36 | using std::vector; |
---|
| 37 | using std::string; |
---|
| 38 | using std::map; |
---|
| 39 | using std::string; |
---|
| 40 | |
---|
[98] | 41 | XmlIo x(os); |
---|
[201] | 42 | |
---|
| 43 | vector<string> all_node_map_names = mapstorage->getNodeMapList(); |
---|
| 44 | // name of the maps saved to the nodeset section |
---|
| 45 | vector<string> main_node_map_names; |
---|
| 46 | // name of the maps saved to the gui section |
---|
| 47 | vector<string> gui_node_map_names; |
---|
| 48 | |
---|
| 49 | for (vector<string>::const_iterator it = all_node_map_names.begin(); |
---|
| 50 | it != all_node_map_names.end(); ++it) |
---|
[98] | 51 | { |
---|
[201] | 52 | if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT) |
---|
| 53 | main_node_map_names.push_back(*it); |
---|
| 54 | else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT) |
---|
| 55 | gui_node_map_names.push_back(*it); |
---|
[98] | 56 | } |
---|
[201] | 57 | |
---|
| 58 | { x("main_node_map_names", main_node_map_names); } |
---|
| 59 | { x("gui_node_map_names", gui_node_map_names); } |
---|
| 60 | |
---|
| 61 | map<string, MapValue::Type> node_map_types; |
---|
| 62 | for (vector<string>::const_iterator it = main_node_map_names.begin(); |
---|
| 63 | it != main_node_map_names.end(); ++it) |
---|
| 64 | { |
---|
| 65 | node_map_types[*it] = mapstorage->getNodeMapElementType(*it); |
---|
| 66 | } |
---|
| 67 | for (vector<string>::const_iterator it = gui_node_map_names.begin(); |
---|
| 68 | it != gui_node_map_names.end(); ++it) |
---|
| 69 | { |
---|
| 70 | node_map_types[*it] = mapstorage->getNodeMapElementType(*it); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | { x("node_map_types", node_map_types); } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | vector<string> all_edge_map_names = mapstorage->getEdgeMapList(); |
---|
| 77 | // name of the maps saved to the edgeset section |
---|
| 78 | vector<string> main_edge_map_names; |
---|
| 79 | // name of the maps saved to the gui section |
---|
| 80 | vector<string> gui_edge_map_names; |
---|
| 81 | |
---|
| 82 | for (vector<string>::const_iterator it = all_edge_map_names.begin(); |
---|
| 83 | it != all_edge_map_names.end(); ++it) |
---|
| 84 | { |
---|
| 85 | if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::NESET_SECT) |
---|
| 86 | main_edge_map_names.push_back(*it); |
---|
| 87 | if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::GUI_SECT) |
---|
| 88 | gui_edge_map_names.push_back(*it); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | { x("main_edge_map_names", main_edge_map_names); } |
---|
| 92 | { x("gui_edge_map_names", gui_edge_map_names); } |
---|
| 93 | |
---|
| 94 | map<string, MapValue::Type> edge_map_types; |
---|
| 95 | for (vector<string>::const_iterator it = main_edge_map_names.begin(); |
---|
| 96 | it != main_edge_map_names.end(); ++it) |
---|
| 97 | { |
---|
| 98 | edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it); |
---|
| 99 | } |
---|
| 100 | for (vector<string>::const_iterator it = gui_edge_map_names.begin(); |
---|
| 101 | it != gui_edge_map_names.end(); ++it) |
---|
| 102 | { |
---|
| 103 | edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | { x("edge_map_types", edge_map_types); } |
---|
| 107 | |
---|
| 108 | // write the gui node maps |
---|
| 109 | for (vector<string>::const_iterator it = gui_node_map_names.begin(); |
---|
| 110 | it != gui_node_map_names.end(); ++it) |
---|
| 111 | { |
---|
| 112 | MapValue::Type type = mapstorage->getNodeMapElementType(*it); |
---|
| 113 | const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap(); |
---|
| 114 | switch (type) |
---|
| 115 | { |
---|
| 116 | case MapValue::NUMERIC: |
---|
| 117 | { |
---|
| 118 | std::map<int, double> map_data; |
---|
| 119 | MapStorage::NumericNodeMap& map = |
---|
| 120 | mapstorage->getNumericNodeMap(*it); |
---|
| 121 | for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) |
---|
| 122 | { |
---|
| 123 | map_data[labels[n]] = map[n]; |
---|
| 124 | } |
---|
| 125 | { x(*it, map_data); } |
---|
| 126 | } |
---|
| 127 | break; |
---|
| 128 | case MapValue::STRING: |
---|
| 129 | { |
---|
| 130 | std::map<int, std::string> map_data; |
---|
| 131 | MapStorage::StringNodeMap& map = |
---|
| 132 | mapstorage->getStringNodeMap(*it); |
---|
| 133 | for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) |
---|
| 134 | { |
---|
| 135 | map_data[labels[n]] = map[n]; |
---|
| 136 | } |
---|
| 137 | { x(*it, map_data); } |
---|
| 138 | } |
---|
| 139 | break; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // write the gui edge maps |
---|
| 144 | for (vector<string>::const_iterator it = gui_edge_map_names.begin(); |
---|
| 145 | it != gui_edge_map_names.end(); ++it) |
---|
| 146 | { |
---|
| 147 | MapValue::Type type = mapstorage->getEdgeMapElementType(*it); |
---|
| 148 | const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap(); |
---|
| 149 | switch (type) |
---|
| 150 | { |
---|
| 151 | case MapValue::NUMERIC: |
---|
| 152 | { |
---|
| 153 | std::map<int, double> map_data; |
---|
| 154 | MapStorage::NumericEdgeMap& map = |
---|
| 155 | mapstorage->getNumericEdgeMap(*it); |
---|
| 156 | for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) |
---|
| 157 | { |
---|
| 158 | map_data[labels[e]] = map[e]; |
---|
| 159 | } |
---|
| 160 | { x(*it, map_data); } |
---|
| 161 | } |
---|
| 162 | break; |
---|
| 163 | case MapValue::STRING: |
---|
| 164 | { |
---|
| 165 | std::map<int, std::string> map_data; |
---|
| 166 | MapStorage::StringEdgeMap& map = |
---|
| 167 | mapstorage->getStringEdgeMap(*it); |
---|
| 168 | for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) |
---|
| 169 | { |
---|
| 170 | map_data[labels[e]] = map[e]; |
---|
| 171 | } |
---|
| 172 | { x(*it, map_data); } |
---|
| 173 | } |
---|
| 174 | break; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | { |
---|
| 179 | switch (mapstorage->getNodeCoordsSaveDest()) |
---|
| 180 | { |
---|
| 181 | case MapStorage::SpecMapSaveOpts::GUI_SECT: |
---|
| 182 | { x("node_coords_save_dest", string("gui_sect")); } |
---|
| 183 | // write the node coorinates |
---|
| 184 | { |
---|
| 185 | const MapStorage::NodeLabelMap& labels = |
---|
| 186 | mapstorage->getNodeLabelMap(); |
---|
| 187 | std::map<int, XY> node_coord_map; |
---|
| 188 | MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap(); |
---|
| 189 | for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) |
---|
| 190 | { |
---|
| 191 | node_coord_map[labels[n]] = map[n]; |
---|
| 192 | } |
---|
| 193 | { x("node_coord_map", node_coord_map); } |
---|
| 194 | } |
---|
| 195 | break; |
---|
| 196 | case MapStorage::SpecMapSaveOpts::NESET_SECT: |
---|
| 197 | switch (mapstorage->getNodeCoordsSaveMapNum()) |
---|
| 198 | { |
---|
| 199 | case MapStorage::SpecMapSaveOpts::ONE_MAP: |
---|
| 200 | { x("node_coords_save_dest", string("nodeset_sect_1_map")); } |
---|
| 201 | { x("map_name", mapstorage->getNodeCoordsOneMapName()); } |
---|
| 202 | break; |
---|
| 203 | case MapStorage::SpecMapSaveOpts::TWO_MAPS: |
---|
| 204 | { x("node_coords_save_dest", string("nodeset_sect_2_maps")); } |
---|
| 205 | { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); } |
---|
| 206 | { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); } |
---|
| 207 | break; |
---|
| 208 | } |
---|
| 209 | break; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | { |
---|
| 214 | switch (mapstorage->getArrowCoordsSaveDest()) |
---|
| 215 | { |
---|
| 216 | case MapStorage::SpecMapSaveOpts::GUI_SECT: |
---|
| 217 | { x("arrow_coords_save_dest", string("gui_sect")); } |
---|
| 218 | // write the arrow coorinates |
---|
| 219 | { |
---|
| 220 | const MapStorage::EdgeLabelMap& labels = |
---|
| 221 | mapstorage->getEdgeLabelMap(); |
---|
| 222 | std::map<int, XY> arrow_coord_map; |
---|
| 223 | MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap(); |
---|
| 224 | for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) |
---|
| 225 | { |
---|
| 226 | arrow_coord_map[labels[e]] = map[e]; |
---|
| 227 | } |
---|
| 228 | { x("arrow_coord_map", arrow_coord_map); } |
---|
| 229 | } |
---|
| 230 | break; |
---|
| 231 | case MapStorage::SpecMapSaveOpts::NESET_SECT: |
---|
| 232 | switch (mapstorage->getArrowCoordsSaveMapNum()) |
---|
| 233 | { |
---|
| 234 | case MapStorage::SpecMapSaveOpts::ONE_MAP: |
---|
| 235 | { x("arrow_coords_save_dest", string("edgeset_sect_1_map")); } |
---|
| 236 | { x("map_name", mapstorage->getArrowCoordsOneMapName()); } |
---|
| 237 | break; |
---|
| 238 | case MapStorage::SpecMapSaveOpts::TWO_MAPS: |
---|
| 239 | { x("arrow_coords_save_dest", string("edgeset_sect_2_maps")); } |
---|
| 240 | { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); } |
---|
| 241 | { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); } |
---|
| 242 | break; |
---|
| 243 | } |
---|
| 244 | break; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
[172] | 248 | |
---|
| 249 | std::map<int, std::string> nm; |
---|
| 250 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
| 251 | { |
---|
| 252 | nm[i]=mapstorage->active_nodemaps[i]; |
---|
| 253 | } |
---|
[201] | 254 | { x("active_nodemaps", nm); } |
---|
[172] | 255 | |
---|
| 256 | std::map<int, std::string> em; |
---|
| 257 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
| 258 | { |
---|
| 259 | em[i]=mapstorage->active_edgemaps[i]; |
---|
| 260 | } |
---|
[201] | 261 | { x("active_edgemaps", em); } |
---|
[177] | 262 | |
---|
| 263 | double attraction; |
---|
| 264 | double propulsation; |
---|
| 265 | int iteration; |
---|
| 266 | |
---|
| 267 | mapstorage->get_design_data(attraction, propulsation, iteration); |
---|
| 268 | |
---|
[201] | 269 | { x("redesign-attraction", attraction); } |
---|
| 270 | { x("redesign-propulsation", propulsation); } |
---|
| 271 | { x("redesign-iteration", iteration); } |
---|
[98] | 272 | } |
---|
| 273 | |
---|
[201] | 274 | GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : |
---|
| 275 | Parent(writer), |
---|
| 276 | mapstorage(ms) |
---|
[98] | 277 | { |
---|
| 278 | } |
---|