JOM (Java Optimization Modeler)JOM (Java Optimization Modeler) is a free and open-source Java library targeted to allowing Java programs modeling and solving optimization problems, defining their input parameters, decision variables, objective function, and constraints. Mathematical expressions combining decision variables, constant parameters, operators and functions, are defined using a simple MATLAB-like syntax. JOM allows handling multidimensional arrays of variables and constants. This enables, for instance, defining arrays of constraints in a single line of code. To solve the problem, JOM can interface with installed solvers. Current JOM version can interface with MIPCL (free), GLPK (free), CPLEX (commercial) and XPRESS (commercial) solvers for mixed integer linear problems, and IPOPT (free) for non-linear differentiable problems. Let's see an example to show JOM simplicity. We want to solve a version of the 3-dimensional matching problem (e.g. see). We have three sets \( X, Y, Z \) of \( N \) elements each. We have to create tuples of three elements \( (i,j,k) \) where \( i \in X, j \in Y, k \in Z \), so that no element appears in more than one tuple. Each tuple \( (i,j,k) \) has assigned a benefit given by \( c_{ijk} \). The target is to find the set of tuples that are a matching (no element appears in more than one tuple), and have the maximum possible benefit. The formulation solving this problem is:
\( Example
import com.jom.DoubleMatrixND; import com.jom.OptimizationProblem; public class WWW_3DimMatching { public static void main(String[] args) { int N = 5; // number of elements in each set /* Create the optimization problem object */ OptimizationProblem op = new OptimizationProblem(); /* Add the decision variables to the problem */ op.addDecisionVariable("x", true, new int[] { N , N , N }, 0, 1); // name, isInteger, size , minValue, maxValue /* Set value for the input parameter c_{ijk} */ op.setInputParameter("c", new DoubleMatrixND(new int [] { N , N , N} , "random")); /* Sets the objective function */ op.setObjectiveFunction("maximize", "sum(x .* c)"); /* Add the constraints */ op.addConstraint(" sum(sum(x,3),2) <= 1"); // for each i \sum_{jk} x_{ijk} <= 1 op.addConstraint(" sum(sum(x,3),1) <= 1"); // for each j \sum_{ik} x_{ijk} <= 1 op.addConstraint(" sum(sum(x,2),1) <= 1"); // for each k \sum_{ij} x_{ijk} <= 1 /* Call the solver to solve the problem */ op.solve("glpk" , "solverLibraryName" , "glpk_4_47"); if (!op.solutionIsOptimal ()) throw new RuntimeException ("An optimal solution was not found"); /* Print the solution */ DoubleMatrixND sol = op.getPrimalSolution("x"); for (int c1 = 0 ; c1 < N ; c1 ++) for (int c2 = 0 ; c2 < N ; c2 ++) for (int c3 = 0 ; c3 < N ; c3 ++) if (sol.get(new int [] { c1 , c2 , c3}) == 1) System.out.println (c1 + " - " + c2 + " - " + c3); } }
JOM has been thought as a tool to assist the teaching and research activities which are focused on optimization, or where optimization problems are solved. Students/researchers can focus on solving optimization problems and analyzing the solutions obtained, getting rid of the burden of interfacing to the solvers, and making use of the flexibility that Java provides to handle the problem data. JOM is just accessed from standard Java programs, calling the methods in the JOM class OptimizationProblem. In addition, the JOM modeling language is much simpler than (although not as powerful as) commercial alternatives for modeling as AMPL or GAMS. Other features in JOM are:
And remember that JOM is free and open-source! It is licensed under the GNU Lesser General Public License (L-GPL). Then, you can use JOM as a library in your programs for free, can make money from them, and do not have to disclose your code. You are obligued to mention that you are using JOM in your program. |