Add graph references
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/* Last update: 08-May-2013 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "glpk.h"
|
||||
#include "proxy.h"
|
||||
|
||||
/**********************************************************************/
|
||||
int main(int argc, char **argv)
|
||||
/**********************************************************************/
|
||||
{
|
||||
glp_prob *lp;
|
||||
int ncols, status;
|
||||
double *initsol, zstar, *xstar;
|
||||
|
||||
/* check arguments */
|
||||
if ( (argc == 1) || (argc > 3) ) {
|
||||
printf("ERROR: Usage: ts <instance> <(possibly) xml initsols>\n"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* creating the problem */
|
||||
lp = glp_create_prob();
|
||||
glp_set_prob_name(lp, "Proxy");
|
||||
|
||||
/* reading the problem */
|
||||
glp_term_out(GLP_OFF);
|
||||
#if 0 /* by mao */
|
||||
status = glp_read_lp(lp, NULL, argv[1]);
|
||||
#else
|
||||
status = glp_read_mps(lp, GLP_MPS_FILE, NULL, argv[1]);
|
||||
#endif
|
||||
glp_term_out(GLP_ON);
|
||||
if ( status ) {
|
||||
printf("Problem %s does not exist!!!, status %d\n",
|
||||
argv[1], status);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ncols = glp_get_num_cols(lp);
|
||||
|
||||
initsol = (double *) calloc(ncols+1, sizeof(double));
|
||||
|
||||
if (argc == 3) {
|
||||
FILE *fp=fopen(argv[2],"r");
|
||||
char tmp[256]={0x0};
|
||||
int counter = 1;
|
||||
while(fp!=NULL && fgets(tmp, sizeof(tmp),fp)!=NULL)
|
||||
{
|
||||
char *valini = strstr(tmp, "value");
|
||||
if (valini!=NULL){
|
||||
int num;
|
||||
double dnum;
|
||||
valini +=7;
|
||||
sscanf(valini, "%d%*s",&num);
|
||||
dnum = (double)num;
|
||||
initsol[counter] = dnum;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
xstar = (double *) calloc(ncols+1, sizeof(double));
|
||||
|
||||
if (argc == 3) {
|
||||
status = proxy(lp, &zstar, xstar, initsol, 0.0, 0, 1);
|
||||
}
|
||||
else {
|
||||
status = proxy(lp, &zstar, xstar, NULL, 0.0, 0, 1);
|
||||
}
|
||||
|
||||
printf("Status = %d; ZSTAR = %f\n",status,zstar);
|
||||
/*
|
||||
int i;
|
||||
for (i=1; i< ncols+1; i++) {
|
||||
printf("XSTAR[%d] = %f\n",i, xstar[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
glp_delete_prob(lp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+1069
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
/* proxy.h (proximity search heuristic algorithm) */
|
||||
|
||||
/***********************************************************************
|
||||
* This code is part of GLPK (GNU Linear Programming Kit).
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
* Written by Giorgio Sartor <0gioker0@gmail.com>.
|
||||
*
|
||||
* GLPK is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GLPK is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GLPK. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef PROXY_H
|
||||
#define PROXY_H
|
||||
|
||||
#define proxy _glp_proxy
|
||||
int proxy(glp_prob *lp, double *zstar, double *xstar,
|
||||
const double initsol[], double rel_impr, int tlim,
|
||||
int verbose);
|
||||
|
||||
#endif
|
||||
|
||||
/* eof */
|
||||
@@ -0,0 +1,86 @@
|
||||
/* proxy1.c */
|
||||
|
||||
/***********************************************************************
|
||||
* This code is part of GLPK (GNU Linear Programming Kit).
|
||||
* Copyright (C) 2013, 2018 Free Software Foundation, Inc.
|
||||
* Written by Andrew Makhorin <mao@gnu.org>.
|
||||
*
|
||||
* GLPK is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GLPK is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GLPK. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************/
|
||||
|
||||
#include "env.h"
|
||||
#include "ios.h"
|
||||
#include "proxy.h"
|
||||
|
||||
void ios_proxy_heur(glp_tree *T)
|
||||
{ glp_prob *prob;
|
||||
int j, status;
|
||||
double *xstar, zstar;
|
||||
/* this heuristic is applied only once on the root level */
|
||||
if (!(T->curr->level == 0 && T->curr->solved == 1))
|
||||
goto done;
|
||||
prob = glp_create_prob();
|
||||
glp_copy_prob(prob, T->mip, 0);
|
||||
xstar = xcalloc(1+prob->n, sizeof(double));
|
||||
for (j = 1; j <= prob->n; j++)
|
||||
xstar[j] = 0.0;
|
||||
if (T->mip->mip_stat != GLP_FEAS)
|
||||
status = proxy(prob, &zstar, xstar, NULL, 0.0,
|
||||
T->parm->ps_tm_lim, 1);
|
||||
else
|
||||
{ double *xinit = xcalloc(1+prob->n, sizeof(double));
|
||||
for (j = 1; j <= prob->n; j++)
|
||||
xinit[j] = T->mip->col[j]->mipx;
|
||||
status = proxy(prob, &zstar, xstar, xinit, 0.0,
|
||||
T->parm->ps_tm_lim, 1);
|
||||
xfree(xinit);
|
||||
}
|
||||
if (status == 0)
|
||||
#if 0 /* 17/III-2016 */
|
||||
glp_ios_heur_sol(T, xstar);
|
||||
#else
|
||||
{ /* sometimes the proxy heuristic reports a wrong solution, so
|
||||
* make sure that the solution is really integer feasible */
|
||||
int i, feas1, feas2, ae_ind, re_ind;
|
||||
double ae_max, re_max;
|
||||
glp_copy_prob(prob, T->mip, 0);
|
||||
for (j = 1; j <= prob->n; j++)
|
||||
prob->col[j]->mipx = xstar[j];
|
||||
for (i = 1; i <= prob->m; i++)
|
||||
{ GLPROW *row;
|
||||
GLPAIJ *aij;
|
||||
row = prob->row[i];
|
||||
row->mipx = 0.0;
|
||||
for (aij = row->ptr; aij != NULL; aij = aij->r_next)
|
||||
row->mipx += aij->val * aij->col->mipx;
|
||||
}
|
||||
glp_check_kkt(prob, GLP_MIP, GLP_KKT_PE, &ae_max, &ae_ind,
|
||||
&re_max, &re_ind);
|
||||
feas1 = (re_max <= 1e-6);
|
||||
glp_check_kkt(prob, GLP_MIP, GLP_KKT_PB, &ae_max, &ae_ind,
|
||||
&re_max, &re_ind);
|
||||
feas2 = (re_max <= 1e-6);
|
||||
if (feas1 && feas2)
|
||||
glp_ios_heur_sol(T, xstar);
|
||||
else
|
||||
xprintf("WARNING: PROXY HEURISTIC REPORTED WRONG SOLUTION; "
|
||||
"SOLUTION REJECTED\n");
|
||||
}
|
||||
#endif
|
||||
xfree(xstar);
|
||||
glp_delete_prob(prob);
|
||||
done: return;
|
||||
}
|
||||
|
||||
/* eof */
|
||||
Reference in New Issue
Block a user