COIN-OR::LEMON - Graph Library

source: glemon-0.x/kruskalbox.cc @ 200:c7ae8642a8d8

Last change on this file since 200:c7ae8642a8d8 was 194:6b2b718420eb, checked in by Hegyi Péter, 17 years ago

Header reorganising

File size: 2.2 KB
Line 
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
19#include <lemon/kruskal.h>
20
21#include <mapstorage.h>
22#include <mapselector.h>
23#include <algobox.h>
24#include <kruskalbox.h>
25
26enum {INPUT, OUTPUT, MAP_NUM};
27
28KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
29{
30  init(t);
31}
32   
33void KruskalBox::run()
34{
35  if(
36     tabcbt.get_active_text()!="" &&
37     (edgemapcbts[INPUT])->get_active_text()!="" &&
38     (edgemapcbts[OUTPUT])->get_active_text()!=""
39     )
40    {
41
42      const Graph &g=mapstorage->graph;
43      Graph::EdgeMap<double> * inputmap=
44        ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
45      Graph::EdgeMap<bool> outputmap(g);
46      double res=kruskal(g, *inputmap, outputmap);
47
48      for (EdgeIt i(g); i!=INVALID; ++i)
49        {
50          if(outputmap[i])
51            {
52              (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
53                                               get_active_text()]))[i]=1;
54            }
55          else
56            {
57              (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
58                                               get_active_text()]))[i]=0;
59            }
60        }
61
62      std::ostringstream o;
63      o << "Result: " << res;
64      resultlabel.set_text(o.str());
65
66      mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
67      //   mapstorage->changeActiveMap(true, E_COLOR,
68      //                              (edgemapcbts[OUTPUT])->get_active_text());
69      //   mapstorage->changeActiveMap(true, E_TEXT,
70      //                              (edgemapcbts[INPUT])->get_active_text());
71 
72    }
73}
74   
75void KruskalBox::build_box()
76{
77  std::vector<std::string> empty_vector;
78
79  addMapSelector("Edgecosts: ", true);
80  addMapSelector("Edges of tree here: ", true);
81
82  resultlabel.set_text("Result: algorithm is not run yet.");
83  pack_start(resultlabel);
84}
Note: See TracBrowser for help on using the repository browser.