min: x1+x2+x3+x4; 4*x1+3*x2-2*x3-x4>=2; x1+x2+6*x3+2*x4<=22; assign1: x3=x1+x2+1; int x1, x2, x3;
The first line must state the objective function and whether or not you wish to maximize or minimize it. The first line must begin with "min:" or "max:" and then be followed by the objective function and then a semicolon.
The constraints can be either <= or <= constraints. You can also included assignments, i.e., equality statements (like the x3=x1+x2+1 line above, which is labeled with "assign1:").
Constraint and assignment lines can be labelled, as the x3=x1+x2+1 line is. You should always label assignment lines. Unlabeled assignment lines can result in lpsolve ignoring your assignment. Labeling can make it easier to trace lpsolve results and troubleshoot. The labels can be essentially any string you want, followed by a colon (:) but it's probably best to stick to letters and numbers.
We can add variables, too, to help us keep track of results. The LP above could be written:
min: x1+x2+x3+x4; polar=4*x1+3*x2-2*x3-x4; polar>=2; grizzly=x1+x2+6*x3+2*x4; grizzly<=22; assign1: x3=x1+x2+1; int x1, x2, x3;
Here I have introduced variables, polar and grizzly, to keep track of some of the quantities in the LP. When lpsolve solves this LP, it will report the values of polar and grizzly, and from this it will be easy to see whether or not the polar constraint and the grizzly constraint are binding.
The last line specifies that x1, x2, and x3 are integer. In addition to int, we can also use bin to specify that variables are binary, i.e., they take on only the values 0 and 1. For example, instead of the int line above, the line
bin x1, x2, x3;
If there is no specification for a variable, lpsolve will treat the variable as real (floating-point). So in this example x4 would be a real variable (i.e., it might take on non-integer values).
You can mix the variable types: some can be real, some integer, some binary, by using multiple lines of this type.
min: +c_1+c_2+c_3+c_4+...+c_9+c_10+c_11+c_12; (11 lines of the following type: ensure that lower numbered colors are used before higher numbered colors) c_2<=c_1; . . c_12<=c_11; (12 lines of the following type: ensure that every vertex is colored with exactly one color) +x_1_1+x_1_2+x_1_3+...+x_1_10+x_1_11+x_1_12=1; . . (142 lines of the following type: ensure that the c variables keep track of colors that are used) x_1_1<= c_1; . . (251 lines of the following type: ensure vertices connected by edges are different colors) x_1_1+x_2_1 <=1; . . (ensure all variables are binary) bin x_1_1,...,x_12_12,c_1,...,c_12;
Often, many of the variables in a solution will be zero, so leave those out in your writeups, and add the comment "All other variables are zero." after you give the values of the non-zero variables, like this:
Value of objective function: 410.00000000 Actual values of the variables: x2 1 x4 1 x5 1 x6 1 x8 1 x9 1 All other variables are zero.This is much easier to read than a possibly very long list that the reader (and you!) would have to hunt through to find the ones.
lp_solve -ia inputFile.lpThis will print intermediate solutions as well, so if the computation takes a long time, you can watch its progress.