Forum Discussion

FICO's avatar
FICO
Community Manager
3 years ago

Print intermediate solution and bounds with Mosel

Hi, I tried to search forit but I did not find any answer.

Is it possible, while solving a MIP from Mosel, to get the incumbent and the best bound at specific time limits (e.g., after every 1000 seconds)?

3 Replies

  • FICO's avatar
    FICO
    Community Manager

    There are currently no Optimizer callbacks tied to timed events. You could try using the optnode callback, which will be called once per node during the branch-and-bound tree and combine this with a message callback to ensure more callbacks are fired from the root node.

    See below for a demonstration of the optnode callback for a periodic output after freq many seconds.

    model "periodically report best solution and bound during a solve"
     uses "mmsystem", "mmxprs"
     
     forward public function periodic_optnode: boolean
    !setparam("XPRS_verbose", true)
      
     ! initialize initial time
     starttime := gettime
     lasttime := starttime
     
     ! frequency (minimum (fraction of) seconds between two consecutive prints)
     freq := 1000.0
     
     setcallback(XPRS_CB_OPTNODE, "periodic_optnode")
     
     !
     !  ... your solve commands here
     !
     
     public function periodic_optnode: boolean
      if gettime - lasttime >= freq then
       writeln("(Opt Node ", gettime - starttime, " seconds, Best Bound: ", getparam("XPRS_BESTBOUND"), " Best Solution: ", getparam("XPRS_MIPBESTOBJVAL"));
       lasttime := gettime
      end-if
     end-function
     
    end-model
  • FICO's avatar
    FICO
    Community Manager

    A modification to the previous answer: Mosel implements the Optimizer callback CHECKTIME, since Xpress Release 9.0 (Mosel 6.2) this callback can be configured to be invoked at regular time intervals. Please take a look at this example that shows the use of various solver callbacks (including CHECKTIME configured with a time interval) for reporting purposes: elscb_graph.mos

  • FICO's avatar
    FICO
    Community Manager

    NB: This example also forms part of the Xpress distribution (see subdirectory examples/mosel/WhitePapers/MoselPar of your Xpress installation).