Debian Codegraph @

SYMPHONY/Applications/MPP/src/Master/mpp_main.c

raw
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.branchAndBound();
51
52 return(0);
53 }
54
55 #else
56
57 #include "symphony.h"
58 #include "sym_master.h"
59 #include "mpp.h"
60 #include <stdlib.h>
61
62 int mpp_test(sym_environment *env);
63
64 int main(int argc, char **argv)
65 {
66 int termcode;
67 mpp_problem *mpp;
68
69 sym_environment *env = sym_open_environment();
70
71 sym_version();
72
73 CALL_FUNCTION( sym_get_user_data(env, (void **)&mpp) );
74
75 CALL_FUNCTION( sym_parse_command_line(env, argc, argv) );
76
77 if(mpp->par.test){
78
79 mpp_test(env);
80
81 } else {
82
83 CALL_FUNCTION( sym_load_problem(env) );
84
85 CALL_FUNCTION( sym_find_initial_bounds(env) );
86
87 sym_set_int_param(env, "do_primal_heuristic", FALSE);
88
89 CALL_FUNCTION( sym_solve(env) );
90 }
91
92 CALL_FUNCTION( sym_close_environment(env) );
93
94 return(0);
95 }
96
97 /*===========================================================================*\
98 \*===========================================================================*/
99
100 int mpp_test(sym_environment *env)
101 {
102 int termcode, i, file_num = 1;
103 char input_files[2][MAX_FILE_NAME_LENGTH +1] = {"sample.mpp"};
104
105 double sol[1] = {70.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-03;
111 mpp_problem *mpp = (mpp_problem *) env->user;
112
113 if (strcmp(mpp->par.test_dir, "") == 0){
114 strcpy(input_dir, ".");
115 } else{
116 strcpy(input_dir, mpp->par.test_dir);
117 }
118
119 sym_set_int_param(env, "verbosity", -10);
120
121 for(i = 0; i<file_num; i++){
122
123 strcpy(infile, "");
124 sprintf(infile, "%s%s%s", input_dir, "/", input_files[i]);
125 strcpy(mpp->par.infile, infile);
126
127 CALL_FUNCTION( sym_load_problem(env) );
128
129 printf("Solving %s...\n", input_files[i]);
130
131 CALL_FUNCTION( sym_solve(env) );
132
133 sym_get_obj_val(env, &obj_val[i]);
134
135 if((obj_val[i] < sol[i] + tol) &&
136 (obj_val[i] > sol[i] - tol)){
137 printf("Success!\n");
138 } else {
139 printf("Failure!(%f, %f) \n", obj_val[i], sol[i]);
140 }
141
142 if(env->mip->n && i + 1 < file_num){
143 free_master_u(env);
144 strcpy(env->par.infile, "");
145 env->mip = (MIPdesc *) calloc(1, sizeof(MIPdesc));
146 }
147 }
148
149 mpp->par.test = FALSE;
150
151 FREE(input_dir);
152 FREE(infile);
153 FREE(obj_val);
154
155 return(0);
156
157 }
158
159 #endif