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 (ted@lehigh.edu)             */
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 <stdio.h>
18 #include <math.h>
19 #include <stdlib.h>
20 
21 /* SYMPHONY include files */
22 #include "sym_constants.h"
23 #include "sym_macros.h"
24 #include "sym_proccomm.h"
25 
26 /* VRP include files */
27 #include "vrp_dg.h"
28 #include "vrp_const.h"
29 #include "vrp_macros.h"
30 #include "vrp_messages.h"
31 
32 /*===========================================================================*/
33 
34 /*===========================================================================*\
35  * This file contains the user-written functions for the drawgraph process.
36 \*===========================================================================*/
37 
user_dg_process_message(void * user,window * win,FILE * write_to)38 int user_dg_process_message(void *user, window *win, FILE *write_to)
39 {
40    vrp_dg *win_vrp = (vrp_dg *)user;
41    int msgtag;
42    int length;
43    int *xind;
44    double *xval;
45 
46    receive_int_array(&msgtag, 1);
47    switch (msgtag){
48     case VRP_CTOI_DRAW_FRAC_GRAPH:
49       receive_int_array(&length, 1);
50       xind = (int *) malloc(length * ISIZE);
51       xval = (double *) malloc(length * DSIZE);
52       receive_int_array(xind, length);
53       receive_dbl_array(xval, length);
54       dg_freenet(win_vrp->n);
55       win_vrp->n = dg_createnet(win->g.nodenum, length, xind, xval);
56       FREE(xind);
57       FREE(xval);
58       dg_net_shrink_chains(win_vrp->n);
59       copy_network_into_graph(win_vrp->n, &win->g);
60       display_graph_on_canvas(win, write_to);
61       break;
62    }
63    return(USER_NO_PP);
64 }
65 
66 /*===========================================================================*/
67 
user_dg_init_window(void ** user,window * win)68 int user_dg_init_window(void **user, window *win)
69 {
70    vrp_dg *win_vrp = (vrp_dg *) calloc(1, sizeof(vrp_dg));
71 #if 0
72    int vertnum = win_vrp->g.nodenum;
73 
74    win_vrp->edges = (int *) calloc (vertnum*(vertnum-1), sizeof(int));
75 
76    /*create the edge list (we assume a complete graph)*/
77    for (i = 1, k = 0; i < vertnum; i++){
78       for (j = 0; j < i; j++){
79 	 vrp->edges[2*k] = j;
80 	 vrp->edges[2*k+1] = i;
81 	 k++;
82       }
83    }
84 #endif
85 
86    *user = win_vrp;
87 
88    return(USER_NO_PP);
89 }
90 
91 /*===========================================================================*/
92 
user_dg_free_window(void ** user,window * win)93 int user_dg_free_window(void **user, window *win)
94 {
95    vrp_dg *win_vrp = (vrp_dg *)*user;
96 
97    dg_freenet(win_vrp->n);
98    FREE(*user);
99 
100    return(USER_NO_PP);
101 }
102 
103 /*===========================================================================*/
104 
user_initialize_dg(void ** user)105 int user_initialize_dg(void **user)
106 {
107    return(USER_NO_PP);
108 }
109 
110 /*===========================================================================*/
111 
user_free_dg(void ** user)112 int user_free_dg(void **user)
113 {
114    return(USER_NO_PP);
115 }
116 
117 /*===========================================================================*/
118 
user_interpret_text(void * user,int text_length,char * text,int owner_tid)119 int user_interpret_text(void *user, int text_length, char *text,
120 			 int owner_tid)
121 {
122    return(USER_NO_PP);
123 }
124 
125