18 #define POS(R,C,NC) ((R)*(NC)+(C))
21 static char*
errors[]={
"ERROR! Function \'loadMatrix\' -> \'calloc\'.\n"
22 ,
"ERROR! Function \'printRes\' -> \'newArray\'.\n"
23 ,
"ERROR! Function \'printRes\' -> \'malloc\'.\n"
24 ,
"ERROR! Function \'printRes\' -> \'arrayInsert\'.\n"
25 ,
"ERROR! Invalid parameters.\n"
37 res=calloc((condc+1+eqc)*(varc+condc+eqc+2),
sizeof(
double));
49 for(col=0;col<k-2;col++)
52 res[
POS(0,col,k)]=tmp?type*(*tmp):0;
63 res[
POS(row,k-2,k)]=exp->
rhs;
64 res[
POS(row,k-1,k)]=row+varc-1;
66 for(col=0;col<varc;col++)
69 res[
POS(row,col,k)]=tmp?*tmp:0;
81 res[
POS(row,k-2,k)]=-1*(exp->
rhs);
82 res[
POS(row,k-1,k)]=row+varc-1;
84 for(col=0;col<varc;col++)
87 res[
POS(row,col,k)]=tmp?-(*tmp):0;
94 for(row=0;row<condc;row++)
95 for(col=0;col<condc;col++)
96 res[
POS(row+1,col+varc,k)]=row==col;
103 void printRes(
Array vars,
double* tab,
const char* varob,
int varc,
int condc,
int type)
118 for(i=1;i<condc+1;i++)
119 if(tab[
POS(i,k-1,k)]<varc)
121 tmp=malloc(
sizeof(
double));
128 *tmp=tab[
POS(i,k-2,k)];
137 puts(
"====================");
138 printf(
"%s = %f\n",varob,-type*tab[
POS(0,k-2,k)]);
139 puts(
"--------------------");
144 if(!
arrayAt(res,i,(
void**)&tmp)) printf(
" %f\n",*tmp);
145 else printf(
" 0.0\n");
147 puts(
"====================");
155 int opt(
int argc,
char** argv,
char** in,
char** out)
159 static struct option options[]={{
"output" ,required_argument,NULL,
'o'}
160 ,{
"input" ,required_argument,NULL,
'i'}
161 ,{
"tables" ,no_argument ,NULL,
't'}
162 ,{
"help" ,no_argument ,NULL,
'h'}
163 ,{
"version",no_argument ,NULL,
'v'}
169 while((c=getopt_long(argc,argv,
"o:i:thv",options,NULL))!=-1)
173 case 'o' : *out=optarg;
175 case 'i' : *in=optarg;
179 case 'h' : puts(
"rlp version 1.5, Copyright (C) 2006, 2009, 2015 Rui Carlos Goncalves\n"
180 "rlp comes with ABSOLUTELY NO WARRANTY. This is free software, and\n"
181 "you are welcome to redistribute it under certain conditions. See the GNU\n"
182 "General Public Licence for details.\n\n"
183 "Solve linear programming problems using simplex method.\n\n"
185 " --help Print this help\n"
186 " --version Print version info\n"
187 " --input=<file> Input file (default: stdin)\n"
188 " --tables Print all tables\n"
189 " --output=<file> Output file (default: stdout)"
193 case 'v' : puts(
"rlp version 1.5, Copyright (C) 2006, 2009, 2015 Rui Carlos Goncalves\n"
194 "rlp comes with ABSOLUTELY NO WARRANTY. This is free software, and\n"
195 "you are welcome to redistribute it under certain conditions. See the GNU\n"
196 "General Public Licence for details."
void arrayDelete(Array array)
Deletes an array.
Array newArray(int size)
Creates an empty array, with the specified initial capacity.
Array coefs
Coefficients of the variables.
double * loadMatrix(Prob prob, int varc, int condc, int eqc, int type)
From the info collected by the parser, creates a matrix representing the problem to solve...
int op
Operator of the expression.
int listRemoveFst(List list, void **value)
Removes the first element of a list.
Definition of functions used by main.
int arrayAt(Array array, int index, void **elem)
Provides the element at the specified position of an array.
#define POS(R, C, NC)
Given a row (R), a column (C), and the number of columns (NC) of a matrix, computes an equivalent 1D ...
static char * errors[]
Error messages.
List exps
List of expressions (objective function, and conditions).
int arrayMap(Array array, void(*fun)(void *))
Applies a function to the elements of an array.
int opt(int argc, char **argv, char **in, char **out)
Checks the options specified by the user.
void printRes(Array vars, double *tab, const char *varob, int varc, int condc, int type)
Prints the result.
double rhs
Right-hand side of the expression.
int arrayInsert(Array array, int index, void *elem, int replace)
Inserts an new element at the specified position of an array.