| 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 <math.h> |
| 18 |
|
| 19 |
/* VRP include files */ |
| 20 |
#include "vrp_macros.h" |
| 21 |
|
| 22 |
/*===========================================================================*/ |
| 23 |
|
| 24 |
void BOTH_ENDS(int index, int *v0, int *v1) |
| 25 |
{ |
| 26 |
*v0 = (int)(floor(sqrt(1+8.0*index)/2+.500000001)); |
| 27 |
*v1 = index - (*v0 * (*v0-1)/2); |
| 28 |
} |
| 29 |
|
| 30 |
/*===========================================================================*/ |
| 31 |
|
| 32 |
int NEAREST_INT(double num) |
| 33 |
{ |
| 34 |
return((num - ((int)num) > ((int)num) + 1 - num) ? |
| 35 |
(int)ceil(num) : (int)floor(num)); |
| 36 |
} |
| 37 |
|
| 38 |
/*===========================================================================*/ |
| 39 |
|
| 40 |
int INDEX(int v0, int v1) |
| 41 |
{ |
| 42 |
return( (v1) > (v0) ? ((int)(v1))*((v1)-1)/2+(v0) : |
| 43 |
((int)(v0))*((v0)-1)/2+(v1)); |
| 44 |
} |
| 45 |
|
| 46 |
/*===========================================================================*/ |
| 47 |
|
| 48 |
/*approximates the number of trucks necessary to service a set of customers*/ |
| 49 |
int BINS(int weight, int capacity) |
| 50 |
{ |
| 51 |
return((int) ceil(((double)weight)/((double)capacity))); |
| 52 |
} |
| 53 |
|
| 54 |
/*===========================================================================*/ |
| 55 |
|
| 56 |
/*calculates the right hand side of a subtour elimination constraint*/ |
| 57 |
int RHS(int cust_num, int weight, int capacity) |
| 58 |
{ |
| 59 |
return(cust_num-BINS(weight, capacity)); |
| 60 |
} |