| 1 |
/*===========================================================================*/ |
| 2 |
/* */ |
| 3 |
/* This file is part of a demonstration application for use with the */ |
| 4 |
/* SYMPHONY Branch, Cut, and Price Library. This application is a solver for */ |
| 5 |
/* the Vehicle Routing Problem and the Traveling Salesman Problem. */ |
| 6 |
/* */ |
| 7 |
/* (c) Copyright 2000-2007 Ted Ralphs. All Rights Reserved. */ |
| 8 |
/* */ |
| 9 |
/* This application was developed by Ted Ralphs ([email protected]) */ |
| 10 |
/* */ |
| 11 |
/* This software is licensed under the Eclipse Public License. Please see */ |
| 12 |
/* accompanying file for terms. */ |
| 13 |
/* */ |
| 14 |
/*===========================================================================*/ |
| 15 |
|
| 16 |
/* system include files */ |
| 17 |
#include <string.h> |
| 18 |
#include <stdio.h> |
| 19 |
|
| 20 |
/* SYMPHONY include files */ |
| 21 |
#include "sym_constants.h" |
| 22 |
#include "sym_proccomm.h" |
| 23 |
#include "sym_dg_params.h" |
| 24 |
|
| 25 |
/* VRP include files */ |
| 26 |
#include "vrp_messages.h" |
| 27 |
#include "vrp_common_types.h" |
| 28 |
#include "vrp_dg_functions.h" |
| 29 |
#include "vrp_macros.h" |
| 30 |
|
| 31 |
/*===========================================================================*/ |
| 32 |
|
| 33 |
/*===========================================================================*\ |
| 34 |
* This file contains additional user functions for the draw graph process. |
| 35 |
\*===========================================================================*/ |
| 36 |
|
| 37 |
void init_window(int dg_id, char *name, int width, int height) |
| 38 |
{ |
| 39 |
if (dg_id){ |
| 40 |
int s_bufid, code; |
| 41 |
s_bufid = init_send(DataInPlace); |
| 42 |
send_str(name); |
| 43 |
send_str(name); |
| 44 |
/* no change in the default window_desc data structure */ |
| 45 |
code = 4; |
| 46 |
send_int_array(&code, 1); |
| 47 |
code = CANVAS_WIDTH; |
| 48 |
send_int_array(&code, 1); |
| 49 |
send_int_array(&width, 1); |
| 50 |
code = CANVAS_HEIGHT; |
| 51 |
send_int_array(&code, 1); |
| 52 |
send_int_array(&height, 1); |
| 53 |
code = VIEWABLE_WIDTH; |
| 54 |
send_int_array(&code, 1); |
| 55 |
send_int_array(&width, 1); |
| 56 |
code = VIEWABLE_HEIGHT; |
| 57 |
send_int_array(&code, 1); |
| 58 |
send_int_array(&height, 1); |
| 59 |
send_msg(dg_id, CTOI_INITIALIZE_WINDOW); |
| 60 |
freebuf(s_bufid); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/*===========================================================================*/ |
| 65 |
|
| 66 |
void wait_for_click(int dg_id, char *name, int report) |
| 67 |
{ |
| 68 |
if (dg_id){ |
| 69 |
int s_bufid, r_bufid; |
| 70 |
s_bufid = init_send(DataInPlace); |
| 71 |
send_str(name); |
| 72 |
send_msg(dg_id, report); |
| 73 |
freebuf(s_bufid); |
| 74 |
if (report == CTOI_WAIT_FOR_CLICK_AND_REPORT){ |
| 75 |
r_bufid = receive_msg(dg_id, ITOC_CLICK_HAPPENED); |
| 76 |
freebuf(r_bufid); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/*===========================================================================*/ |
| 82 |
|
| 83 |
void delete_graph(int dg_id, char *name) |
| 84 |
{ |
| 85 |
if (dg_id){ |
| 86 |
int s_bufid; |
| 87 |
s_bufid = init_send(DataInPlace); |
| 88 |
send_str(name); |
| 89 |
send_msg(dg_id, CTOI_DELETE_GRAPH); |
| 90 |
freebuf(s_bufid); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/*===========================================================================*/ |
| 95 |
|
| 96 |
void display_graph(int dg_id, char *name) |
| 97 |
{ |
| 98 |
if (dg_id){ |
| 99 |
int s_bufid; |
| 100 |
s_bufid = init_send(DataInPlace); |
| 101 |
send_str(name); |
| 102 |
send_msg(dg_id, CTOI_DRAW_GRAPH); |
| 103 |
freebuf(s_bufid); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/*===========================================================================*/ |
| 108 |
|
| 109 |
void copy_node_set(int dg_id, int clone, char *name) |
| 110 |
{ |
| 111 |
if (dg_id){ |
| 112 |
int s_bufid; |
| 113 |
char node_place[MAX_NAME_LENGTH +1] = {"node_placement"}; |
| 114 |
s_bufid = init_send(DataInPlace); |
| 115 |
if (clone){ |
| 116 |
send_str(node_place); |
| 117 |
send_str(name); |
| 118 |
send_str(name); |
| 119 |
send_msg(dg_id, CTOI_CLONE_WINDOW); |
| 120 |
}else{ |
| 121 |
send_str(name); |
| 122 |
send_str(node_place); |
| 123 |
send_msg(dg_id, CTOI_COPY_GRAPH); |
| 124 |
} |
| 125 |
freebuf(s_bufid); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
/*===========================================================================*/ |
| 130 |
|
| 131 |
void disp_vrp_tour(int dg_id, int clone, char *name, |
| 132 |
_node *tour, int vertnum, int numroutes, int report) |
| 133 |
{ |
| 134 |
if (dg_id){ |
| 135 |
int i, j, prev_j, key = 0, s_bufid, zero = 0; |
| 136 |
int v0 = 0, v1 = tour[0].next; |
| 137 |
int edgenum = vertnum+numroutes-1; |
| 138 |
|
| 139 |
copy_node_set(dg_id, clone, name); |
| 140 |
s_bufid = init_send(DataInPlace); |
| 141 |
send_str(name); |
| 142 |
i = MODIFY_ADD_EDGES; |
| 143 |
send_int_array(&i, 1); |
| 144 |
send_int_array(&edgenum, 1); |
| 145 |
j = INDEX(v0, v1); |
| 146 |
send_int_array(&j, 1); |
| 147 |
send_int_array(&v0, 1); |
| 148 |
send_int_array(&v1, 1); |
| 149 |
send_int_array(&key, 1); |
| 150 |
for (i = 1; i < vertnum; i++){ |
| 151 |
v1=tour[v0=v1].next; |
| 152 |
if (tour[v0].route == tour[v1].route){ |
| 153 |
j = INDEX(v0, v1); |
| 154 |
send_int_array(&j, 1); |
| 155 |
send_int_array(&v0, 1); |
| 156 |
send_int_array(&v1, 1); |
| 157 |
send_int_array(&key, 1); |
| 158 |
}else if (v1 == 0){ |
| 159 |
j = INDEX(v0, 0); |
| 160 |
send_int_array(&j, 1); |
| 161 |
send_int_array(&v0, 1); |
| 162 |
send_int_array(&zero, 1); |
| 163 |
send_int_array(&key, 1); |
| 164 |
}else{ |
| 165 |
prev_j = j; |
| 166 |
if ((j = INDEX(v0, 0)) != prev_j){ |
| 167 |
send_int_array(&j, 1); |
| 168 |
send_int_array(&v0, 1); |
| 169 |
send_int_array(&zero, 1); |
| 170 |
send_int_array(&key, 1); |
| 171 |
} |
| 172 |
j = INDEX(0, v1); |
| 173 |
send_int_array(&j, 1); |
| 174 |
send_int_array(&zero, 1); |
| 175 |
send_int_array(&v1, 1); |
| 176 |
send_int_array(&key, 1); |
| 177 |
} |
| 178 |
} |
| 179 |
i = MODIFY_END_OF_MESSAGE; |
| 180 |
send_int_array(&i, 1); |
| 181 |
send_msg(dg_id, CTOI_MODIFY_GRAPH); |
| 182 |
display_graph(dg_id, name); |
| 183 |
if (report == CTOI_WAIT_FOR_CLICK_NO_REPORT || |
| 184 |
report == CTOI_WAIT_FOR_CLICK_AND_REPORT) |
| 185 |
wait_for_click(dg_id, name, report); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
/*===========================================================================*/ |
| 190 |
|
| 191 |
void draw_edge_set_from_edge_data(int dg_id, char *name, |
| 192 |
int edgenum, edge_data *edges) |
| 193 |
{ |
| 194 |
if (dg_id){ |
| 195 |
int i, j, key, s_bufid; |
| 196 |
|
| 197 |
key = 0; |
| 198 |
s_bufid = init_send(DataInPlace); |
| 199 |
send_str(name); |
| 200 |
i = MODIFY_ADD_EDGES; |
| 201 |
send_int_array(&i, 1); |
| 202 |
send_int_array(&edgenum, 1); |
| 203 |
for (i = 0; i < edgenum; i++){ |
| 204 |
j = INDEX(edges[i].v0, edges[i].v1); |
| 205 |
send_int_array(&j, 1); |
| 206 |
send_int_array(&edges[i].v0, 1); |
| 207 |
send_int_array(&edges[i].v1, 1); |
| 208 |
send_int_array(&key, 1); |
| 209 |
} |
| 210 |
i = MODIFY_END_OF_MESSAGE; |
| 211 |
send_int_array(&i, 1); |
| 212 |
send_msg(dg_id, CTOI_MODIFY_GRAPH); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
/*===========================================================================*/ |
| 217 |
|
| 218 |
void draw_edge_set_from_userind(int dg_id, char *name, |
| 219 |
int edgenum, int *userind) |
| 220 |
{ |
| 221 |
if (dg_id){ |
| 222 |
int i, v0, v1, key, s_bufid; |
| 223 |
|
| 224 |
key = 0; |
| 225 |
s_bufid = init_send(DataInPlace); |
| 226 |
send_str(name); |
| 227 |
i = MODIFY_ADD_EDGES; |
| 228 |
send_int_array(&i, 1); |
| 229 |
send_int_array(&edgenum, 1); |
| 230 |
for (i = 0; i < edgenum; i++){ |
| 231 |
BOTH_ENDS(userind[i], &v0, &v1); |
| 232 |
send_int_array(userind + i, 1); |
| 233 |
send_int_array(&v0, 1); |
| 234 |
send_int_array(&v1, 1); |
| 235 |
send_int_array(&key, 1); |
| 236 |
} |
| 237 |
i = MODIFY_END_OF_MESSAGE; |
| 238 |
send_int_array(&i, 1); |
| 239 |
send_msg(dg_id, CTOI_MODIFY_GRAPH); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
/*===========================================================================*/ |
| 244 |
|
| 245 |
void draw_weighted_edge_set(int dg_id, char *name, |
| 246 |
int edgenum, int *userind, |
| 247 |
double *value, double etol) |
| 248 |
{ |
| 249 |
if (dg_id){ |
| 250 |
int i, v0, v1, key, s_bufid; |
| 251 |
char dashpattern[MAX_DASH_PATTERN_LENGTH +1]; |
| 252 |
char weight[MAX_WEIGHT_LENGTH +1]; |
| 253 |
|
| 254 |
strcpy(dashpattern, "4 3"); |
| 255 |
s_bufid = init_send(DataInPlace); |
| 256 |
send_str(name); |
| 257 |
i = MODIFY_ADD_EDGES; |
| 258 |
send_int_array(&i, 1); |
| 259 |
send_int_array(&edgenum, 1); |
| 260 |
for (i = 0; i < edgenum; i++){ |
| 261 |
BOTH_ENDS(userind[i], &v0, &v1); |
| 262 |
send_int_array(userind + i, 1); |
| 263 |
send_int_array(&v0, 1); |
| 264 |
send_int_array(&v1, 1); |
| 265 |
if (value[i] > 1-etol){ |
| 266 |
strcpy(weight, "1"); |
| 267 |
key = 8; |
| 268 |
}else{ |
| 269 |
sprintf(weight, "%.3f", value[i]); |
| 270 |
key = 10; |
| 271 |
} |
| 272 |
send_int_array(&key, 1); |
| 273 |
send_str(weight); |
| 274 |
if (key & 2) |
| 275 |
send_str(dashpattern); |
| 276 |
} |
| 277 |
i = MODIFY_END_OF_MESSAGE; |
| 278 |
send_int_array(&i, 1); |
| 279 |
send_msg(dg_id, CTOI_MODIFY_GRAPH); |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
/*===========================================================================*/ |
| 284 |
|
| 285 |
void display_support_graph(int dg_id, int clone, char *name, |
| 286 |
int edgenum, int *userind, |
| 287 |
double *value, double etol, int report) |
| 288 |
{ |
| 289 |
if (dg_id){ |
| 290 |
copy_node_set(dg_id, clone, name); |
| 291 |
draw_weighted_edge_set(dg_id, name, edgenum, userind, value, etol); |
| 292 |
display_graph(dg_id, name); |
| 293 |
if (report == CTOI_WAIT_FOR_CLICK_NO_REPORT || |
| 294 |
report == CTOI_WAIT_FOR_CLICK_AND_REPORT) |
| 295 |
wait_for_click(dg_id, name, report); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
/*===========================================================================*/ |
| 300 |
|
| 301 |
void display_compressed_support_graph(int dg_id, int clone, char *name, |
| 302 |
int edgenum, int *userind, |
| 303 |
double *value, int report) |
| 304 |
{ |
| 305 |
if (dg_id){ |
| 306 |
int s_bufid, i; |
| 307 |
|
| 308 |
copy_node_set(dg_id, clone, name); |
| 309 |
s_bufid = init_send(DataInPlace); |
| 310 |
send_str(name); |
| 311 |
i = VRP_CTOI_DRAW_FRAC_GRAPH; |
| 312 |
send_int_array(&i, 1); |
| 313 |
send_int_array(&edgenum, 1); |
| 314 |
send_int_array(userind, edgenum); |
| 315 |
send_dbl_array(value, edgenum); |
| 316 |
send_msg(dg_id, CTOI_USER_MESSAGE); |
| 317 |
if (report == CTOI_WAIT_FOR_CLICK_NO_REPORT || |
| 318 |
report == CTOI_WAIT_FOR_CLICK_AND_REPORT) |
| 319 |
wait_for_click(dg_id, name, report); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
/*===========================================================================*/ |
| 324 |
|
| 325 |
void display_part_tour(int dg_id, int clone, char *name, int *tour, |
| 326 |
int numroutes, int report) |
| 327 |
{ |
| 328 |
if (dg_id){ |
| 329 |
int v0 = 0, v1 = tour[0], nv1, nv0; |
| 330 |
int s_bufid, i, j; |
| 331 |
int edgenum = 0, key = 0; |
| 332 |
|
| 333 |
copy_node_set(dg_id, TRUE, name); |
| 334 |
|
| 335 |
s_bufid = init_send(DataInPlace); |
| 336 |
send_str(name); |
| 337 |
i = MODIFY_ADD_EDGES; |
| 338 |
send_int_array(&i, 1); |
| 339 |
/*first count the number of edges*/ |
| 340 |
edgenum++; |
| 341 |
while (v1 != numroutes){ |
| 342 |
v1 = tour[v0=v1]; |
| 343 |
edgenum++; |
| 344 |
} |
| 345 |
send_int_array(&edgenum, 1); |
| 346 |
/*Now reset and pack the edges themselves*/ |
| 347 |
v0 = 0; |
| 348 |
v1 = tour[0]; |
| 349 |
nv1 = v1>numroutes?v1-numroutes:0; |
| 350 |
nv0 = v0>numroutes?v0-numroutes:0; |
| 351 |
j = INDEX(nv0,nv1); |
| 352 |
send_int_array(&j, 1); |
| 353 |
send_int_array(&nv0, 1); |
| 354 |
send_int_array(&nv1, 1); |
| 355 |
send_int_array(&key, 1); |
| 356 |
while (v1 != numroutes){ |
| 357 |
v1 = tour[v0=v1]; |
| 358 |
nv1 = v1>numroutes?v1-numroutes:0; |
| 359 |
nv0 = v0>numroutes?v0-numroutes:0; |
| 360 |
j = INDEX(nv0,nv1); |
| 361 |
send_int_array(&j, 1); |
| 362 |
send_int_array(&nv0, 1); |
| 363 |
send_int_array(&nv1, 1); |
| 364 |
send_int_array(&key, 1); |
| 365 |
} |
| 366 |
i = MODIFY_END_OF_MESSAGE; |
| 367 |
send_int_array(&i, 1); |
| 368 |
send_msg(dg_id, CTOI_MODIFY_GRAPH); |
| 369 |
display_graph(dg_id, name); |
| 370 |
if (report == CTOI_WAIT_FOR_CLICK_NO_REPORT || |
| 371 |
report == CTOI_WAIT_FOR_CLICK_AND_REPORT) |
| 372 |
wait_for_click(dg_id, name, report); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
/*===========================================================================*/ |
| 377 |
|
| 378 |
void disp_lb(int dg_id, int clone, char *name, int *tree, |
| 379 |
dbl_edge_data *best_edges, int vertnum, |
| 380 |
int numroutes, int report) |
| 381 |
{ |
| 382 |
if (dg_id){ |
| 383 |
int i, j, s_bufid, zero = 0; |
| 384 |
int edgenum = vertnum + numroutes - 1; |
| 385 |
|
| 386 |
copy_node_set(dg_id, clone, name); |
| 387 |
|
| 388 |
s_bufid = init_send(DataInPlace); |
| 389 |
send_str(name); |
| 390 |
i = MODIFY_ADD_EDGES; |
| 391 |
send_int_array(&i, 1); |
| 392 |
send_int_array(&edgenum, 1); |
| 393 |
for (i=1; i < vertnum; i++){ |
| 394 |
j = INDEX(i, tree[i]); |
| 395 |
send_int_array(&j, 1); |
| 396 |
send_int_array(&i, 1); |
| 397 |
send_int_array(tree+i, 1); |
| 398 |
send_int_array(&zero, 1); |
| 399 |
} |
| 400 |
|
| 401 |
for (i=0; i < numroutes; i++){ |
| 402 |
j = INDEX(best_edges[i].v0, best_edges[i].v1); |
| 403 |
send_int_array(&j, 1); |
| 404 |
send_int_array(&best_edges[i].v0, 1); |
| 405 |
send_int_array(&best_edges[i].v1, 1); |
| 406 |
send_int_array(&zero, 1); |
| 407 |
} |
| 408 |
i = MODIFY_END_OF_MESSAGE; |
| 409 |
send_int_array(&i, 1); |
| 410 |
send_msg(dg_id, CTOI_MODIFY_GRAPH); |
| 411 |
display_graph(dg_id, name); |
| 412 |
if (report == CTOI_WAIT_FOR_CLICK_NO_REPORT || |
| 413 |
report == CTOI_WAIT_FOR_CLICK_AND_REPORT) |
| 414 |
wait_for_click(dg_id, name, report); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
|