1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gui_writer.cc Mon Jul 07 08:10:39 2008 -0500
1.3 @@ -0,0 +1,281 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include "gui_writer.h"
1.23 +#include "io_helper.h"
1.24 +#include "mapstorage.h"
1.25 +#include "xml.h"
1.26 +#include <lemon/dim2.h>
1.27 +#include <vector>
1.28 +
1.29 +#include <gui_writer.h>
1.30 +#include <mapstorage.h>
1.31 +
1.32 +// std::string GuiWriter::header()
1.33 +// {
1.34 +// return "@gui";
1.35 +// }
1.36 +
1.37 +void GuiWriter::write(std::ostream& os)
1.38 +{
1.39 + using std::vector;
1.40 + using std::string;
1.41 + using std::map;
1.42 + using std::string;
1.43 +
1.44 + os << "@gui" << std::endl;
1.45 +
1.46 + XmlIo x(os);
1.47 +
1.48 + vector<string> all_node_map_names = mapstorage->getNodeMapList();
1.49 + // name of the maps saved to the nodeset section
1.50 + vector<string> main_node_map_names;
1.51 + // name of the maps saved to the gui section
1.52 + vector<string> gui_node_map_names;
1.53 +
1.54 + for (vector<string>::const_iterator it = all_node_map_names.begin();
1.55 + it != all_node_map_names.end(); ++it)
1.56 + {
1.57 + if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT)
1.58 + main_node_map_names.push_back(*it);
1.59 + else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT)
1.60 + gui_node_map_names.push_back(*it);
1.61 + }
1.62 +
1.63 + { x("main_node_map_names", main_node_map_names); }
1.64 + { x("gui_node_map_names", gui_node_map_names); }
1.65 +
1.66 + map<string, MapValue::Type> node_map_types;
1.67 + for (vector<string>::const_iterator it = main_node_map_names.begin();
1.68 + it != main_node_map_names.end(); ++it)
1.69 + {
1.70 + node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
1.71 + }
1.72 + for (vector<string>::const_iterator it = gui_node_map_names.begin();
1.73 + it != gui_node_map_names.end(); ++it)
1.74 + {
1.75 + node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
1.76 + }
1.77 +
1.78 + { x("node_map_types", node_map_types); }
1.79 +
1.80 +
1.81 + vector<string> all_arc_map_names = mapstorage->getArcMapList();
1.82 + // name of the maps saved to the arcset section
1.83 + vector<string> main_arc_map_names;
1.84 + // name of the maps saved to the gui section
1.85 + vector<string> gui_arc_map_names;
1.86 +
1.87 + for (vector<string>::const_iterator it = all_arc_map_names.begin();
1.88 + it != all_arc_map_names.end(); ++it)
1.89 + {
1.90 + if (mapstorage->getArcMapSaveDest(*it) == MapStorage::NESET_SECT)
1.91 + main_arc_map_names.push_back(*it);
1.92 + if (mapstorage->getArcMapSaveDest(*it) == MapStorage::GUI_SECT)
1.93 + gui_arc_map_names.push_back(*it);
1.94 + }
1.95 +
1.96 + { x("main_arc_map_names", main_arc_map_names); }
1.97 + { x("gui_arc_map_names", gui_arc_map_names); }
1.98 +
1.99 + map<string, MapValue::Type> arc_map_types;
1.100 + for (vector<string>::const_iterator it = main_arc_map_names.begin();
1.101 + it != main_arc_map_names.end(); ++it)
1.102 + {
1.103 + arc_map_types[*it] = mapstorage->getArcMapElementType(*it);
1.104 + }
1.105 + for (vector<string>::const_iterator it = gui_arc_map_names.begin();
1.106 + it != gui_arc_map_names.end(); ++it)
1.107 + {
1.108 + arc_map_types[*it] = mapstorage->getArcMapElementType(*it);
1.109 + }
1.110 +
1.111 + { x("arc_map_types", arc_map_types); }
1.112 +
1.113 + // write the gui node maps
1.114 + for (vector<string>::const_iterator it = gui_node_map_names.begin();
1.115 + it != gui_node_map_names.end(); ++it)
1.116 + {
1.117 + MapValue::Type type = mapstorage->getNodeMapElementType(*it);
1.118 + const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap();
1.119 + switch (type)
1.120 + {
1.121 + case MapValue::NUMERIC:
1.122 + {
1.123 + std::map<int, double> map_data;
1.124 + MapStorage::NumericNodeMap& map =
1.125 + mapstorage->getNumericNodeMap(*it);
1.126 + for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n)
1.127 + {
1.128 + map_data[labels[n]] = map[n];
1.129 + }
1.130 + { x(*it, map_data); }
1.131 + }
1.132 + break;
1.133 + case MapValue::STRING:
1.134 + {
1.135 + std::map<int, std::string> map_data;
1.136 + MapStorage::StringNodeMap& map =
1.137 + mapstorage->getStringNodeMap(*it);
1.138 + for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n)
1.139 + {
1.140 + map_data[labels[n]] = map[n];
1.141 + }
1.142 + { x(*it, map_data); }
1.143 + }
1.144 + break;
1.145 + }
1.146 + }
1.147 +
1.148 + // write the gui arc maps
1.149 + for (vector<string>::const_iterator it = gui_arc_map_names.begin();
1.150 + it != gui_arc_map_names.end(); ++it)
1.151 + {
1.152 + MapValue::Type type = mapstorage->getArcMapElementType(*it);
1.153 + const MapStorage::ArcLabelMap& labels = mapstorage->getArcLabelMap();
1.154 + switch (type)
1.155 + {
1.156 + case MapValue::NUMERIC:
1.157 + {
1.158 + std::map<int, double> map_data;
1.159 + MapStorage::NumericArcMap& map =
1.160 + mapstorage->getNumericArcMap(*it);
1.161 + for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e)
1.162 + {
1.163 + map_data[labels[e]] = map[e];
1.164 + }
1.165 + { x(*it, map_data); }
1.166 + }
1.167 + break;
1.168 + case MapValue::STRING:
1.169 + {
1.170 + std::map<int, std::string> map_data;
1.171 + MapStorage::StringArcMap& map =
1.172 + mapstorage->getStringArcMap(*it);
1.173 + for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e)
1.174 + {
1.175 + map_data[labels[e]] = map[e];
1.176 + }
1.177 + { x(*it, map_data); }
1.178 + }
1.179 + break;
1.180 + }
1.181 + }
1.182 +
1.183 + {
1.184 + switch (mapstorage->getNodeCoordsSaveDest())
1.185 + {
1.186 + case MapStorage::SpecMapSaveOpts::GUI_SECT:
1.187 + { x("node_coords_save_dest", string("gui_sect")); }
1.188 + // write the node coorinates
1.189 + {
1.190 + const MapStorage::NodeLabelMap& labels =
1.191 + mapstorage->getNodeLabelMap();
1.192 + std::map<int, XY> node_coord_map;
1.193 + MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
1.194 + for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n)
1.195 + {
1.196 + node_coord_map[labels[n]] = map[n];
1.197 + }
1.198 + { x("node_coord_map", node_coord_map); }
1.199 + }
1.200 + break;
1.201 + case MapStorage::SpecMapSaveOpts::NESET_SECT:
1.202 + switch (mapstorage->getNodeCoordsSaveMapNum())
1.203 + {
1.204 + case MapStorage::SpecMapSaveOpts::ONE_MAP:
1.205 + { x("node_coords_save_dest", string("nodeset_sect_1_map")); }
1.206 + { x("map_name", mapstorage->getNodeCoordsOneMapName()); }
1.207 + break;
1.208 + case MapStorage::SpecMapSaveOpts::TWO_MAPS:
1.209 + { x("node_coords_save_dest", string("nodeset_sect_2_maps")); }
1.210 + { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); }
1.211 + { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); }
1.212 + break;
1.213 + }
1.214 + break;
1.215 + }
1.216 + }
1.217 +
1.218 + {
1.219 + switch (mapstorage->getArrowCoordsSaveDest())
1.220 + {
1.221 + case MapStorage::SpecMapSaveOpts::GUI_SECT:
1.222 + { x("arrow_coords_save_dest", string("gui_sect")); }
1.223 + // write the arrow coorinates
1.224 + {
1.225 + const MapStorage::ArcLabelMap& labels =
1.226 + mapstorage->getArcLabelMap();
1.227 + std::map<int, XY> arrow_coord_map;
1.228 + MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
1.229 + for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e)
1.230 + {
1.231 + arrow_coord_map[labels[e]] = map[e];
1.232 + }
1.233 + { x("arrow_coord_map", arrow_coord_map); }
1.234 + }
1.235 + break;
1.236 + case MapStorage::SpecMapSaveOpts::NESET_SECT:
1.237 + switch (mapstorage->getArrowCoordsSaveMapNum())
1.238 + {
1.239 + case MapStorage::SpecMapSaveOpts::ONE_MAP:
1.240 + { x("arrow_coords_save_dest", string("arcset_sect_1_map")); }
1.241 + { x("map_name", mapstorage->getArrowCoordsOneMapName()); }
1.242 + break;
1.243 + case MapStorage::SpecMapSaveOpts::TWO_MAPS:
1.244 + { x("arrow_coords_save_dest", string("arcset_sect_2_maps")); }
1.245 + { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); }
1.246 + { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); }
1.247 + break;
1.248 + }
1.249 + break;
1.250 + }
1.251 + }
1.252 +
1.253 +
1.254 + std::map<int, std::string> nm;
1.255 + for(int i=0;i<NODE_PROPERTY_NUM;i++)
1.256 + {
1.257 + nm[i]=mapstorage->active_nodemaps[i];
1.258 + }
1.259 + { x("active_nodemaps", nm); }
1.260 +
1.261 + std::map<int, std::string> em;
1.262 + for(int i=0;i<EDGE_PROPERTY_NUM;i++)
1.263 + {
1.264 + em[i]=mapstorage->active_arcmaps[i];
1.265 + }
1.266 + { x("active_arcmaps", em); }
1.267 +
1.268 + double attraction;
1.269 + double propulsation;
1.270 + int iteration;
1.271 +
1.272 + mapstorage->get_design_data(attraction, propulsation, iteration);
1.273 +
1.274 + { x("redesign-attraction", attraction); }
1.275 + { x("redesign-propulsation", propulsation); }
1.276 + { x("redesign-iteration", iteration); }
1.277 +}
1.278 +
1.279 +//GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) :
1.280 +GuiWriter::GuiWriter(MapStorage* ms) :
1.281 + //Parent(writer),
1.282 + mapstorage(ms)
1.283 +{
1.284 +}