kruskalbox.cc
author ladanyi
Wed, 02 May 2007 20:33:58 +0000
changeset 200 c7ae8642a8d8
parent 174 95872af46fc4
child 201 879e47e5b731
permissions -rw-r--r--
Bugfix.
alpar@174
     1
/* -*- C++ -*-
alpar@174
     2
 *
alpar@174
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@174
     4
 *
alpar@174
     5
 * Copyright (C) 2003-2006
alpar@174
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@174
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@174
     8
 *
alpar@174
     9
 * Permission to use, modify and distribute this software is granted
alpar@174
    10
 * provided that this copyright notice appears in all copies. For
alpar@174
    11
 * precise terms see the accompanying LICENSE file.
alpar@174
    12
 *
alpar@174
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@174
    14
 * express or implied, and with no claim as to its suitability for any
alpar@174
    15
 * purpose.
alpar@174
    16
 *
alpar@174
    17
 */
alpar@174
    18
hegyi@194
    19
#include <lemon/kruskal.h>
hegyi@194
    20
hegyi@194
    21
#include <mapstorage.h>
hegyi@194
    22
#include <mapselector.h>
hegyi@194
    23
#include <algobox.h>
hegyi@106
    24
#include <kruskalbox.h>
hegyi@106
    25
hegyi@109
    26
enum {INPUT, OUTPUT, MAP_NUM};
hegyi@109
    27
hegyi@108
    28
KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
hegyi@106
    29
{
hegyi@108
    30
  init(t);
hegyi@106
    31
}
hegyi@106
    32
    
hegyi@106
    33
void KruskalBox::run()
hegyi@106
    34
{
hegyi@114
    35
  if(
hegyi@114
    36
     tabcbt.get_active_text()!="" &&
hegyi@114
    37
     (edgemapcbts[INPUT])->get_active_text()!="" &&
hegyi@114
    38
     (edgemapcbts[OUTPUT])->get_active_text()!=""
hegyi@114
    39
     )
hegyi@114
    40
    {
hegyi@109
    41
alpar@145
    42
      const Graph &g=mapstorage->graph;
hegyi@114
    43
      Graph::EdgeMap<double> * inputmap=
hegyi@114
    44
	((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
hegyi@114
    45
      Graph::EdgeMap<bool> outputmap(g);
hegyi@114
    46
      double res=kruskal(g, *inputmap, outputmap);
hegyi@109
    47
hegyi@114
    48
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@114
    49
	{
hegyi@114
    50
	  if(outputmap[i])
hegyi@114
    51
	    {
hegyi@114
    52
	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
hegyi@114
    53
					       get_active_text()]))[i]=1;
hegyi@114
    54
	    }
hegyi@114
    55
	  else
hegyi@114
    56
	    {
hegyi@114
    57
	      (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
hegyi@114
    58
					       get_active_text()]))[i]=0;
hegyi@114
    59
	    }
hegyi@114
    60
	}
hegyi@111
    61
hegyi@114
    62
      std::ostringstream o;
hegyi@114
    63
      o << "Result: " << res;
hegyi@114
    64
      resultlabel.set_text(o.str());
hegyi@114
    65
hegyi@114
    66
      mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
hegyi@114
    67
      //   mapstorage->changeActiveMap(true, E_COLOR,
hegyi@114
    68
      // 			      (edgemapcbts[OUTPUT])->get_active_text());
hegyi@114
    69
      //   mapstorage->changeActiveMap(true, E_TEXT,
hegyi@114
    70
      // 			      (edgemapcbts[INPUT])->get_active_text());
alpar@110
    71
  
hegyi@114
    72
    }
hegyi@106
    73
}
hegyi@106
    74
    
hegyi@106
    75
void KruskalBox::build_box()
hegyi@106
    76
{
hegyi@114
    77
  std::vector<std::string> empty_vector;
hegyi@114
    78
hegyi@116
    79
  addMapSelector("Edgecosts: ", true);
hegyi@116
    80
  addMapSelector("Edges of tree here: ", true);
hegyi@109
    81
hegyi@109
    82
  resultlabel.set_text("Result: algorithm is not run yet.");
hegyi@109
    83
  pack_start(resultlabel);
hegyi@106
    84
}