1 /* Last update: 08-May-2013 */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "glpk.h"
8 #include "proxy.h"
9
10 /**********************************************************************/
main(int argc,char ** argv)11 int main(int argc, char **argv)
12 /**********************************************************************/
13 {
14 glp_prob *lp;
15 int ncols, status;
16 double *initsol, zstar, *xstar;
17
18 /* check arguments */
19 if ( (argc == 1) || (argc > 3) ) {
20 printf("ERROR: Usage: ts <instance> <(possibly) xml initsols>\n"
21 );
22 exit(1);
23 }
24
25 /* creating the problem */
26 lp = glp_create_prob();
27 glp_set_prob_name(lp, "Proxy");
28
29 /* reading the problem */
30 glp_term_out(GLP_OFF);
31 #if 0 /* by mao */
32 status = glp_read_lp(lp, NULL, argv[1]);
33 #else
34 status = glp_read_mps(lp, GLP_MPS_FILE, NULL, argv[1]);
35 #endif
36 glp_term_out(GLP_ON);
37 if ( status ) {
38 printf("Problem %s does not exist!!!, status %d\n",
39 argv[1], status);
40 exit(1);
41 }
42
43 ncols = glp_get_num_cols(lp);
44
45 initsol = (double *) calloc(ncols+1, sizeof(double));
46
47 if (argc == 3) {
48 FILE *fp=fopen(argv[2],"r");
49 char tmp[256]={0x0};
50 int counter = 1;
51 while(fp!=NULL && fgets(tmp, sizeof(tmp),fp)!=NULL)
52 {
53 char *valini = strstr(tmp, "value");
54 if (valini!=NULL){
55 int num;
56 double dnum;
57 valini +=7;
58 sscanf(valini, "%d%*s",&num);
59 dnum = (double)num;
60 initsol[counter] = dnum;
61 counter++;
62 }
63 }
64 fclose(fp);
65 }
66
67 xstar = (double *) calloc(ncols+1, sizeof(double));
68
69 if (argc == 3) {
70 status = proxy(lp, &zstar, xstar, initsol, 0.0, 0, 1);
71 }
72 else {
73 status = proxy(lp, &zstar, xstar, NULL, 0.0, 0, 1);
74 }
75
76 printf("Status = %d; ZSTAR = %f\n",status,zstar);
77 /*
78 int i;
79 for (i=1; i< ncols+1; i++) {
80 printf("XSTAR[%d] = %f\n",i, xstar[i]);
81 }
82 */
83
84 glp_delete_prob(lp);
85
86 return 0;
87 }
88