[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] Copy of problem
From: |
François Galea |
Subject: |
Re: [Help-glpk] Copy of problem |
Date: |
Tue, 30 Jan 2007 11:08:13 +0100 |
User-agent: |
IceDove 1.5.0.9 (X11/20061220) |
Hi,
address@hidden a écrit :
There is some function of
GLPK to create a #8220;copy #8221; of the problem I am using?
Something like LPX*copy_prob=lpx_copy_problem(original_prob);
I need to restore the
original problem several times...
Please see the following message:
http://lists.gnu.org/archive/html/help-glpk/2003-08/msg00023.html
I have downlaoded the provided file some time ago. The GLPK API has
changed a bit since this source code was released, hence it doesn't
compile on recent releases of GLPK.
I have attached an updated version, which compiles smoothly with GLPK 4.13.
/* lpx_copy_prob */
#include <stddef.h>
#include "glpk.h"
LPX *lpx_copy_prob(LPX *orig)
{ /* create a copy of given problem object */
LPX *copy;
int m, n, i, j, type, stat, *ind, len, clss;
double lb, ub, *val;
/* create a copy */
copy = lpx_create_prob();
/* problem name */
lpx_set_prob_name(copy, lpx_get_prob_name(orig));
/* problem class */
clss = lpx_get_class(orig);
lpx_set_class(copy, clss);
/* rows */
m = lpx_get_num_rows(orig);
lpx_add_rows(copy, m);
for (i = 1; i <= m; i++)
{ /* row name */
lpx_set_row_name(copy, i, lpx_get_row_name(orig, i));
/* type and bounds */
lpx_get_row_bnds(orig, i, &type, &lb, &ub);
lpx_set_row_bnds(copy, i, type, lb, ub);
/* current status */
lpx_get_row_info(orig, i, &stat, NULL, NULL);
lpx_set_row_stat(copy, i, stat);
}
/* columns */
n = lpx_get_num_cols(orig);
lpx_add_cols(copy, n);
for (j = 1; j <= n; j++)
{ /* column name */
lpx_set_col_name(copy, j, lpx_get_col_name(orig, j));
/* column kind */
if (clss == LPX_MIP)
lpx_set_col_kind(copy, j, lpx_get_col_kind(orig, j));
/* type and bounds */
lpx_get_col_bnds(orig, j, &type, &lb, &ub);
lpx_set_col_bnds(copy, j, type, lb, ub);
/* objective coefficient */
lpx_set_obj_coef(copy, j, lpx_get_obj_coef(orig, j));
/* current status */
lpx_get_col_info(orig, j, &stat, NULL, NULL);
lpx_set_col_stat(copy, j, stat);
}
/* objective name */
lpx_set_obj_name(copy, lpx_get_obj_name(orig));
/* objective sense */
lpx_set_obj_dir(copy, lpx_get_obj_dir(orig));
/* constant term of the objective */
lpx_set_obj_coef(copy, 0, lpx_get_obj_coef(orig, 0));
/* constraint matrix */
ind = ucalloc(1+m, sizeof(int));
val = ucalloc(1+m, sizeof(double));
for (j = 1; j <= n; j++)
{ len = lpx_get_mat_col(orig, j, ind, val);
lpx_set_mat_col(copy, j, len, ind, val);
}
ufree(ind);
ufree(val);
return copy;
}
/* eof */