FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Adding the message callback in Java

Description
The examples demonstrates how to define a messaging callback for the Xpress Optimizer in Java.

callback_java.zip[download all files]

Source Files





Callback.java

import com.dashoptimization.*;

class Callback implements XPRSmessageListener
{
    public void run ()
    {
        try {
            XPRSprob problem = new XPRSprob ();

            problem.setIntControl (XPRS.LPLOG, 1);
            problem.addMessageListener(this,null);

            problem.readProb ("javatest","");
            problem.lpOptimize ("");

            problem.removeMessageListener();
        } catch(XPRSprobException xpe) {
            xpe.printStackTrace();
        }
    }

    public void XPRSmessageEvent(XPRSprob prob,
        Object data, String msg, int len, int type)
    {
        if (msg != null) {
            System.out.println (msg);
        }
    }

    public static void main(String [] args)
    {
        try {
            XPRS.init ();
        } catch (Exception e) {
            System.out.println ("Failed to initialize");
            return;
        }

        try {
          Callback c = new Callback ();
          c.run ();

        } finally {
          XPRS.free ();
        }
    }
}

Back to examples browserPrevious exampleNext example