Home

OR-Objects FAQ

1. General
    1.1 - What is OR-Objects?
    1.2 - How much does it cost?
    1.3 - Can I use the freeware version for commercial applications?
    1.4- Can I use the freeware version on a client-server based application?

2. Standard - How Do I ...
    2.1 - Generate random numbers from a probability distribution?
    2.2 - Find the mean and standard deviation of a vector?
    2.3 - Integrate a function numerically?
    2.4 - Solve an equation numerically?
    2.5 - Find the inverse of a matrix?
    2.6 - Solve simultaneous linear equations?
    2.7 - Find the shortest path in a graph?
    2.8 - Optimize using linear programming?
    2.9 - Use probability distributions to model arrivals?
    2.10 - Color the vertices and edges of a graph?
    2.11 - Solve a Traveling Salesman Problem?
    2.12 - Solve a Vehicle Routing Problem?
    2.13 - Estimate the population mean, median and proportion from a sample?
    2.14 - Perform correlation analysis?
    2.15 - Solve multiple regression problems?


1. General


1.1 What is OR-Objects?

OR-Objects  is a library of Javatm classes for developing Operations Research applications. The purpose of OR-Objects is to provide a foundation of reusable software to speed the development of OR applications and make them more reliable. OR-Objects includes data structures and algorithms for developing custom solutions as well as many classical algorithms.


1.2 How much does it cost?

The freeware version of OR-Objects costs nothing. You can get a single copy and use it for private or commercal applications. The freeware version can not be redistributed.Here is the license agreement.


1.3 Can I use the freeware version for commercial applications?

Yes, here is the license agreement.


1.4 Can I use the freeware version on a server based application?

Yes, a single copy installed on the server. Here is the license agreement.


2. How Do I ...


2.1 Generate random numbers from a probability distribution?

 The continuous and discrete distribution classes are contained in the probability package drasys.or.prob. Here is an example that generates random numbers from a normal distribution with a mean of 2.0 and standard deviation of 3.0.

  2.2 Easily find the mean and standard deviation of a vector?

The vector classes are contained in the matrix package drasys.or.matrix. Here is an example that creates a vector and then computes the mean and standard deviation.

2.3 Integrate a function numerically?

The integration classes are contained in the nonlinear package drasys.or.nonlinear. Here is an example that integrates ex from 0.0 to 1.0.

2.4 Solve an equation numerically?

The equation solution classes are contained in the nonlinear package drasys.or.nonlinear. Here is an example that solves for the value of  x in gamma(x) = 4.0;

2.5 Find the inverse of a matrix?

The linear algebra classes are contained in the algebra package drasys.or.linear.algebra. Here is an example that inverts a random matrix and then checks the results.

2.6 Solve simultaneous linear equations?

The decomposition classes are contained in the algebra package drasys.or.linear.algabra. Here is an example that solves a set of simultaneous equations for multiple right hand side vectors.

2.7 Find the shortest path in a graph?

The graph classes are contained in the graph package drasys.or.graph. There are two tutorials in the OR-Objects Tutorials that demonstrate the use of shortest path algorithms. Tutorial-1 shows how to use OR-Objects to find the shortest path between two vertices. Tutorial-2 shows how to find multiple paths to or from a single vertex.


2.8 Optimize using linear programming?

The linear programming classes are contained in the mathematical programming package drasys.or.mp.lp. This example shows how to use OR-Objects to optimize a small linear model using the simplex algorithm.
 
Linear Model

 (max) Z = 20x1 + 15x2

 c1:   x1         <=  100
 c2:          x2  <=  100
 c3: 50x1 + 35x2  <=  6000
 c4: 20x1 + 15x2  >=  2000

import drasys.or.mp.*;
import drasys.or.mp.lp.*;

public class MpExample
{

    public static void
    main(String[] args)
    throws Exception
    {
        SizableProblemI prob = new Problem(4,2);
        prob.getMetadata().put("lp.isMaximize", "true");

        prob.newVariable("x1").setObjectiveCoefficient(20.0);
        prob.newVariable("x2").setObjectiveCoefficient(15.0);

        final byte LTE = Constraint.LESS;
        final byte GTE = Constraint.GREATER;
        prob.newConstraint("c1").setType(LTE).setRightHandSide(  100.0);
        prob.newConstraint("c2").setType(LTE).setRightHandSide(  100.0);
        prob.newConstraint("c3").setType(LTE).setRightHandSide( 6000.0);
        prob.newConstraint("c4").setType(GTE).setRightHandSide( 2000.0);

        // Columnwise insertion is more efficient for the default matrix.
        prob.setCoefficientAt("c1",  "x1",  1.0);
        prob.setCoefficientAt("c3",  "x1", 50.0);
        prob.setCoefficientAt("c4",  "x1", 20.0);
        prob.setCoefficientAt("c2",  "x2",  1.0);
        prob.setCoefficientAt("c3",  "x2", 35.0);
        prob.setCoefficientAt("c4",  "x2", 15.0);

        LinearProgrammingI lp = new DenseSimplex(prob);
        double ans = lp.solve();
        System.out.println("Solution = "+ans);
    }

}


2.9 Use probability distributions to model arrivals?

The probability package drasys.or.prob contains the probability distribution classes and Tutorial-3 demonstrates the use of the ExponentialDistribution and the EmpiricalDistribution to model passengers entering an elevator system.


2.10 Color the vertices and edges of a graph?

The graph classes are contained in the graph coloring package drasys.or.graph.color. This examples shows how to use OR-Objects to color the vertices and edges of the following graph where ths vertices are labeled A through G and the edges are labeled one through ten.


2.11 Solve a Traveling Salesman Problem?

The TSP package drasys.or.graph.tsp contains the traveling salesman problem classes and Tutorial-4 demonstrates the use of several of the TSP algorithms in OR-Objects.


2.12 Solve a Vehicle Routing Problem?

The VRP package drasys.or.graph.vrp contains the traveling salesman problem classes and Tutorial-6 demonstrates the use of several of the VRP algorithms in OR-Objects.


2.13 Estimate the population mean, median and proportion from a sample?

The statistical estimation classes are contained in the package drasys.or.stat.est.Here is an example that creates a sample and then estimates the mean, median and proportion along with the associated confidence intervals.

3. Professional - How Do I ...



 

2.14 Perform correlation analysis?


        double[][]data = {
            {47,4.2}, {71,8.1}, {64,6.8}, {35,4.3}, {43,5.0},
            {60,7.5}, {38,4.7}, {59,5.9}, {67,6.9}, {56,5.7},
            {67,5.7}, {57,5.4}, {69,7.5}, {38,3.8}, {54,5.9},
            {76,6.3}, {53,5.7}, {40,4.0}, {47,5.2}, {23,2.2},
        };

        LinearCorrelation lc = new LinearCorrelation(new ColumnMajorMatrix(data));
 

        MatrixI sumSquares = lc.getSumOfSquares();
        System.out.println("Sum of squares for col-0 = " + sumSquares.elementAt(0);
        System.out.println("Sum of squares for col-1 = " + sumSquares.elementAt(1);

        MatrixI sumProd = lc.getSumOfProducts();
        System.out.println("Sum of squares for col-0 = " + sumProd.elementAt(0,0);
        System.out.println("Sum of squares for col-1 = " + sumProd.elementAt(1,1);
        System.out.println("Sum of products for col-0 and col-1 = " + sumProd.elementAt(0,1);

        MatrixI correlation = lc.getCorrelation();
        System.out.println("Correlation for col-0  and col-1 = " + correlation.elementAt(0,1);

        MatrixI upperBound = lc.getUpperBound(0.95);
        System.out.println("Correlation upper bound for col-0  and col-1 = " + upperBound.elementAt(0,1);

        MatrixI lowerBound = lc.getLowerBound(0.95);
        System.out.println("Correlation lower bound for col-0  and col-1 = " + lowerBound.elementAt(0,1);
 


2.15 Solve multiple regression problems?

        double[] dep = {
            19929, 5839,  23696,  9881, 30011,
             7241, 11634, 45684, 36476, 12068,
        };

        double[][] indep = {
            {10.5, 2200}, { 2.5, 1000}, {13.1, 3250}, { 4.0, 1475}, {14.7, 3800},
            { 3.6, 1200}, { 7.1, 1900}, {22.5, 5575}, {17.0, 4200}, { 6.4, 1850},
        };

        VectorI dependent = new DenseVector(da);
        MatrixI independent = new RowArrayMatrix(ia, true);
        LinearRegressionI reg = new ReverseLinear(dependent, independent);

        // Print coefficients
        VectorI coef = reg.getCoefficients();
        System.out.println("Intercept Coefficient = "+coef.elementAt(2));
        System.out.println("Column-0  Coefficient = "+coef.elementAt(0));
        System.out.println("Column-1  Coefficient = "+coef.elementAt(1));

        //Print regression report
        System.out.println(reg);
 


Copyright (C) 1997-2000 by DRA Systems all rights reserved.