Skip to content
Browse files

initial commit

  • Loading branch information...
1 parent eebd765 commit 00e17c717b9e34c441df777ade3de7716b89a202 @nflip committed May 11, 2012
Showing with 98 additions and 0 deletions.
  1. +41 −0 simple/RDemo3.java
  2. +57 −0 simple/Simple.java
View
41 simple/RDemo3.java
@@ -0,0 +1,41 @@
+import lpsolve.*;
+
+public class RDemo3 {
+
+ public static void main(String[] args) {
+ try {
+ // Create a problem with 4 variables and 0 constraints
+ LpSolve solver = LpSolve.makeLp(0, 3);
+
+ // add constraints
+ solver.strAddConstraint("3 -2 0", LpSolve.LE, 6);
+ solver.strAddConstraint("2 -1 -1", LpSolve.GE, 4);
+ solver.strAddConstraint("1 2 3", LpSolve.LE, 10);
+
+ // set objective function
+ solver.strSetObjFn("-1 3 1");
+ solver.setMaxim();
+ solver.setLpName("Example from http://www.hs-augsburg.de/informatik/projekte/mebib/emiel/entw_inf/or_verf/linopt_bsp.html");
+ solver.setVerbose(3);
+ //solver.dualizeLp();
+ // solve the problem
+ solver.solve();
+ // solver.printTableau();
+ //solver.printDuals();
+ solver.printLp();
+ // print solution
+ System.out.println("Value of objective function: " + solver.getObjective());
+ double[] var = solver.getPtrVariables();
+ for (int i = 0; i < var.length; i++) {
+ System.out.println("Value of var[" + i + "] = " + var[i]);
+ }
+
+ // delete the problem and free memory
+ solver.deleteLp();
+ }
+ catch (LpSolveException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
View
57 simple/Simple.java
@@ -0,0 +1,57 @@
+import lpsolve.*;
+
+public class Simple {
+
+ public static void main(String[] args) {
+ try {
+ // Create a problem with 4 variables and 0 constraints
+ LpSolve solver = LpSolve.makeLp(0, 6);
+
+ // add constraints
+ solver.strAddConstraint("1 0 0 0 0 0", LpSolve.LE, 5);
+ solver.strAddConstraint("0 1 0 0 0 0", LpSolve.LE, 10);
+ solver.strAddConstraint("0 0 1 0 0 0", LpSolve.LE, 7);
+ solver.strAddConstraint("0 0 0 1 0 0", LpSolve.LE, 7);
+ solver.strAddConstraint("0 0 0 0 1 0", LpSolve.LE, 3);
+ solver.strAddConstraint("0 0 0 0 0 1", LpSolve.LE, 12);
+
+ solver.strAddConstraint("1 0 -1 0 0 0", LpSolve.EQ, 0);
+
+ solver.strAddConstraint("0 1 0 -1 -1 0", LpSolve.EQ, 0);
+
+ solver.strAddConstraint("0 0 1 1 0 -1", LpSolve.EQ, 0);
+
+
+
+
+ // set objective function
+ solver.strSetObjFn("1 1 0 0 0 0");
+ solver.setMaxim();
+ solver.setLpName("Simple example for assignment 1");
+ solver.setVerbose(3);
+ // solve the problem
+ //solver.dualizeLp();
+ solver.solve();
+
+ solver.printDuals();
+ // solver.printTableau();
+ // solver.printLp();
+ // print solution
+
+ System.out.println("Value of objective function: " + solver.getObjective());
+ double[] var = solver.getPtrVariables();
+ for (int i = 0; i < var.length; i++) {
+ System.out.println("Value of var[" + i + "] = " + var[i]);
+ }
+
+ // delete the problem and free memory
+
+ System.out.println(solver.getStatustext(solver.getStatus()));
+ solver.deleteLp();
+ }
+ catch (LpSolveException e) {
+ e.printStackTrace();
+ }
+ }
+
+}

0 comments on commit 00e17c7

Please sign in to comment.
Something went wrong with that request. Please try again.