1 /*===========================================================================*/
2 /*                                                                           */
3 /* This file is part of the SYMPHONY Branch, Cut, and Price Library.         */
4 /*                                                                           */
5 /* SYMPHONY was jointly developed by Ted Ralphs (ted@lehigh.edu) and         */
6 /* Laci Ladanyi (ladanyi@us.ibm.com).                                        */
7 /*                                                                           */
8 /* (c) Copyright 2000-2005-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 
main(int argc,char ** argv)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.branchAndBound();
51 
52    return(0);
53 }
54 
55 #else
56 
57 #include "symphony.h"
58 #include "sym_master.h"
59 #include "spp.h"
60 #include <stdlib.h>
61 
62 int spp_test(sym_environment *env);
63 
main(int argc,char ** argv)64 int main(int argc, char **argv)
65 {
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      CALL_FUNCTION( sym_load_problem(env) );
85 
86      CALL_FUNCTION( sym_find_initial_bounds(env) );
87 
88      CALL_FUNCTION( sym_solve(env) );
89 
90    }
91 
92    CALL_FUNCTION( sym_close_environment(env) );
93 
94    return(0);
95 }
96 
97 /*===========================================================================*\
98 \*===========================================================================*/
99 
spp_test(sym_environment * env)100 int spp_test(sym_environment *env)
101 {
102     int termcode, i, file_num = 2;
103    char input_files[1][MAX_FILE_NAME_LENGTH +1] = {"sample.spp"};
104 
105    double sol[1] = {6314.00};
106 
107    char *input_dir = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1));
108    char *infile = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1));
109    double *obj_val = (double *)calloc(DSIZE,file_num);
110    double tol = 1e-06;
111    spp_problem *spp;
112 
113    CALL_FUNCTION( sym_get_user_data(env, (void **)&spp) );
114 
115    if (strcmp(spp->par->test_dir, "") == 0){
116      strcpy(input_dir, ".");
117    } else{
118      strcpy(input_dir, spp->par->test_dir);
119    }
120 
121    sym_set_int_param(env, "verbosity", -10);
122    spp->par->verbosity = -10;
123 
124   for(i = 0; i<file_num; i++){
125 
126     strcpy(infile, "");
127     sprintf(infile, "%s%s%s", input_dir, "/", input_files[i]);
128     strcpy(spp->par->infile, infile);
129 
130     CALL_FUNCTION( sym_load_problem(env) );
131 
132     printf("Solving %s...\n", input_files[i]);
133 
134     CALL_FUNCTION( sym_solve(env) );
135 
136     sym_get_obj_val(env, &obj_val[i]);
137 
138     if((obj_val[i] < sol[i] + tol) &&
139        (obj_val[i] > sol[i] - tol)){
140       printf("Success!\n");
141     } else {
142       printf("Failure!(%f, %f) \n", obj_val[i], sol[i]);
143     }
144 
145     if(env->mip->n && i + 1 < file_num){
146       free_master_u(env);
147       strcpy(env->par.infile, "");
148       env->mip = (MIPdesc *) calloc(1, sizeof(MIPdesc));
149     }
150   }
151 
152   spp->par->test = FALSE;
153 
154   FREE(input_dir);
155   FREE(infile);
156   FREE(obj_val);
157 
158   return(0);
159 
160 }
161 
162 #endif
163 
164