| 1 |
/*===========================================================================*/ |
| 2 |
/* */ |
| 3 |
/* This file is part of the SYMPHONY Branch, Cut, and Price Library. */ |
| 4 |
/* */ |
| 5 |
/* SYMPHONY was jointly developed by Ted Ralphs ([email protected]) and */ |
| 6 |
/* Laci Ladanyi ([email protected]). */ |
| 7 |
/* */ |
| 8 |
/* (c) Copyright 2000-2007 Ted Ralphs. All Rights Reserved. */ |
| 9 |
/* */ |
| 10 |
/* This software is licensed under the Eclipse Public License. Please see */ |
| 11 |
/* accompanying file for terms. */ |
| 12 |
/* */ |
| 13 |
/*===========================================================================*/ |
| 14 |
/*===========================================================================*/ |
| 15 |
|
| 16 |
#define CALL_FUNCTION(f) \ |
| 17 |
if ((termcode = f) < 0){ \ |
| 18 |
printf("Error detected: termcode = %i\n", termcode); \ |
| 19 |
printf("Exiting...\n\n"); \ |
| 20 |
exit(termcode); \ |
| 21 |
} |
| 22 |
|
| 23 |
/*===========================================================================*\ |
| 24 |
This file contains the main() for the master process. |
| 25 |
|
| 26 |
Note that, if you want to use the OSI SYMPHONY interface, you should set the |
| 27 |
USE_OSI_INTERFACE flag and define the COINROOT path in the SYMPHONY |
| 28 |
Makefile. Otherwise, the C callable library functions will be used by |
| 29 |
default. See below for the usage. |
| 30 |
\*===========================================================================*/ |
| 31 |
|
| 32 |
#if defined(USE_OSI_INTERFACE) |
| 33 |
|
| 34 |
#include "OsiSymSolverInterface.hpp" |
| 35 |
|
| 36 |
int main(int argc, char **argv) |
| 37 |
{ |
| 38 |
OsiSymSolverInterface si; |
| 39 |
|
| 40 |
/* Parse the command line */ |
| 41 |
si.parseCommandLine(argc, argv); |
| 42 |
|
| 43 |
/* Read in the problem */ |
| 44 |
si.loadProblem(); |
| 45 |
|
| 46 |
/* Find a priori problem bounds */ |
| 47 |
si.findInitialBounds(); |
| 48 |
|
| 49 |
/* Solve the problem */ |
| 50 |
si.setSymParam("lp_executable_name", "spp_lp_cg"); |
| 51 |
si.branchAndBound(); |
| 52 |
|
| 53 |
return(0); |
| 54 |
} |
| 55 |
|
| 56 |
#else |
| 57 |
|
| 58 |
#include "symphony.h" |
| 59 |
#include "sym_master.h" |
| 60 |
#include "spp.h" |
| 61 |
#include <stdlib.h> |
| 62 |
|
| 63 |
int spp_test(sym_environment *env); |
| 64 |
|
| 65 |
int main(int argc, char **argv) |
| 66 |
{ |
| 67 |
int termcode; |
| 68 |
spp_problem *spp; |
| 69 |
|
| 70 |
sym_environment *env = sym_open_environment(); |
| 71 |
|
| 72 |
sym_version(); |
| 73 |
|
| 74 |
CALL_FUNCTION( sym_parse_command_line(env, argc, argv) ); |
| 75 |
|
| 76 |
CALL_FUNCTION( sym_get_user_data(env, (void **)&spp) ); |
| 77 |
|
| 78 |
if(spp->par->test){ |
| 79 |
|
| 80 |
spp_test(env); |
| 81 |
|
| 82 |
} else { |
| 83 |
|
| 84 |
|
| 85 |
CALL_FUNCTION( sym_load_problem(env) ); |
| 86 |
|
| 87 |
CALL_FUNCTION( sym_find_initial_bounds(env) ); |
| 88 |
|
| 89 |
sym_set_str_param(env, "lp_executable_name", "spp_lp_cg"); |
| 90 |
sym_set_int_param(env, "generate_cgl_cuts", FALSE); |
| 91 |
|
| 92 |
CALL_FUNCTION( sym_solve(env) ); |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
CALL_FUNCTION( sym_close_environment(env) ); |
| 97 |
|
| 98 |
return(0); |
| 99 |
} |
| 100 |
|
| 101 |
/*===========================================================================*\ |
| 102 |
\*===========================================================================*/ |
| 103 |
|
| 104 |
|
| 105 |
int spp_test(sym_environment *env) |
| 106 |
{ |
| 107 |
int termcode, i, file_num = 1; |
| 108 |
char input_files[1][MAX_FILE_NAME_LENGTH +1] = {"sample.spp"}; |
| 109 |
|
| 110 |
double sol[1] = {6314.00}; |
| 111 |
|
| 112 |
char *input_dir = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1)); |
| 113 |
char *infile = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1)); |
| 114 |
double *obj_val = (double *)calloc(DSIZE,file_num); |
| 115 |
double tol = 1e-03; |
| 116 |
spp_problem *spp; |
| 117 |
|
| 118 |
CALL_FUNCTION( sym_get_user_data(env, (void **)&spp) ); |
| 119 |
|
| 120 |
if (strcmp(spp->par->test_dir, "") == 0){ |
| 121 |
strcpy(input_dir, "."); |
| 122 |
} else{ |
| 123 |
strcpy(input_dir, spp->par->test_dir); |
| 124 |
} |
| 125 |
|
| 126 |
sym_set_int_param(env, "verbosity", -10); |
| 127 |
spp->par->verbosity = -10; |
| 128 |
|
| 129 |
for(i = 0; i<file_num; i++){ |
| 130 |
|
| 131 |
strcpy(infile, ""); |
| 132 |
sprintf(infile, "%s%s%s", input_dir, "/", input_files[i]); |
| 133 |
strcpy(spp->par->infile, infile); |
| 134 |
|
| 135 |
CALL_FUNCTION( sym_load_problem(env) ); |
| 136 |
|
| 137 |
printf("Solving %s...\n", input_files[i]); |
| 138 |
|
| 139 |
CALL_FUNCTION( sym_solve(env) ); |
| 140 |
|
| 141 |
sym_get_obj_val(env, &obj_val[i]); |
| 142 |
|
| 143 |
if((obj_val[i] < sol[i] + tol) && |
| 144 |
(obj_val[i] > sol[i] - tol)){ |
| 145 |
printf("Success!\n"); |
| 146 |
} else { |
| 147 |
printf("Failure!(%f, %f) \n", obj_val[i], sol[i]); |
| 148 |
} |
| 149 |
|
| 150 |
if(env->mip->n && i + 1 < file_num){ |
| 151 |
free_master_u(env); |
| 152 |
strcpy(env->par.infile, ""); |
| 153 |
env->mip = (MIPdesc *) calloc(1, sizeof(MIPdesc)); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
spp->par->test = FALSE; |
| 158 |
|
| 159 |
FREE(input_dir); |
| 160 |
FREE(infile); |
| 161 |
FREE(obj_val); |
| 162 |
|
| 163 |
return(0); |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
#endif |
| 168 |
|