Giter Site home page Giter Site logo

irzinfante / fixed-mps Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 72 KB

Library to easily generate fixed MPS files for LP solvers

License: GNU General Public License v3.0

Java 100.00%
math lp mps optimization operations-research fixed-mps constraints linear-programming linear-programming-modeler lp-problem

fixed-mps's Introduction

Usage of the library

Let's put it simple. Having the following linear programming (LP) problem,

our goal is to generate, in the most simple and intuitive way, a fixed-format MPS file representing the problem.

We import the fixed-mps library from Maven with

<!-- https://mvnrepository.com/artifact/eu.irzinfante/fixed-mps -->
<dependency>
    <groupId>eu.irzinfante</groupId>
    <artifactId>fixed-mps</artifactId>
    <version>1.1.1</version>
</dependency>

Now, the instruction for building the LP problem is the following:

import eu.irzinfante.fixedmps.core.Problem;
import eu.irzinfante.fixedmps.core.Problem.ProblemBuilder;
import eu.irzinfante.fixedmps.core.Variable.VarBuilder;
import eu.irzinfante.fixedmps.core.Constraint.ConstraintBuilder;

Problem lp = new ProblemBuilder(

	new VarBuilder(-1).lowerBound(0).upperBound(Double.MAX_VALUE).integer().build(),
	new VarBuilder(-1).lowerBound(0).upperBound(Double.MAX_VALUE).integer().build()

)
.addConstraint(new ConstraintBuilder(-2,  2).greaterThan(1))
.addConstraint(new ConstraintBuilder(-8, 10).lessThan(13))
.build();

As we can see, the coefficient for each variable in the objective function is given at the time of declaring the variable. We tell also at this point if the variable is integer or binary (or we just build the variable to tell that it is a real).

Then we add the constraints for the problem row by row, giving the coeffient for each variable in order, an telling the type of the constraint (, or ) and the value of the free term.

Now, to get the MPS file (as a String) from the problem we do this:

import eu.irzinfante.fixedmps.util.MPSUtil;

MPSUtil.obtainMPSfile(lp)

The result in this case would be:

NAME          FIXEDMPS
ROWS
 N  OBJ
 G  C0000001
 L  C0000002
COLUMNS
    INT1      'MARKER'                 'INTORG'
    X0000001  C0000002  -8.00000e+00   C0000001  -2.00000e+00
    X0000001  OBJ       -1.00000e+00
    X0000002  C0000002  +1.00000e+01   C0000001  +2.00000e+00
    X0000002  OBJ       -1.00000e+00
    INT1END   'MARKER'                 'INTEND'
RHS
    RHS1      C0000001  +1.00000e+00
    RHS1      C0000002  +1.30000e+01
BOUNDS
 UP BND1      X0000001  +1.00000e+10
 UP BND1      X0000002  +1.00000e+10
ENDATA

License

Copyright (C) 2020-2023 Iker Ruiz de Infante Gonzalez [email protected]

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

LICENSE contains a copy of the full GPLv3 licensing conditions.

fixed-mps's People

Contributors

irzinfante avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.