Xpress Callbacks in Matlab: Difference between revisions

From TomWiki
Jump to navigationJump to search
(Created page with "There are eleven of the Xpress ''MP'' callbacks defined in the interface. A logical vector defines the callbacks to be used in Xpress ''MP''. This vector is named ''callback ''an...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
There are eleven of the Xpress ''MP'' callbacks defined in the interface. A logical vector defines the callbacks to be used in Xpress ''MP''. This vector is named ''callback ''and is one of the input variables to the level 1 interface routine ''xpress''. If the ''i''th entry of the logical vector callback is set, the corresponding callback is defined. The callback calls the ''m''-file specified in Table 2.  The user can edit this ''m''-file directly, or make a new copy. It is important that a new copy is placed in a directory that is searched before the ''xpress ''directory when Matlab goes through the Matlab path.
{{Part Of Manual|title=the Xpress Manual|link=[[Xpress|Xpress Manual]]}}
There are eleven of the Xpress<sup>''MP''</sup> callbacks defined in the interface. A logical vector defines the callbacks to be used in Xpress ''MP''. This vector is named ''callback ''and is one of the input variables to the level 1 interface routine ''xpress''. If the ''i''th entry of the logical vector callback is set, the corresponding callback is defined. The callback calls the ''m''-file specified in [[#Table: The m-file callback routines.]].  The user can edit this ''m''-file directly, or make a new copy. It is important that a new copy is placed in a directory that is searched before the ''xpress ''directory when Matlab goes through the Matlab path.
 
====Table: The m-file callback routines.====


{| class="wikitable"
{| class="wikitable"
!Index||m-file||Description
|+<caption>The m-file callback routines.</caption>
|-valign="top"
!Index||m-file||Description||Section
|-valign="top"
|-valign="top"
|(1)||xpcb usn||User Select Node Callback
|(1)||xpcb_usn||User Select Node Callback||[[Xpress Appendix D#xpcb_usn]]
|-valign="top"
|-valign="top"
|(2)||xpcb upn||User Preprocess Node Callback
|(2)||xpcb_upn||User Preprocess Node Callback||[[Xpress Appendix D#xpcb_upn]]
|-valign="top"
|-valign="top"
|(3)||xpcb uon||User Optimal Node Callback
|(3)||xpcb_uon||User Optimal Node Callback||[[Xpress Appendix D#xpcb_uon]]
|-valign="top"
|-valign="top"
|(4)||xpcb uin||User Infeasible Node Callback
|(4)||xpcb_uin||User Infeasible Node Callback||[[Xpress Appendix D#xpcb_uin]]
|-valign="top"
|-valign="top"
|(5)||xpcb uis||User Integer Solution Callback
|(5)||xpcb_uis||User Integer Solution Callback||[[Xpress Appendix D#xpcb_uis]]
|-valign="top"
|-valign="top"
|(6)||xpcb ucn||User Node Cut-off Callback
|(6)||xpcb_ucn||User Node Cut-off Callback||[[Xpress Appendix D#xpcb_ucn]]
|-valign="top"
|-valign="top"
|(7)||xpcb ucb||User Choose Branching Variable Callback
|(7)||xpcb_ucb||User Choose Branching Variable Callback||[[Xpress Appendix D#xpcb_ucb]]
|-valign="top"
|-valign="top"
|(8)||xpcb il||Simplex Log Callback
|(8)||xpcb_il||Simplex Log Callback||[[Xpress Appendix D#xpcb_il]]
|-valign="top"
|-valign="top"
|(9)||xpcb gl||Global Log
|(9)||xpcb_gl||Global Log||[[Xpress Appendix D#xpcb_gl]]
|-valign="top"
|-valign="top"
|(10)||xpcb bl||Barrier Log Callback
|(10)||xpcb_bl||Barrier Log Callback||[[Xpress Appendix D#xpcb_bl]]
|-valign="top"
|-valign="top"
|(11)||xpcb uop||User Output Callback
|(11)||xpcb_uop||User Output Callback||[[Xpress Appendix D#xpcb_uop]]
|}
|}


Before each call to the callback routine, the interface is defining the control variables and problem attributes as global variables in Matlab. By making the following global declarations in the callback ''m''-file, global  xpControlVariables xpProblemAttrib all control variables and problem attributes are accessible as subfields  to the global variables.
Before each call to the callback routine, the interface is defining the control variables and problem attributes as global variables in Matlab. By making the following global declarations in the callback ''m''-file,  
 
The ''Prob ''structure is input to all callback ''m''-file routines as the last parameter. If TOMLAB calls ''xpress'', then ''Prob ''is the standard TOMLAB  problem structure, otherwise the user optionally can set:  ''P rob.P ''= ''P roblemN umber'';, where ProblemNumber is some integer.  If any callback is  defined  (see description of callback) then the  arrays that define the current problem are set by the interface as fields in ''Prob''. The defined fields are ''Prob.c'', ''Prob.x L'', ''Prob.x U'', ''Prob.A'', ''Prob.b L'', ''Prob.b U ''and. ''Prob.QP.F''. The user then has full access to the original problem in the callback routine.
 
In one of the callback routines, ''xpcb gl'', a simple knapsack heuristic is implemented. This heuristic is also part of the standard Xpress''M P  ''example files. Running the knapsack test program ''xpknaps'', with the second input argument ''Run ''= 1 runs the knapsack heuristic in the callback. ''xpknaps ''sets ''Prob.MIP.KNAPSACK = 1 ''to enable execution of the heuristic in ''xpcb gl''.
 
If there are no integer variables in the problem to be solved, i.e.  a pure LP or QP problem, then the first seven callbacks as well as the 9th  callback (Global Log) are automatically disabled. If the problem is a mixed-integer problem,  then the  8th  callback (Simplex Log Callback) is disabled. This change is made on around row 254 i ''xpress.m ''and the user may comment this row (''callback''(8) = 0;) to avoid it.
 
==Test Routines in Non-Tomlab Format==
 
A set of test routines have been defined illustrating  the use of the ''xpress ''main routine.  The test routines and utilities are shown in Table 3.
 
It is easy to call the test routines, e.g.


<pre>
<pre>
x = xptest1;
global xpControlVariables xpProblemAttrib
x = xptest2;
x = xptest3;
</pre>
</pre>


will call the three routines solving GAP problems. The ''xpaircrew ''test problem has no input parameters, just call:
all control variables and problem attributes are accessible as subfields to the global variables.


<pre>
The ''Prob ''structure is input to all callback ''m''-file routines as the last parameter. If TOMLAB calls ''xpress'', then ''Prob ''is the standard TOMLAB  problem structure, otherwise the user optionally can set:  ''Prob.P ''= ''ProblemNumber'';, where ProblemNumber is some integer.  If any callback is defined (see description of callback) then the arrays that define the current problem are set by the interface as fields in ''Prob''. The defined fields are ''Prob.c'', ''Prob.x_L'', ''Prob.x_U'', ''Prob.A'', ''Prob.b_L'', ''Prob.b_U ''and. ''Prob.QP.F''. The user then has full access to the original problem in the callback routine.
xpaircrew;
</pre>


The knapsack test routine runs three test examples. It is possible to change the cut strategy (third input parameter) and whether to use the knapsack heuristic in the callback routine ''xpcb gl ''(second input parameter). To run the second test example, using the simple knapsack heuristic, and aggressive cuts, the call is
In one of the callback routines, ''xpcb_gl'', a simple knapsack heuristic is implemented. This heuristic is also part of the standard Xpress<sup>''MP''</sup> example files. Running the knapsack test program ''xpknaps'', with the second input argument ''Run ''= 1 runs the knapsack heuristic in the callback. ''xpknaps'' sets ''Prob.MIP.KNAPSACK = 1'' to enable execution of the heuristic in ''xpcb_gl''.


<pre>
If there are no integer variables in the problem to be solved, i.e. a pure LP or QP problem, then the first seven callbacks as well as the 9th  callback (Global Log) are automatically disabled. If the problem is a mixed-integer problem, then the  8th  callback (Simplex Log Callback) is disabled. This change is made on around row 254 in ''xpress.m ''and the user may comment this row (''callback''(8) = 0;) to avoid it.
xpknaps(2,1,2);
</pre>
 
The first parameter selects the test problem. Calling without any parameters
 
<pre>
xpknaps
</pre>
 
is the same as the call
 
<pre>
xpknaps(1,0,0);
</pre>
 
{|class="wikitable"
!Function||Description
|+<caption>The test routines and utilities.</caption>
|-valign="top"
|''abc2gap''||Utility to convert a Generalized Assignment Problem (GAP) to stan- dard form for Xpress''M P  ''.
|-valign="top"
|''xpbiptest''||Test of three large binary integer linear problems.
|-valign="top"
|''xpiptest''||Test of three large integer linear problems.
|-valign="top"
|''xpknaps''||Test of knapsack problems.
|-valign="top"
|''xptest1''||Test of a Generalized Assignment Problem (GAP).
|-valign="top"
|''xptest2''||Test of the same GAP problem as ''xptest1'', but using sos1 variables.
|-valign="top"
|''xptest3''||Test of a Generalized Assignment Problem (GAP).
|}

Latest revision as of 13:22, 22 January 2012

Notice.png

This page is part of the Xpress Manual. See Xpress Manual.

There are eleven of the XpressMP callbacks defined in the interface. A logical vector defines the callbacks to be used in Xpress MP. This vector is named callback and is one of the input variables to the level 1 interface routine xpress. If the ith entry of the logical vector callback is set, the corresponding callback is defined. The callback calls the m-file specified in #Table: The m-file callback routines.. The user can edit this m-file directly, or make a new copy. It is important that a new copy is placed in a directory that is searched before the xpress directory when Matlab goes through the Matlab path.

Table: The m-file callback routines.

The m-file callback routines.
Index m-file Description Section
(1) xpcb_usn User Select Node Callback Xpress Appendix D#xpcb_usn
(2) xpcb_upn User Preprocess Node Callback Xpress Appendix D#xpcb_upn
(3) xpcb_uon User Optimal Node Callback Xpress Appendix D#xpcb_uon
(4) xpcb_uin User Infeasible Node Callback Xpress Appendix D#xpcb_uin
(5) xpcb_uis User Integer Solution Callback Xpress Appendix D#xpcb_uis
(6) xpcb_ucn User Node Cut-off Callback Xpress Appendix D#xpcb_ucn
(7) xpcb_ucb User Choose Branching Variable Callback Xpress Appendix D#xpcb_ucb
(8) xpcb_il Simplex Log Callback Xpress Appendix D#xpcb_il
(9) xpcb_gl Global Log Xpress Appendix D#xpcb_gl
(10) xpcb_bl Barrier Log Callback Xpress Appendix D#xpcb_bl
(11) xpcb_uop User Output Callback Xpress Appendix D#xpcb_uop

Before each call to the callback routine, the interface is defining the control variables and problem attributes as global variables in Matlab. By making the following global declarations in the callback m-file,

global xpControlVariables xpProblemAttrib

all control variables and problem attributes are accessible as subfields to the global variables.

The Prob structure is input to all callback m-file routines as the last parameter. If TOMLAB calls xpress, then Prob is the standard TOMLAB problem structure, otherwise the user optionally can set: Prob.P = ProblemNumber;, where ProblemNumber is some integer. If any callback is defined (see description of callback) then the arrays that define the current problem are set by the interface as fields in Prob. The defined fields are Prob.c, Prob.x_L, Prob.x_U, Prob.A, Prob.b_L, Prob.b_U and. Prob.QP.F. The user then has full access to the original problem in the callback routine.

In one of the callback routines, xpcb_gl, a simple knapsack heuristic is implemented. This heuristic is also part of the standard XpressMP example files. Running the knapsack test program xpknaps, with the second input argument Run = 1 runs the knapsack heuristic in the callback. xpknaps sets Prob.MIP.KNAPSACK = 1 to enable execution of the heuristic in xpcb_gl.

If there are no integer variables in the problem to be solved, i.e. a pure LP or QP problem, then the first seven callbacks as well as the 9th callback (Global Log) are automatically disabled. If the problem is a mixed-integer problem, then the 8th callback (Simplex Log Callback) is disabled. This change is made on around row 254 in xpress.m and the user may comment this row (callback(8) = 0;) to avoid it.