Codebase list mccs / upstream/1.01
Imported Upstream version 1.01 Ralf Treinen 10 years ago
4 changed file(s) with 31 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
0
1 mccs 1.01 (24/05/11):
2 * correct some bugs in lp_solver.c: there was some troubleshot in reading solutions from underlying solvers
3
205205 rm -f lpsolver.out
206206 rm -f installed.txt removed.txt
207207 rm -f sol
208 rm -f cplex.log clone0.log
208209 rm -f */*~
209210
210211
99 #include <math.h>
1010
1111 #define OUTPUT_MODEL 0
12 #define USEXNAME 0
1213
1314 // solver creation
1415 abstract_solver *new_cplex_solver() { return new cplex_solver(); }
9697 lb[i] = 0;
9798 ub[i] = 1;
9899 vartype[i] = 'B';
99 varname[(*ipkg)->rank] = (*ipkg)->versioned_name;
100 if (USEXNAME) {
101 char *name;
102 char buffer[20];
103
104 sprintf(buffer, "x%d", i);
105 if ((name = (char *)malloc(strlen(buffer)+1)) == (char *)NULL) {
106 fprintf(stderr, "CUDF error: can not alloc memory for variable name in cplex_solver::end_objective.\n");
107 exit(-1);
108 }
109 strcpy(name, buffer);
110 varname[(*ipkg)->rank] = name;
111 } else
112 varname[(*ipkg)->rank] = (*ipkg)->versioned_name;
100113 i++;
101114 }
102115
107120
108121 sprintf(buffer, "x%d", i);
109122 if ((name = (char *)malloc(strlen(buffer)+1)) == (char *)NULL) {
110 fprintf(stderr, "CUDF error: can not alloc memory for variable name in glpk_solver::end_objective.\n");
123 fprintf(stderr, "CUDF error: can not alloc memory for variable name in cplex_solver::end_objective.\n");
111124 exit(-1);
112125 }
113126 strcpy(name, buffer);
101101
102102 if (verbosity < 2)
103103 sprintf(command, "cat %s >> %s; %s %s > %s 2> /dev/null",
104 ctlpfilename, lpfilename, lpsolver, lpfilename, lpoutfilename);
104 ctlpfilename, lpfilename, lpsolver, lpfilename, lpoutfilename);
105105 else
106106 sprintf(command, "cat %s >> %s; %s %s | tee %s",
107107 ctlpfilename, lpfilename, lpsolver, lpfilename, lpoutfilename);
129129 }
130130 break;
131131 case 'C':
132 if (strncmp(command, "Coin:Infeasible - objective value", 33) == 0)
132 if ((strncmp(command, "Coin:Infeasible - objective value", 33) == 0) ||
133 (strncmp(command, "CPLEX> MIP - Integer infeasible.", 32) == 0))
133134 status = 0;
134135 else if (strncmp(command, "Coin:Optimal - objective value", 30) == 0) {
135136 status = 1;
136137 if (sscanf(command+30, "%d", &iobjval) > 0) objval = objvals[iobj] = iobjval;
138 } else if (strncmp(command, "CPLEX> MIP - Integer optimal solution: Objective = ", 52) == 0) {
139 status = 1;
140 if (sscanf(command+52, "%d", &iobjval) > 0) objval = objvals[iobj] = iobjval;
137141 }
138142 break;
139143 }
148152 for (int i = 0; i < nb_packages; i++) solution[i] = 0;
149153
150154 bool eos = false;
151 while ((! eos) && (! feof(fsol)) && (fgets(command, 1000, fsol) != NULL))
155 while ((! eos) && (! feof(fsol)) && (fgets(command, 1000, fsol) != NULL)) {
152156 switch (command[0]) {
153157 case 'x':
154 {
155 int l = 0, v = 0;
156 if ((l = sscanf(command+1, "%d", &rank)) > 0)
157 if (sscanf(command+l+2, "%d", &v) > 0)
158 if (v == 1)
159 solution[rank] = 1;
160 }
158 if (sscanf(command+1, "%d", &rank) > 0) solution[rank] = 1;
161159 break;
162160 case ' ':
163161 {
164 int i = 1, l = 0, v = 0;
162 int i = 1;
165163 for (; ((command[i] != 'x') && (i < 1000)); i++);
166164 if (command[i] == 'x')
167 if ((l = sscanf(command+i+1, "%d", &rank)) > 0)
168 if (sscanf(command+i+l+2, "%d", &v) > 0)
169 if (v == 1)
170 solution[rank] = 1;
171
165 if (sscanf(command+i+1, "%d", &rank) > 0) solution[rank] = 1;
172166 }
173167 break;
174168 case '\n':
175 case 'C':
176169 eos = true;
177170 break;
178171 }
172 }
179173 } else if (status == 0)
180174 break;
181175 }