How to get a minimum value that solve a system of inequalities?

639 Views Asked by At

I have searched about in here but it loses all sense when I try to implement LP in Java with JOptimizer library,

I need to find a way to solve this simple inequality:

x*k+y*k'>0

with:

1>=x>=0
1>=y>=0

Where k and k' are given constants.

What is the best way to solve this?

Can anyone help me to solve my problem?

1

There are 1 best solutions below

1
On BEST ANSWER

Seems you don't have the idea about linear programming. Please Read about it. Here is the answer you asked for.

import com.joptimizer.functions.ConvexMultivariateRealFunction;
import com.joptimizer.functions.LinearMultivariateRealFunction;
import com.joptimizer.optimizers.JOptimizer;
import com.joptimizer.optimizers.OptimizationRequest;
import com.joptimizer.optimizers.PrimalDualMethod;

/**
 *
 * @author K.P.L.Kanchana
 */
public class Demo {

    public static void main(String[] args){
//        BasicConfigurator.configure(); // uncomment and see the console log4j:WARN

           // setting value for k as k1 variable
           double k1 = 100.2;

           // setting value for k' as k2 variable
           double k2 = 30.4;

        // Objective function (plane)
        LinearMultivariateRealFunction objectiveFunction = new LinearMultivariateRealFunction(new double[] {-k1, -k2}, 0); // Maximize kX + K'X

        //inequalities (polyhedral feasible set G.X<H )
        ConvexMultivariateRealFunction[] inequalities = new ConvexMultivariateRealFunction[4];
        // x > 0 ('<=' constraints not applicable in JOptimizer)
        inequalities[0] = new LinearMultivariateRealFunction(new double[] {-1, 0}, 0); // -x > o
        // y > 0 ('<=' constraints not applicable in JOptimizer)
        inequalities[1] = new LinearMultivariateRealFunction(new double[] {0, -1}, 0); // -y > o
        // x < 1 ('<=' constraints not applicable in JOptimizer)
        inequalities[2] = new LinearMultivariateRealFunction(new double[] {1, 0}, -1); // x-1 < o
        // y < 1 ('<=' constraints not applicable in JOptimizer)
        inequalities[3] = new LinearMultivariateRealFunction(new double[] {0, 1}, -1); // y-1 < o

        //optimization problem
        OptimizationRequest or = new OptimizationRequest();
        or.setF0(objectiveFunction);
        or.setFi(inequalities);

        or.setToleranceFeas(JOptimizer.DEFAULT_FEASIBILITY_TOLERANCE);
        or.setTolerance(JOptimizer.DEFAULT_TOLERANCE);

        //optimization
        PrimalDualMethod opt = new PrimalDualMethod();
        opt.setOptimizationRequest(or);
        try {
            int returnCode = opt.optimize();
        }
        catch (Exception ex) {
            ex.printStackTrace();
            return;
        }

        // get the solution
        double[] sol = opt.getOptimizationResponse().getSolution();

        // display the solution
        System.out.println("X = " + sol[0]);
        System.out.println("X = " + sol[1]);
    }

}