Giter Site home page Giter Site logo

jscipopt's Introduction

This project provides an interface from the Java programming language to the SCIP solver software.

How to build a model using JSCIPOpt

There are several examples provided in the examples folder. These display some functionality of the interface and can serve as an entry point for writing more complex code. The following steps are always required when using the interface:

  1. It is necessary to add

    import jscip.*;

to the beginning of your Java file. This imports all needed classes to use the interfaces.

  1. Create a solver instance and initialize the internal C data structures with

    Scip scip = new SCIP();
    scip.create("Example");
    

This is the equivalent to calling SCIPcreate(&scip) and SCIPcreateProbBasic(scip, "Example") in C.

  1. The most important classes are Scip.java, Variable.java, Constraint.java, and Solution.java. They represent the C data structs SCIP, SCIP_VAR, SCIP_CONS,SCIP_SOL and provide some basic functionality. Using the Java classes works similar to C , e.g.,

    Variable vars = new Variables[2];
    vars[0] = scip.createVar("x", 1.0, 2.0, -1.0, SCIP_Vartype.SCIP_VARTYPE_INTEGER);
    vars[1] = scip.createVar("y", 3.0, 4.0, -2.0, SCIP_Vartype.SCIP_VARTYPE_CONTINUOUS);
    
    double[] vals = {1.0, -3.6};
    Constraint lincons = scip.createConsLinear("lincons", vars, vals, -scip.infinity(), 10.0);
    scip.addCons(lincons);
    scip.releaseCons(lincons);
    
    scip.solve();
    scip.free();
    

which creates two variables, a linear constraint, adds it to SCIP, solves the problem and finally frees it.

How to extend the interface

The package already contains an interface to SCIP created with the Simplified Wrapper and Interface Generator SWIG. Extending the interface requires to install SWIG. The following steps are necessary to add a new function to the interface:

  1. Add the signature of an interface function to src/scipjni.i, e.g.,

    SCIP_Real SCIPfeastol(SCIP* scip);

  2. Implement the function, depending on its signature, in java/jscip/{Scip,Variable,Constraint,Solution}.java, e.g.,

    public class Scip
    {
       private SWIGTYPE_p_SCIP _scipptr;
    
       ...
    
       public double feastol()
       {
          return SCIPJNI.SCIPfeastol(_scipptr);
       }
    }
    
  3. Follow the steps in INSTALL.md to compile JSCIPOpt.

Note that each of the four mentioned classes hold their own C pointer in a class generated by SWIG. The object of this class needs to be passed to the new implemented interface function.

After all previous steps it is now possible to call the function via

double ftol = scip.feastol();

jscipopt's People

Contributors

ambros-gleixner avatar charlene-hu avatar charlene-videoamp avatar fserra avatar hassancehef avatar hoangtungdinh avatar kkofler avatar mueldgog avatar xunzhang 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.