kruskalbox.cc
author hegyi
Tue, 27 Feb 2007 17:23:55 +0000
changeset 192 9d7489e8921e
parent 145 5baba2a107a1
child 194 6b2b718420eb
permissions -rw-r--r--
Forgot the meat.
     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 <kruskalbox.h>
    20 
    21 enum {INPUT, OUTPUT, MAP_NUM};
    22 
    23 KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
    24 {
    25   init(t);
    26 }
    27     
    28 void KruskalBox::run()
    29 {
    30   if(
    31      tabcbt.get_active_text()!="" &&
    32      (edgemapcbts[INPUT])->get_active_text()!="" &&
    33      (edgemapcbts[OUTPUT])->get_active_text()!=""
    34      )
    35     {
    36 
    37       const Graph &g=mapstorage->graph;
    38       Graph::EdgeMap<double> * inputmap=
    39 	((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
    40       Graph::EdgeMap<bool> outputmap(g);
    41       double res=kruskal(g, *inputmap, outputmap);
    42 
    43       for (EdgeIt i(g); i!=INVALID; ++i)
    44 	{
    45 	  if(outputmap[i])
    46 	    {
    47 	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
    48 					       get_active_text()]))[i]=1;
    49 	    }
    50 	  else
    51 	    {
    52 	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
    53 					       get_active_text()]))[i]=0;
    54 	    }
    55 	}
    56 
    57       std::ostringstream o;
    58       o << "Result: " << res;
    59       resultlabel.set_text(o.str());
    60 
    61       mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
    62       //   mapstorage->changeActiveMap(true, E_COLOR,
    63       // 			      (edgemapcbts[OUTPUT])->get_active_text());
    64       //   mapstorage->changeActiveMap(true, E_TEXT,
    65       // 			      (edgemapcbts[INPUT])->get_active_text());
    66   
    67     }
    68 }
    69     
    70 void KruskalBox::build_box()
    71 {
    72   std::vector<std::string> empty_vector;
    73 
    74   addMapSelector("Edgecosts: ", true);
    75   addMapSelector("Edges of tree here: ", true);
    76 
    77   resultlabel.set_text("Result: algorithm is not run yet.");
    78   pack_start(resultlabel);
    79 }