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@42
|
19 |
#include <new_map_win.h>
|
hegyi@42
|
20 |
|
hegyi@42
|
21 |
bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
|
hegyi@42
|
22 |
{
|
hegyi@42
|
23 |
if(e->keyval==GDK_Escape)
|
hegyi@42
|
24 |
{
|
hegyi@42
|
25 |
hide();
|
hegyi@42
|
26 |
}
|
hegyi@42
|
27 |
return true;
|
hegyi@42
|
28 |
}
|
hegyi@42
|
29 |
|
hegyi@96
|
30 |
NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap")
|
hegyi@42
|
31 |
{
|
hegyi@42
|
32 |
set_default_size(200, 50);
|
hegyi@42
|
33 |
|
hegyi@42
|
34 |
signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
|
hegyi@42
|
35 |
|
hegyi@90
|
36 |
Gtk::VBox * vbox=get_vbox();
|
hegyi@42
|
37 |
|
hegyi@42
|
38 |
//entries
|
hegyi@42
|
39 |
table=new Gtk::Table(3, 2, false);
|
hegyi@42
|
40 |
|
hegyi@42
|
41 |
label=new Gtk::Label;
|
hegyi@42
|
42 |
label->set_text("Name of new map:");
|
hegyi@42
|
43 |
name.set_text("");
|
hegyi@42
|
44 |
|
hegyi@42
|
45 |
(*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
46 |
(*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
47 |
|
hegyi@42
|
48 |
label=new Gtk::Label;
|
hegyi@42
|
49 |
label->set_text("Default value in the map:");
|
hegyi@42
|
50 |
default_value.set_text("0");
|
hegyi@42
|
51 |
|
hegyi@42
|
52 |
(*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
53 |
(*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
54 |
|
hegyi@42
|
55 |
//node vs. edge map selector
|
hegyi@42
|
56 |
Gtk::RadioButton::Group group = node.get_group();
|
hegyi@42
|
57 |
edge.set_group(group);
|
hegyi@90
|
58 |
|
hegyi@90
|
59 |
if(edgenode)
|
hegyi@90
|
60 |
{
|
hegyi@90
|
61 |
(*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@90
|
62 |
(*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@90
|
63 |
}
|
hegyi@90
|
64 |
else
|
hegyi@90
|
65 |
{
|
hegyi@90
|
66 |
if(itisedge)
|
hegyi@90
|
67 |
{
|
hegyi@90
|
68 |
edge.set_active();
|
hegyi@90
|
69 |
}
|
hegyi@90
|
70 |
else
|
hegyi@90
|
71 |
{
|
hegyi@90
|
72 |
node.set_active();
|
hegyi@90
|
73 |
}
|
hegyi@90
|
74 |
}
|
hegyi@42
|
75 |
|
hegyi@90
|
76 |
vbox->pack_start(*table);
|
hegyi@42
|
77 |
|
hegyi@42
|
78 |
//OK button
|
hegyi@90
|
79 |
add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
hegyi@42
|
80 |
|
hegyi@42
|
81 |
show_all_children();
|
hegyi@42
|
82 |
|
hegyi@42
|
83 |
}
|
hegyi@42
|
84 |
|
hegyi@90
|
85 |
void NewMapWin::on_response(int response_id)
|
hegyi@85
|
86 |
{
|
hegyi@90
|
87 |
if(response_id==Gtk::RESPONSE_OK)
|
hegyi@85
|
88 |
{
|
hegyi@90
|
89 |
double def_val=0;
|
hegyi@85
|
90 |
|
hegyi@90
|
91 |
//get and formulate text
|
hegyi@90
|
92 |
std::string def_val_str=default_value.get_text();
|
hegyi@118
|
93 |
|
hegyi@118
|
94 |
bool only_nums=true;
|
hegyi@118
|
95 |
for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
|
hegyi@118
|
96 |
{
|
hegyi@118
|
97 |
if( def_val_str[i]<'0' || def_val_str[i]>'9' )
|
hegyi@118
|
98 |
{
|
hegyi@118
|
99 |
only_nums=false;
|
hegyi@118
|
100 |
}
|
hegyi@118
|
101 |
}
|
hegyi@118
|
102 |
std::string polishform;
|
hegyi@118
|
103 |
|
hegyi@118
|
104 |
if(only_nums)
|
hegyi@118
|
105 |
{
|
hegyi@118
|
106 |
def_val=atof(def_val_str.c_str());
|
hegyi@118
|
107 |
}
|
hegyi@118
|
108 |
else
|
hegyi@118
|
109 |
{
|
hegyi@118
|
110 |
polishform=string2Polishform(def_val_str,edge.get_active());
|
hegyi@118
|
111 |
}
|
hegyi@42
|
112 |
|
hegyi@90
|
113 |
//get name of text
|
hegyi@90
|
114 |
std::string mapname=name.get_text();
|
hegyi@118
|
115 |
|
hegyi@118
|
116 |
if(!mapname.empty()&&(!polishform.empty()||only_nums))
|
hegyi@90
|
117 |
{
|
hegyi@90
|
118 |
int abortion=0;
|
hegyi@90
|
119 |
if(edge.get_active())
|
hegyi@90
|
120 |
{
|
hegyi@90
|
121 |
//create the new map
|
hegyi@118
|
122 |
Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
|
hegyi@118
|
123 |
|
hegyi@118
|
124 |
if(!only_nums)
|
hegyi@88
|
125 |
{
|
hegyi@118
|
126 |
std::stack<double> polishstack;
|
hegyi@118
|
127 |
|
hegyi@118
|
128 |
for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
|
hegyi@88
|
129 |
{
|
hegyi@118
|
130 |
for(int i=0;i<(int)polishform.size();i++)
|
hegyi@88
|
131 |
{
|
hegyi@118
|
132 |
double op1=0, op2=0;
|
hegyi@118
|
133 |
bool operation=true;
|
hegyi@90
|
134 |
switch(polishform[i])
|
hegyi@90
|
135 |
{
|
hegyi@90
|
136 |
case '+':
|
hegyi@90
|
137 |
case '-':
|
hegyi@90
|
138 |
case '/':
|
hegyi@90
|
139 |
case '*':
|
hegyi@118
|
140 |
op1=polishstack.top();
|
hegyi@118
|
141 |
polishstack.pop();
|
hegyi@118
|
142 |
op2=polishstack.top();
|
hegyi@118
|
143 |
polishstack.pop();
|
hegyi@90
|
144 |
break;
|
hegyi@90
|
145 |
default:
|
hegyi@118
|
146 |
//substitute variable
|
hegyi@118
|
147 |
std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
|
hegyi@118
|
148 |
bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
|
hegyi@118
|
149 |
if(itisvar)
|
hegyi@118
|
150 |
{
|
hegyi@118
|
151 |
polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
|
hegyi@118
|
152 |
}
|
hegyi@118
|
153 |
else
|
hegyi@118
|
154 |
{
|
hegyi@118
|
155 |
polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
|
hegyi@118
|
156 |
}
|
hegyi@118
|
157 |
operation=false;
|
hegyi@90
|
158 |
break;
|
hegyi@90
|
159 |
}
|
hegyi@118
|
160 |
if(operation)
|
hegyi@118
|
161 |
{
|
hegyi@118
|
162 |
double res;
|
hegyi@118
|
163 |
switch(polishform[i])
|
hegyi@118
|
164 |
{
|
hegyi@118
|
165 |
case '+':
|
hegyi@118
|
166 |
res=op1+op2;
|
hegyi@118
|
167 |
break;
|
hegyi@118
|
168 |
case '-':
|
hegyi@118
|
169 |
res=op2-op1;
|
hegyi@118
|
170 |
break;
|
hegyi@118
|
171 |
case '/':
|
hegyi@118
|
172 |
res=op2/op1;
|
hegyi@118
|
173 |
break;
|
hegyi@118
|
174 |
case '*':
|
hegyi@118
|
175 |
res=op1*op2;
|
hegyi@118
|
176 |
break;
|
hegyi@118
|
177 |
default:
|
hegyi@118
|
178 |
std::cout << "How could we get here?" << std::endl;
|
hegyi@118
|
179 |
break;
|
hegyi@118
|
180 |
}
|
hegyi@118
|
181 |
polishstack.push(res);
|
hegyi@118
|
182 |
}
|
hegyi@118
|
183 |
}//foreach letter in polishform
|
hegyi@118
|
184 |
(*emptr)[k]=polishstack.top();
|
hegyi@118
|
185 |
}//foreach edge
|
hegyi@118
|
186 |
}//!only_nums
|
hegyi@90
|
187 |
|
hegyi@90
|
188 |
//if addition was not successful addEdgeMap returns one.
|
hegyi@90
|
189 |
//cause can be that there is already a map named like the new one
|
hegyi@96
|
190 |
if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
|
hegyi@90
|
191 |
{
|
hegyi@90
|
192 |
abortion=1;
|
hegyi@90
|
193 |
}
|
hegyi@90
|
194 |
|
hegyi@90
|
195 |
//add it to the list of the displayable maps
|
hegyi@108
|
196 |
//furthermore it is done by signals
|
hegyi@108
|
197 |
//mytab.registerNewEdgeMap(mapname);
|
hegyi@90
|
198 |
|
hegyi@90
|
199 |
//display it
|
hegyi@94
|
200 |
//gdc.changeEdgeText(mapname);
|
hegyi@88
|
201 |
}
|
hegyi@90
|
202 |
else //!edge.get_active()
|
hegyi@90
|
203 |
{
|
hegyi@90
|
204 |
//create the new map
|
hegyi@118
|
205 |
Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
|
hegyi@88
|
206 |
|
hegyi@118
|
207 |
if(!only_nums)
|
hegyi@118
|
208 |
{
|
hegyi@118
|
209 |
std::stack<double> polishstack;
|
hegyi@88
|
210 |
|
hegyi@118
|
211 |
for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
|
hegyi@88
|
212 |
{
|
hegyi@118
|
213 |
for(int i=0;i<(int)polishform.size();i++)
|
hegyi@88
|
214 |
{
|
hegyi@118
|
215 |
double op1=0, op2=0;
|
hegyi@118
|
216 |
bool operation=true;
|
hegyi@90
|
217 |
switch(polishform[i])
|
hegyi@90
|
218 |
{
|
hegyi@90
|
219 |
case '+':
|
hegyi@90
|
220 |
case '-':
|
hegyi@90
|
221 |
case '/':
|
hegyi@90
|
222 |
case '*':
|
hegyi@118
|
223 |
op1=polishstack.top();
|
hegyi@118
|
224 |
polishstack.pop();
|
hegyi@118
|
225 |
op2=polishstack.top();
|
hegyi@118
|
226 |
polishstack.pop();
|
hegyi@90
|
227 |
break;
|
hegyi@90
|
228 |
default:
|
hegyi@118
|
229 |
std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
|
hegyi@118
|
230 |
bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
|
hegyi@118
|
231 |
if(itisvar)
|
hegyi@118
|
232 |
{
|
hegyi@118
|
233 |
polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
|
hegyi@118
|
234 |
}
|
hegyi@118
|
235 |
else
|
hegyi@118
|
236 |
{
|
hegyi@118
|
237 |
polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
|
hegyi@118
|
238 |
}
|
hegyi@118
|
239 |
operation=false;
|
hegyi@90
|
240 |
break;
|
hegyi@90
|
241 |
}
|
hegyi@118
|
242 |
if(operation)
|
hegyi@118
|
243 |
{
|
hegyi@118
|
244 |
double res;
|
hegyi@118
|
245 |
switch(polishform[i])
|
hegyi@118
|
246 |
{
|
hegyi@118
|
247 |
case '+':
|
hegyi@118
|
248 |
res=op1+op2;
|
hegyi@118
|
249 |
break;
|
hegyi@118
|
250 |
case '-':
|
hegyi@118
|
251 |
res=op2-op1;
|
hegyi@118
|
252 |
break;
|
hegyi@118
|
253 |
case '/':
|
hegyi@118
|
254 |
res=op2/op1;
|
hegyi@118
|
255 |
break;
|
hegyi@118
|
256 |
case '*':
|
hegyi@118
|
257 |
res=op1*op2;
|
hegyi@118
|
258 |
break;
|
hegyi@118
|
259 |
default:
|
hegyi@118
|
260 |
std::cout << "How could we get here?" << std::endl;
|
hegyi@118
|
261 |
break;
|
hegyi@118
|
262 |
}
|
hegyi@118
|
263 |
polishstack.push(res);
|
hegyi@118
|
264 |
}
|
hegyi@90
|
265 |
}
|
hegyi@118
|
266 |
(*emptr)[k]=polishstack.top();
|
hegyi@88
|
267 |
}
|
hegyi@88
|
268 |
}
|
hegyi@90
|
269 |
//if addition was not successful addNodeMap returns one.
|
hegyi@90
|
270 |
//cause can be that there is already a map named like the new one
|
hegyi@96
|
271 |
if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
|
hegyi@90
|
272 |
{
|
hegyi@90
|
273 |
abortion=1;
|
hegyi@90
|
274 |
}
|
hegyi@90
|
275 |
|
hegyi@90
|
276 |
//add it to the list of the displayable maps
|
hegyi@108
|
277 |
//furthermore it is done by signals
|
hegyi@108
|
278 |
//mytab.registerNewNodeMap(mapname);
|
hegyi@90
|
279 |
|
hegyi@90
|
280 |
//display it
|
hegyi@90
|
281 |
//gdc.changeNodeText(mapname);
|
hegyi@88
|
282 |
}
|
hegyi@90
|
283 |
if(!abortion)
|
hegyi@88
|
284 |
{
|
hegyi@90
|
285 |
name.set_text("");
|
hegyi@90
|
286 |
default_value.set_text("0");
|
hegyi@90
|
287 |
edge.show();
|
hegyi@90
|
288 |
node.show();
|
hegyi@90
|
289 |
hide();
|
hegyi@88
|
290 |
}
|
hegyi@46
|
291 |
}
|
hegyi@42
|
292 |
}
|
hegyi@42
|
293 |
}
|
hegyi@42
|
294 |
|
hegyi@90
|
295 |
|
hegyi@88
|
296 |
std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
|
hegyi@88
|
297 |
{
|
hegyi@88
|
298 |
bool valid_entry=true;
|
hegyi@88
|
299 |
|
hegyi@88
|
300 |
std::map<std::string, int> str2i;
|
hegyi@88
|
301 |
|
hegyi@88
|
302 |
std::string command;
|
hegyi@88
|
303 |
|
hegyi@88
|
304 |
std::string variable;
|
hegyi@88
|
305 |
|
hegyi@88
|
306 |
char index='a';
|
hegyi@88
|
307 |
|
hegyi@88
|
308 |
for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
|
hegyi@88
|
309 |
{
|
hegyi@88
|
310 |
switch(rawcommand[i])
|
hegyi@88
|
311 |
{
|
hegyi@88
|
312 |
case '+':
|
hegyi@88
|
313 |
case '-':
|
hegyi@88
|
314 |
case '*':
|
hegyi@88
|
315 |
case '/':
|
hegyi@88
|
316 |
case ')':
|
hegyi@88
|
317 |
case '(':
|
hegyi@88
|
318 |
if(!variable.empty())
|
hegyi@88
|
319 |
{
|
hegyi@88
|
320 |
valid_entry=validVariable(variable, itisedge);
|
hegyi@88
|
321 |
ch2var[index]=variable;
|
hegyi@88
|
322 |
command+=index;
|
hegyi@88
|
323 |
index++;
|
hegyi@88
|
324 |
variable.erase(0,variable.size());
|
hegyi@88
|
325 |
}
|
hegyi@88
|
326 |
command+=rawcommand[i];
|
hegyi@88
|
327 |
break;
|
hegyi@88
|
328 |
default:
|
hegyi@88
|
329 |
variable+=rawcommand[i];
|
hegyi@88
|
330 |
break;
|
hegyi@88
|
331 |
}
|
hegyi@88
|
332 |
}
|
hegyi@88
|
333 |
|
hegyi@88
|
334 |
if(!variable.empty()&&valid_entry)
|
hegyi@88
|
335 |
{
|
hegyi@88
|
336 |
valid_entry=validVariable(variable, itisedge);
|
hegyi@88
|
337 |
ch2var[index]=variable;
|
hegyi@88
|
338 |
command+=index;
|
hegyi@88
|
339 |
index++;
|
hegyi@88
|
340 |
variable.erase(0,variable.size());
|
hegyi@88
|
341 |
}
|
hegyi@88
|
342 |
|
hegyi@88
|
343 |
if(valid_entry)
|
hegyi@88
|
344 |
{
|
hegyi@88
|
345 |
unsigned int pr=10000;
|
hegyi@88
|
346 |
bool prevmult=false;
|
hegyi@89
|
347 |
unsigned int prev_change=pr;
|
hegyi@89
|
348 |
unsigned int prev_br=pr;
|
hegyi@88
|
349 |
int counter=0;
|
hegyi@88
|
350 |
std::string comm_nobr="";
|
hegyi@88
|
351 |
std::vector<unsigned int> p;
|
hegyi@88
|
352 |
p.resize(counter+1);
|
hegyi@88
|
353 |
|
hegyi@88
|
354 |
//limits
|
hegyi@88
|
355 |
//6 brackets embedded
|
hegyi@88
|
356 |
//100 operation in a row from the same priority
|
hegyi@88
|
357 |
|
hegyi@88
|
358 |
for(int i=0;i<(int)command.size();i++)
|
hegyi@88
|
359 |
{
|
hegyi@88
|
360 |
bool put_in_string=true;
|
hegyi@88
|
361 |
switch(command[i])
|
hegyi@88
|
362 |
{
|
hegyi@88
|
363 |
case '(':
|
hegyi@88
|
364 |
pr=prev_br+10000;
|
hegyi@88
|
365 |
prev_br=pr;
|
hegyi@88
|
366 |
prevmult=false;
|
hegyi@88
|
367 |
put_in_string=false;
|
hegyi@88
|
368 |
break;
|
hegyi@88
|
369 |
case ')':
|
hegyi@88
|
370 |
pr=prev_br-10000;
|
hegyi@88
|
371 |
prev_br=pr;
|
hegyi@88
|
372 |
prevmult=false;
|
hegyi@88
|
373 |
put_in_string=false;
|
hegyi@88
|
374 |
break;
|
hegyi@88
|
375 |
case '+':
|
hegyi@88
|
376 |
case '-':
|
hegyi@88
|
377 |
if(prevmult)
|
hegyi@88
|
378 |
{
|
hegyi@88
|
379 |
pr=prev_change;
|
hegyi@88
|
380 |
}
|
hegyi@88
|
381 |
p[counter]=pr;
|
hegyi@88
|
382 |
pr-=100;
|
hegyi@88
|
383 |
|
hegyi@88
|
384 |
prevmult=false;
|
hegyi@88
|
385 |
break;
|
hegyi@88
|
386 |
case '/':
|
hegyi@88
|
387 |
case '*':
|
hegyi@88
|
388 |
if(!prevmult)
|
hegyi@88
|
389 |
{
|
hegyi@88
|
390 |
prev_change=pr;
|
hegyi@88
|
391 |
pr+=200;
|
hegyi@88
|
392 |
pr-=1;
|
hegyi@88
|
393 |
}
|
hegyi@88
|
394 |
p[counter]=pr;
|
hegyi@88
|
395 |
pr-=1;
|
hegyi@88
|
396 |
prevmult=true;
|
hegyi@88
|
397 |
break;
|
hegyi@88
|
398 |
default:
|
hegyi@88
|
399 |
p[counter]=65000;
|
hegyi@88
|
400 |
break;
|
hegyi@88
|
401 |
}
|
hegyi@88
|
402 |
if(put_in_string)
|
hegyi@88
|
403 |
{
|
hegyi@88
|
404 |
counter++;
|
hegyi@88
|
405 |
p.resize(counter+1);
|
hegyi@88
|
406 |
comm_nobr=comm_nobr+command[i];
|
hegyi@88
|
407 |
}
|
hegyi@88
|
408 |
}
|
hegyi@88
|
409 |
|
hegyi@88
|
410 |
tree_node * root=weightedString2Tree(comm_nobr, p, 0);
|
hegyi@88
|
411 |
|
hegyi@88
|
412 |
std::string polishform=postOrder(root);
|
hegyi@88
|
413 |
|
hegyi@117
|
414 |
deleteTree(root);
|
hegyi@117
|
415 |
|
hegyi@88
|
416 |
return polishform;
|
hegyi@88
|
417 |
}
|
hegyi@88
|
418 |
return "";
|
hegyi@88
|
419 |
}
|
hegyi@88
|
420 |
|
hegyi@117
|
421 |
void NewMapWin::deleteTree(NewMapWin::tree_node * node)
|
hegyi@117
|
422 |
{
|
hegyi@117
|
423 |
if(node->left_child!=NULL)
|
hegyi@117
|
424 |
{
|
hegyi@117
|
425 |
deleteTree(node->left_child);
|
hegyi@117
|
426 |
}
|
hegyi@117
|
427 |
if(node->right_child!=NULL)
|
hegyi@117
|
428 |
{
|
hegyi@117
|
429 |
deleteTree(node->right_child);
|
hegyi@117
|
430 |
}
|
hegyi@117
|
431 |
delete node;
|
hegyi@117
|
432 |
}
|
hegyi@117
|
433 |
|
hegyi@88
|
434 |
NewMapWin::tree_node * NewMapWin::weightedString2Tree(std::string to_tree, std::vector<unsigned int> & p, int offset)
|
hegyi@88
|
435 |
{
|
hegyi@89
|
436 |
unsigned int min=p[offset];
|
hegyi@88
|
437 |
int minplace=0;
|
hegyi@88
|
438 |
for(int i=0;i<(int)to_tree.size();i++)
|
hegyi@88
|
439 |
{
|
hegyi@88
|
440 |
if(min>p[offset+i])
|
hegyi@88
|
441 |
{
|
hegyi@88
|
442 |
min=p[offset+i];
|
hegyi@88
|
443 |
minplace=i;
|
hegyi@88
|
444 |
}
|
hegyi@88
|
445 |
}
|
hegyi@88
|
446 |
tree_node * act_node=new tree_node;
|
hegyi@88
|
447 |
act_node->ch=to_tree[minplace];
|
hegyi@88
|
448 |
if(to_tree.size()>=3)
|
hegyi@88
|
449 |
{
|
hegyi@88
|
450 |
act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
|
hegyi@88
|
451 |
act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
|
hegyi@88
|
452 |
}
|
hegyi@88
|
453 |
else
|
hegyi@88
|
454 |
{
|
hegyi@88
|
455 |
act_node->left_child=NULL;
|
hegyi@88
|
456 |
act_node->right_child=NULL;
|
hegyi@88
|
457 |
}
|
hegyi@88
|
458 |
return act_node;
|
hegyi@88
|
459 |
}
|
hegyi@88
|
460 |
|
hegyi@88
|
461 |
std::string NewMapWin::postOrder(tree_node * subtree)
|
hegyi@88
|
462 |
{
|
hegyi@88
|
463 |
std::string subtree_to_string;
|
hegyi@88
|
464 |
if(subtree->left_child)
|
hegyi@88
|
465 |
{
|
hegyi@88
|
466 |
subtree_to_string=postOrder(subtree->left_child);
|
hegyi@88
|
467 |
}
|
hegyi@88
|
468 |
if(subtree->right_child)
|
hegyi@88
|
469 |
{
|
hegyi@88
|
470 |
subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
|
hegyi@88
|
471 |
}
|
hegyi@88
|
472 |
subtree_to_string=subtree_to_string+subtree->ch;
|
hegyi@88
|
473 |
return subtree_to_string;
|
hegyi@88
|
474 |
}
|
hegyi@88
|
475 |
|
hegyi@88
|
476 |
bool NewMapWin::validVariable(std::string variable, bool itisedge)
|
hegyi@88
|
477 |
{
|
hegyi@88
|
478 |
bool cancel;
|
hegyi@88
|
479 |
//is it mapname?
|
hegyi@88
|
480 |
if(itisedge)
|
hegyi@88
|
481 |
{
|
hegyi@96
|
482 |
cancel=(mytab.mapstorage.edgemap_storage.find(variable)==mytab.mapstorage.edgemap_storage.end());
|
hegyi@88
|
483 |
}
|
hegyi@88
|
484 |
else
|
hegyi@88
|
485 |
{
|
hegyi@96
|
486 |
cancel=(mytab.mapstorage.nodemap_storage.find(variable)==mytab.mapstorage.nodemap_storage.end());
|
hegyi@88
|
487 |
}
|
hegyi@88
|
488 |
//maybe it is number
|
hegyi@88
|
489 |
int point_num=0;
|
hegyi@88
|
490 |
if(cancel)
|
hegyi@88
|
491 |
{
|
hegyi@88
|
492 |
cancel=false;
|
hegyi@88
|
493 |
for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
|
hegyi@88
|
494 |
{
|
hegyi@88
|
495 |
if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
|
hegyi@88
|
496 |
{
|
hegyi@88
|
497 |
cancel=true;
|
hegyi@88
|
498 |
}
|
hegyi@88
|
499 |
else
|
hegyi@88
|
500 |
{
|
hegyi@88
|
501 |
if(variable[j]=='.')
|
hegyi@88
|
502 |
{
|
hegyi@88
|
503 |
point_num++;
|
hegyi@88
|
504 |
if(point_num>1)
|
hegyi@88
|
505 |
{
|
hegyi@88
|
506 |
cancel=true;
|
hegyi@88
|
507 |
}
|
hegyi@88
|
508 |
}
|
hegyi@88
|
509 |
}
|
hegyi@88
|
510 |
}
|
hegyi@88
|
511 |
}
|
hegyi@88
|
512 |
if(cancel)
|
hegyi@88
|
513 |
{
|
hegyi@88
|
514 |
return false;
|
hegyi@88
|
515 |
}
|
hegyi@88
|
516 |
return true;
|
hegyi@88
|
517 |
}
|