| 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 |
/* This application was developed by Ted Ralphs ([email protected]) */ |
| 8 |
/* This file was modified by Ali Pilatin January, 2005 ([email protected]) */ |
| 9 |
/* */ |
| 10 |
/* (c) Copyright 2000-2005 Ted Ralphs. All Rights Reserved. */ |
| 11 |
/* */ |
| 12 |
/* This software is licensed under the Eclipse Public License. Please see */ |
| 13 |
/* accompanying file for terms. */ |
| 14 |
/* */ |
| 15 |
/*===========================================================================*/ |
| 16 |
|
| 17 |
#include <stdio.h> |
| 18 |
#include "sym_macros.h" |
| 19 |
#include "vrp_const.h" |
| 20 |
#include "sym_proccomm.h" |
| 21 |
#include "heur_routines.h" |
| 22 |
|
| 23 |
/*===========================================================================*/ |
| 24 |
|
| 25 |
/*------------------------------------------------------------------*\ |
| 26 |
| This function receives the data that the function broadcast sends | |
| 27 |
| and returns the tid of the sending process | |
| 28 |
\*------------------------------------------------------------------*/ |
| 29 |
|
| 30 |
int receive(heur_prob *p) |
| 31 |
{ |
| 32 |
int r_bufid, info, bytes, msgtag, parent; |
| 33 |
|
| 34 |
PVM_FUNC(r_bufid, pvm_recv(-1, VRP_BROADCAST_DATA)); |
| 35 |
PVM_FUNC(info, pvm_bufinfo(r_bufid, &bytes, &msgtag, &parent)); |
| 36 |
PVM_FUNC(info, pvm_upkint(&(p->dist.wtype), 1, 1)); |
| 37 |
PVM_FUNC(info, pvm_upkint(&(p->vertnum), 1, 1)); |
| 38 |
PVM_FUNC(info, pvm_upkint(&(p->depot), 1, 1)); |
| 39 |
PVM_FUNC(info, pvm_upkint(&p->capacity, 1, 1)); |
| 40 |
p->demand = (int *) calloc (p->vertnum, sizeof(int)); |
| 41 |
PVM_FUNC(info, pvm_upkint(p->demand, p->vertnum, 1)); |
| 42 |
p->edgenum = p->vertnum*(p->vertnum-1)/2; |
| 43 |
if (p->dist.wtype){ /* not EXPLICIT */ |
| 44 |
p->dist.coordx = (double *) calloc(p->vertnum, sizeof(double)); |
| 45 |
p->dist.coordy = (double *) calloc(p->vertnum, sizeof(double)); |
| 46 |
PVM_FUNC(info, pvm_upkdouble(p->dist.coordx, p->vertnum, 1)); |
| 47 |
PVM_FUNC(info, pvm_upkdouble(p->dist.coordy, p->vertnum, 1)); |
| 48 |
if ((p->dist.wtype == _EUC_3D) || (p->dist.wtype == _MAX_3D) || |
| 49 |
(p->dist.wtype == _MAN_3D)){ |
| 50 |
p->dist.coordz = (double *) calloc(p->vertnum, sizeof(double)); |
| 51 |
PVM_FUNC(info, pvm_upkdouble(p->dist.coordz, p->vertnum, 1)); |
| 52 |
} |
| 53 |
} |
| 54 |
else{ /* EXPLICIT */ |
| 55 |
p->dist.cost = (int *) malloc (p->edgenum*sizeof(int)); |
| 56 |
PVM_FUNC(info, pvm_upkint(p->dist.cost, (int)p->edgenum, 1)); |
| 57 |
} |
| 58 |
PVM_FUNC(info, pvm_freebuf(r_bufid)); |
| 59 |
return(parent); |
| 60 |
} |
| 61 |
|
| 62 |
/*===========================================================================*/ |
| 63 |
|
| 64 |
/*---------------------------------------------------------------------------*\ |
| 65 |
| This function sends the final tour back to the parent | |
| 66 |
\*---------------------------------------------------------------------------*/ |
| 67 |
|
| 68 |
void send_tour(_node *tour, int cost, int numroutes, int algorithm, |
| 69 |
double cpu_time, int parent, int vertnum, int routes, |
| 70 |
route_data *route_info) |
| 71 |
{ |
| 72 |
int s_bufid, info; |
| 73 |
|
| 74 |
PVM_FUNC(s_bufid, pvm_initsend(PvmDataRaw)); |
| 75 |
PVM_FUNC(info, pvm_pkbyte((char *)tour, (vertnum)*sizeof(_node), 1)); |
| 76 |
PVM_FUNC(info, pvm_pkint(&cost, 1, 1)); |
| 77 |
PVM_FUNC(info, pvm_pkint(&numroutes, 1, 1)); |
| 78 |
PVM_FUNC(info, pvm_pkint(&algorithm, 1, 1)); |
| 79 |
PVM_FUNC(info, pvm_pkdouble(&cpu_time, 1, 1)); |
| 80 |
if (routes){ |
| 81 |
PVM_FUNC(info, pvm_pkbyte((char *)route_info, |
| 82 |
(numroutes+1)*sizeof(route_data), 1)); |
| 83 |
PVM_FUNC(info, pvm_send(parent, HEUR_TOUR_WITH_ROUTES)); |
| 84 |
printf("\nSent HEUR_TOUR_WITH_ROUTES\n\n"); |
| 85 |
} |
| 86 |
else{ |
| 87 |
PVM_FUNC(info, pvm_send(parent, HEUR_TOUR)); |
| 88 |
printf("\nSent HEUR_TOUR\n\n"); |
| 89 |
} |
| 90 |
PVM_FUNC(info, pvm_freebuf(s_bufid)); |
| 91 |
|
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
/*===========================================================================*/ |
| 96 |
|
| 97 |
void free_heur_prob(heur_prob *p) |
| 98 |
{ |
| 99 |
if (p){ |
| 100 |
if (p->cur_tour){ |
| 101 |
FREE(p->cur_tour->tour); |
| 102 |
FREE(p->cur_tour->route_info); |
| 103 |
FREE(p->cur_tour); |
| 104 |
} |
| 105 |
/* |
| 106 |
FREE(p->demand); |
| 107 |
FREE(p->dist.coordx); |
| 108 |
FREE(p->dist.coordy); |
| 109 |
FREE(p->dist.coordz); |
| 110 |
FREE(p->dist.cost); |
| 111 |
FREE(p); |
| 112 |
*/ |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/*===========================================================================*/ |
| 117 |
|
| 118 |
void free_lb_prob(lb_prob *p) |
| 119 |
{ |
| 120 |
if (p){ |
| 121 |
FREE(p->demand); |
| 122 |
FREE(p->dist.coordx); |
| 123 |
FREE(p->dist.coordy); |
| 124 |
FREE(p->dist.coordz); |
| 125 |
FREE(p->dist.cost); |
| 126 |
FREE(p); |
| 127 |
} |
| 128 |
} |
| 129 |
|