[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] Only one data file allowed in GLPK
From: |
Xypron |
Subject: |
[Help-glpk] Only one data file allowed in GLPK |
Date: |
Sat, 27 Sep 2008 19:36:42 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.16) Gecko/20080702 SeaMonkey/1.1.11 |
Hello Andrew,
currently only one data file is allowed in GLPK. This is an unnecessary
restriction.
One use case for multiple data files is keeping master data (e.g.
machines, products, ...) separated from transactional data (orders,
demands) and from parameters, which comes in handy when calculating
different scenarios for the same model. Another use case arises when
working with SQL. It would be wise to keep database connection
information containing passwords separated from other data.
When I analyzed the code I found that the necessary changes in
glpmpl04.c and glplpx17.c are minor:
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.31-multiple_data_files/src/glpmpl04.c?view=diff&r1=286&r2=285&diff_format=h
http://glpk.dyndns.org/viewvc/svn/glpk/glpk/branches/glpk-4.31-multiple_data_files/src/glplpx17.c?view=diff&r1=286&r2=285&diff_format=h
Best regards
Xypron
--- glpk/glpk/trunk/glpk-4.31/src/glplpx17.c 2008/09/25 19:56:22 285
+++ glpk/glpk/branches/glpk-4.31-multiple_data_files/src/glplpx17.c
2008/09/27 17:09:13 286
@@ -27,6 +27,8 @@
#include "glpmpl.h"
#define fault old_fault
+#define MAX_IN_DATA 20
+
/*--------------------------------------------------------------------*/
/* This program is a stand-alone LP/MIP solver. For pure LP problems */
/* either the simplex method or the primal-dual interior point method */
@@ -45,7 +47,8 @@
static const char *in_file = NULL;
/* name of input text file */
-static const char *in_data = NULL;
+static const char *in_data[MAX_IN_DATA];
+static int in_data_cnt = 0;
/* name of optional input text file, which contains data section; NULL
means no separate data section is provided */
@@ -438,11 +441,11 @@
{ xprintf("No data input file specifed\n");
return 1;
}
- if (in_data != NULL)
- { xprintf("Only one data input file allowed\n");
+ if (in_data_cnt >= MAX_IN_DATA )
+ { xprintf("Only %i data input files allowed\n", MAX_IN_DATA);
return 1;
}
- in_data = argv[k];
+ in_data[in_data_cnt++] = argv[k];
}
else if (p("-y") || p("--display"))
{ k++;
@@ -792,6 +795,7 @@
{ LPX *lp = NULL;
MPL *mpl = NULL;
int ret;
+ int i;
xlong_t start;
/* parse command line parameters */
ret = parse_cmdline(argc, argv);
@@ -853,7 +857,7 @@
/* initialize the translator database */
mpl = mpl_initialize();
/* read model section and optional data section */
- ret = mpl_read_model(mpl, (char *)in_file, in_data != NULL);
+ ret = mpl_read_model(mpl, (char *)in_file, in_data_cnt != 0);
if (ret == 4)
err: { xprintf("Model processing error\n");
ret = EXIT_FAILURE;
@@ -861,9 +865,9 @@
}
xassert(ret == 1 || ret == 2);
/* read data section, if necessary */
- if (in_data != NULL)
+ for ( i = 0; i < in_data_cnt; i++, ret=1)
{ xassert(ret == 1);
- ret = mpl_read_data(mpl, (char *)in_data);
+ ret = mpl_read_data(mpl, (char *)in_data[i]);
if (ret == 4) goto err;
xassert(ret == 2);
}
--- glpk/glpk/trunk/glpk-4.31/src/glpmpl04.c 2008/09/25 19:56:22 285
+++ glpk/glpk/branches/glpk-4.31-multiple_data_files/src/glpmpl04.c
2008/09/27 17:09:13 286
@@ -699,7 +699,7 @@
-- processing. */
int mpl_read_data(MPL *mpl, char *file)
-{ if (mpl->phase != 1)
+{ if (mpl->phase != 1 && mpl->phase != 2)
xfault("mpl_read_data: invalid call sequence\n");
if (file == NULL)
xfault("mpl_read_data: no input filename specified\n");
- [Help-glpk] Only one data file allowed in GLPK,
Xypron <=