Forum Discussion

FICO's avatar
FICO
Community Manager
7 years ago

How to load a MIP solution?

Dear all,

Currently, I am trying to provide an initial solution to my IP that has three multidimensional (binary) decision variables (x(N), y(N,M) and z(M)). I know that there are the two functions loadmipsol and addmipsol and I perfectly understand the difference. However, I cannot find a simple example that shows explicitly how to provide a start solution by setting x(1) = 0, x(2) = 1,.... y(1,1) = 0, y2,1) = 1...

That is, how do I use loadmipsol?

Thanks in advance and best regards,

Szymon

5 Replies

  • FICO's avatar
    FICO
    Community Manager

    I figured it out, here some pseudo code:

    declarations
    	
    	! sets
    	N: set of integer
    	M: set of integer
    	
    	! decision variables
    	x: array(N) of mpvar
    	y: array(N,M) of mpvar
    	z: array(M) of mpvar
    	
    	! objective function	
    	obj: linctr                  	
    	
    	! arrays that contain your start solution
    	xStrt: array(N) of integer
    	yStrt: array(N,M) of integer
    	zStrt: array(M) of integer
    	
    	! array that allows you to load the start solution into your variables
    	strtSol: array(mpvar) of real
    	
    end-declarations
     
    ! ------------ ------------- ----------- 
    ! Write your model here....
    ! ....
     
    ! ------------ ------------- ----------- 
    ! Load start solution into variables
    forall(n in N) do
    	strtSol(x(n)) := xStrt(n)
    end-do
     
    forall(n in N, m in M) do
    	strtSol(y(n,m)) := yStrt(n,m)
    end-do
     
    forall(m in M) do
    	strtSol(z(m)) := zStrt(m)
    end-do
     
    ! IMPORTANT! Load problem (compare example "d1wagon2.mos")
    loadprob(obj)
     
    ! ------------ ------------- ----------- 
    ! Load solution into problem
     
    ! Version 1: the way the solution was loaded above suggests that you provide
    ! a complete start solution. Then you can use "loadmipsol"
     
    ! loadmipsol returns a status code about the solution, see
    ! https://www.maths.ed.ac.uk/hall/Xpress/FICO_Docs/mosel/mosel_lang/dhtml/loadmipsol.html
    result := loadmipsol("strtSol",strtSol)
     
    ! Version 2: you can also provide a part of the solution (e.g. set only x). Then,
    ! "addmipsol" will try to build a feasible solution out of that.
    ! To re-inforce the search, one can require Xpress to spend more effort on the 
    ! local search heuristics by " setparam("XPRS_USERSOLHEURISTIC",3)"
    addmipsol("strtSol",strtSol)
     
    ! Re-inforce use of user solution in local search heuristics 
    setparam("XPRS_USERSOLHEURISTIC",3)
     
    ! Reporting use of user solution (since addmipsol is a procedure, not a function)
    setcallback(XPRS_CB_SOLNOTIFY,"solnotify")  
     
     
    ! The procedure; taken from example "d1wagon2.mos"
     public procedure solnotify(id:string, status:integer)
      writeln("Optimiser loaded solution '", id, "' status=", status)
     end-procedure
  • FICO's avatar
    FICO
    Community Manager

    Your version 2 that uses 'addmipsol' is generally preferable since this routine is more flexible, in particular it allows you to provide partial or slightly infeasible solutions (see https://www.fico.com/fico-xpress-optimization/docs/latest/mosel/mosel_lang/dhtml/addmipsol.html )

    It also has an alternative version that takes an 'mpsol' object as its second argument which could be populated as follows for your example:

     declarations

       MySol2: mpsol  

     end-declarations

     forall(n in N) setsol(MySol2, x(n), xStrt(n))

     forall(n in RN, m in RM) setsol(MySol2, y(n,m), Strt(n,m))

     forall(m in RM) setsol(MySol2, z(m), zStrt(m))

     addmipsol("UserSol2", MySol2)     

  • FICO's avatar
    FICO
    Community Manager

    Thank you for your answer. When using addmipsol, XPRS_CB_SOLNOTIFY returns me the status code 8. However, I cannot find an overview of solnotify codes similar to loadmipsol exit codes (https://www.fico.com/fico-xpress-optimization/docs/latest/solver/optimizer/HTML/XPRSloadmipsol.html). Does Fico provide such an overview?

  • FICO's avatar
    FICO
    Community Manager

    Perfect, thanks for your quick reply!