hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all copies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #include "gui_writer.h" hegyi@1: #include "io_helper.h" hegyi@1: #include "mapstorage.h" hegyi@1: #include "xml.h" hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: // std::string GuiWriter::header() hegyi@1: // { hegyi@1: // return "@gui"; hegyi@1: // } hegyi@1: hegyi@1: void GuiWriter::write(std::ostream& os) hegyi@1: { hegyi@1: using std::vector; hegyi@1: using std::string; hegyi@1: using std::map; hegyi@1: using std::string; hegyi@1: hegyi@1: os << "@gui" << std::endl; hegyi@1: hegyi@1: XmlIo x(os); hegyi@1: hegyi@1: vector all_node_map_names = mapstorage->getNodeMapList(); hegyi@1: // name of the maps saved to the nodeset section hegyi@1: vector main_node_map_names; hegyi@1: // name of the maps saved to the gui section hegyi@1: vector gui_node_map_names; hegyi@1: hegyi@1: for (vector::const_iterator it = all_node_map_names.begin(); hegyi@1: it != all_node_map_names.end(); ++it) hegyi@1: { hegyi@1: if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT) hegyi@1: main_node_map_names.push_back(*it); hegyi@1: else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT) hegyi@1: gui_node_map_names.push_back(*it); hegyi@1: } hegyi@1: hegyi@1: { x("main_node_map_names", main_node_map_names); } hegyi@1: { x("gui_node_map_names", gui_node_map_names); } hegyi@1: hegyi@1: map node_map_types; hegyi@1: for (vector::const_iterator it = main_node_map_names.begin(); hegyi@1: it != main_node_map_names.end(); ++it) hegyi@1: { hegyi@1: node_map_types[*it] = mapstorage->getNodeMapElementType(*it); hegyi@1: } hegyi@1: for (vector::const_iterator it = gui_node_map_names.begin(); hegyi@1: it != gui_node_map_names.end(); ++it) hegyi@1: { hegyi@1: node_map_types[*it] = mapstorage->getNodeMapElementType(*it); hegyi@1: } hegyi@1: hegyi@1: { x("node_map_types", node_map_types); } hegyi@1: hegyi@1: hegyi@1: vector all_arc_map_names = mapstorage->getArcMapList(); hegyi@1: // name of the maps saved to the arcset section hegyi@1: vector main_arc_map_names; hegyi@1: // name of the maps saved to the gui section hegyi@1: vector gui_arc_map_names; hegyi@1: hegyi@1: for (vector::const_iterator it = all_arc_map_names.begin(); hegyi@1: it != all_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: if (mapstorage->getArcMapSaveDest(*it) == MapStorage::NESET_SECT) hegyi@1: main_arc_map_names.push_back(*it); hegyi@1: if (mapstorage->getArcMapSaveDest(*it) == MapStorage::GUI_SECT) hegyi@1: gui_arc_map_names.push_back(*it); hegyi@1: } hegyi@1: hegyi@1: { x("main_arc_map_names", main_arc_map_names); } hegyi@1: { x("gui_arc_map_names", gui_arc_map_names); } hegyi@1: hegyi@1: map arc_map_types; hegyi@1: for (vector::const_iterator it = main_arc_map_names.begin(); hegyi@1: it != main_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: arc_map_types[*it] = mapstorage->getArcMapElementType(*it); hegyi@1: } hegyi@1: for (vector::const_iterator it = gui_arc_map_names.begin(); hegyi@1: it != gui_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: arc_map_types[*it] = mapstorage->getArcMapElementType(*it); hegyi@1: } hegyi@1: hegyi@1: { x("arc_map_types", arc_map_types); } hegyi@1: hegyi@1: // write the gui node maps hegyi@1: for (vector::const_iterator it = gui_node_map_names.begin(); hegyi@1: it != gui_node_map_names.end(); ++it) hegyi@1: { hegyi@1: MapValue::Type type = mapstorage->getNodeMapElementType(*it); hegyi@1: const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap(); hegyi@1: switch (type) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: { hegyi@1: std::map map_data; hegyi@1: MapStorage::NumericNodeMap& map = hegyi@1: mapstorage->getNumericNodeMap(*it); hegyi@1: for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n) hegyi@1: { hegyi@1: map_data[labels[n]] = map[n]; hegyi@1: } hegyi@1: { x(*it, map_data); } hegyi@1: } hegyi@1: break; hegyi@1: case MapValue::STRING: hegyi@1: { hegyi@1: std::map map_data; hegyi@1: MapStorage::StringNodeMap& map = hegyi@1: mapstorage->getStringNodeMap(*it); hegyi@1: for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n) hegyi@1: { hegyi@1: map_data[labels[n]] = map[n]; hegyi@1: } hegyi@1: { x(*it, map_data); } hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: // write the gui arc maps hegyi@1: for (vector::const_iterator it = gui_arc_map_names.begin(); hegyi@1: it != gui_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: MapValue::Type type = mapstorage->getArcMapElementType(*it); hegyi@1: const MapStorage::ArcLabelMap& labels = mapstorage->getArcLabelMap(); hegyi@1: switch (type) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: { hegyi@1: std::map map_data; hegyi@1: MapStorage::NumericArcMap& map = hegyi@1: mapstorage->getNumericArcMap(*it); hegyi@1: for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e) hegyi@1: { hegyi@1: map_data[labels[e]] = map[e]; hegyi@1: } hegyi@1: { x(*it, map_data); } hegyi@1: } hegyi@1: break; hegyi@1: case MapValue::STRING: hegyi@1: { hegyi@1: std::map map_data; hegyi@1: MapStorage::StringArcMap& map = hegyi@1: mapstorage->getStringArcMap(*it); hegyi@1: for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e) hegyi@1: { hegyi@1: map_data[labels[e]] = map[e]; hegyi@1: } hegyi@1: { x(*it, map_data); } hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: { hegyi@1: switch (mapstorage->getNodeCoordsSaveDest()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::GUI_SECT: hegyi@1: { x("node_coords_save_dest", string("gui_sect")); } hegyi@1: // write the node coorinates hegyi@1: { hegyi@1: const MapStorage::NodeLabelMap& labels = hegyi@1: mapstorage->getNodeLabelMap(); hegyi@1: std::map node_coord_map; hegyi@1: MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap(); hegyi@1: for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n) hegyi@1: { hegyi@1: node_coord_map[labels[n]] = map[n]; hegyi@1: } hegyi@1: { x("node_coord_map", node_coord_map); } hegyi@1: } hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::NESET_SECT: hegyi@1: switch (mapstorage->getNodeCoordsSaveMapNum()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::ONE_MAP: hegyi@1: { x("node_coords_save_dest", string("nodeset_sect_1_map")); } hegyi@1: { x("map_name", mapstorage->getNodeCoordsOneMapName()); } hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::TWO_MAPS: hegyi@1: { x("node_coords_save_dest", string("nodeset_sect_2_maps")); } hegyi@1: { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); } hegyi@1: { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); } hegyi@1: break; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: { hegyi@1: switch (mapstorage->getArrowCoordsSaveDest()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::GUI_SECT: hegyi@1: { x("arrow_coords_save_dest", string("gui_sect")); } hegyi@1: // write the arrow coorinates hegyi@1: { hegyi@1: const MapStorage::ArcLabelMap& labels = hegyi@1: mapstorage->getArcLabelMap(); hegyi@1: std::map arrow_coord_map; hegyi@1: MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap(); hegyi@1: for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e) hegyi@1: { hegyi@1: arrow_coord_map[labels[e]] = map[e]; hegyi@1: } hegyi@1: { x("arrow_coord_map", arrow_coord_map); } hegyi@1: } hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::NESET_SECT: hegyi@1: switch (mapstorage->getArrowCoordsSaveMapNum()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::ONE_MAP: hegyi@1: { x("arrow_coords_save_dest", string("arcset_sect_1_map")); } hegyi@1: { x("map_name", mapstorage->getArrowCoordsOneMapName()); } hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::TWO_MAPS: hegyi@1: { x("arrow_coords_save_dest", string("arcset_sect_2_maps")); } hegyi@1: { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); } hegyi@1: { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); } hegyi@1: break; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: hegyi@1: std::map nm; hegyi@1: for(int i=0;iactive_nodemaps[i]; hegyi@1: } hegyi@1: { x("active_nodemaps", nm); } hegyi@1: hegyi@1: std::map em; hegyi@1: for(int i=0;iactive_arcmaps[i]; hegyi@1: } hegyi@1: { x("active_arcmaps", em); } hegyi@1: hegyi@1: double attraction; hegyi@1: double propulsation; hegyi@1: int iteration; hegyi@1: hegyi@1: mapstorage->get_design_data(attraction, propulsation, iteration); hegyi@1: hegyi@1: { x("redesign-attraction", attraction); } hegyi@1: { x("redesign-propulsation", propulsation); } hegyi@1: { x("redesign-iteration", iteration); } hegyi@1: } hegyi@1: hegyi@1: //GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : hegyi@1: GuiWriter::GuiWriter(MapStorage* ms) : hegyi@1: //Parent(writer), hegyi@1: mapstorage(ms) hegyi@1: { hegyi@1: }