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 hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: enum {INPUT, OUTPUT, MAP_NUM}; hegyi@1: hegyi@1: KruskalBox::KruskalBox(std::vector t):AlgoBox() hegyi@1: { hegyi@1: init(t); hegyi@1: } hegyi@1: hegyi@1: void KruskalBox::run() hegyi@1: { hegyi@1: if( hegyi@1: tabcbt.get_active_text()!="" && hegyi@1: (arcmapcbts[INPUT])->get_active_text()!="" && hegyi@1: (arcmapcbts[OUTPUT])->get_active_text()!="" hegyi@1: ) hegyi@1: { hegyi@1: hegyi@1: const Digraph &g=mapstorage->getDigraph(); hegyi@1: std::string input_map_name = arcmapcbts[INPUT]->get_active_text(); hegyi@1: Digraph::ArcMap outputmap(g); hegyi@1: const MapStorage::NumericArcMap& inputmap= hegyi@1: mapstorage->getNumericArcMap(input_map_name); hegyi@1: double res=kruskal(g, inputmap, outputmap); hegyi@1: hegyi@1: for (ArcIt i(g); i!=INVALID; ++i) hegyi@1: { hegyi@1: if(outputmap[i]) hegyi@1: { hegyi@1: mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 1.0); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: mapstorage->set(arcmapcbts[OUTPUT]->get_active_text(), i, 0.0); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: std::ostringstream o; hegyi@1: o << "Result: " << res; hegyi@1: resultlabel.set_text(o.str()); hegyi@1: hegyi@1: mapstorage->mapChanged(true, (arcmapcbts[OUTPUT])->get_active_text()); hegyi@1: // mapstorage->changeActiveMap(true, E_COLOR, hegyi@1: // (arcmapcbts[OUTPUT])->get_active_text()); hegyi@1: // mapstorage->changeActiveMap(true, E_TEXT, hegyi@1: // (arcmapcbts[INPUT])->get_active_text()); hegyi@1: hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void KruskalBox::build_box() hegyi@1: { hegyi@1: std::vector empty_vector; hegyi@1: hegyi@1: addMapSelector("Arccosts: ", true, NUM); hegyi@1: addMapSelector("Arcs of tree here: ", true, NUM); hegyi@1: hegyi@1: resultlabel.set_text("Result: algorithm is not run yet."); hegyi@1: pack_start(resultlabel); hegyi@1: }