alpar@174: /* -*- C++ -*- alpar@174: * alpar@174: * This file is a part of LEMON, a generic C++ optimization library alpar@174: * alpar@174: * Copyright (C) 2003-2006 alpar@174: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@174: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@174: * alpar@174: * Permission to use, modify and distribute this software is granted alpar@174: * provided that this copyright notice appears in all copies. For alpar@174: * precise terms see the accompanying LICENSE file. alpar@174: * alpar@174: * This software is provided "AS IS" with no warranty of any kind, alpar@174: * express or implied, and with no claim as to its suitability for any alpar@174: * purpose. alpar@174: * alpar@174: */ alpar@174: hegyi@106: #include hegyi@106: hegyi@109: enum {INPUT, OUTPUT, MAP_NUM}; hegyi@109: hegyi@108: KruskalBox::KruskalBox(std::vector t):AlgoBox() hegyi@106: { hegyi@108: init(t); hegyi@106: } hegyi@106: hegyi@106: void KruskalBox::run() hegyi@106: { hegyi@114: if( hegyi@114: tabcbt.get_active_text()!="" && hegyi@114: (edgemapcbts[INPUT])->get_active_text()!="" && hegyi@114: (edgemapcbts[OUTPUT])->get_active_text()!="" hegyi@114: ) hegyi@114: { hegyi@109: alpar@145: const Graph &g=mapstorage->graph; hegyi@114: Graph::EdgeMap * inputmap= hegyi@114: ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]); hegyi@114: Graph::EdgeMap outputmap(g); hegyi@114: double res=kruskal(g, *inputmap, outputmap); hegyi@109: hegyi@114: for (EdgeIt i(g); i!=INVALID; ++i) hegyi@114: { hegyi@114: if(outputmap[i]) hegyi@114: { hegyi@114: (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> hegyi@114: get_active_text()]))[i]=1; hegyi@114: } hegyi@114: else hegyi@114: { hegyi@114: (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> hegyi@114: get_active_text()]))[i]=0; hegyi@114: } hegyi@114: } hegyi@111: hegyi@114: std::ostringstream o; hegyi@114: o << "Result: " << res; hegyi@114: resultlabel.set_text(o.str()); hegyi@114: hegyi@114: mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); hegyi@114: // mapstorage->changeActiveMap(true, E_COLOR, hegyi@114: // (edgemapcbts[OUTPUT])->get_active_text()); hegyi@114: // mapstorage->changeActiveMap(true, E_TEXT, hegyi@114: // (edgemapcbts[INPUT])->get_active_text()); alpar@110: hegyi@114: } hegyi@106: } hegyi@106: hegyi@106: void KruskalBox::build_box() hegyi@106: { hegyi@114: std::vector empty_vector; hegyi@114: hegyi@116: addMapSelector("Edgecosts: ", true); hegyi@116: addMapSelector("Edges of tree here: ", true); hegyi@109: hegyi@109: resultlabel.set_text("Result: algorithm is not run yet."); hegyi@109: pack_start(resultlabel); hegyi@106: }