Integrated Logistics PROBE - matf.bg.ac.rs · CPXaddrows status=CPXaddrows (env, lp, NUMCOLS,...
Transcript of Integrated Logistics PROBE - matf.bg.ac.rs · CPXaddrows status=CPXaddrows (env, lp, NUMCOLS,...
CPLEX(short guide)
MPIO-CPLEX
CPXopenCPLEX
initializes a CPLEX environment
must be the first CPLEX routine called
env=CPXopenCPLEX (&status)
Parameters:
A pointer to an integer variable status, where an error code is placed by this routine.
Returns:
Pointer env to CPLEX environment
If an error occurs the value env=NULL is returned.
The reason for the error is returned in the variable status.
If the routine is successful, then status=0.
See: http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.3.0/ilog.odms.cplex.help/html/refcallablelibrary/html/functions/CPXopenCPLEX.html?cp=SSSA5P_12.3.0%2F4-6-2-0-598
http://www.iro.umontreal.ca/~gendron/IFT6551/CPLEX/HTML/refcallablelibrary/html/functions/CPXopenCPLEX.html
CPXcreateprob
creates a CPLEX problem object in the CPLEX environment
The problem that is created is an LP minimization problem with zero constraints, zero variables, and an empty constraint matrix. The CPLEX problem object exists until the routine CPXfreeprob() is called.
lp=CPXcreateprob (env, &status, “problem_name”)
Parameters:
env pointer to the CPLEX environment as returned by routine CPXopenCPLEX.
&status pointer to an integer used to return any error code produced by this routine
“problem_name” character string that specifies the name of the problem being created.
Returns:
If successful, CPXcreateprob() returns variable lp that can be passed to other CPLEX routines to identify the problem object that is created.
If not successful, a lp=NULL is returned, and an error status is returned in the variable status. If the routine is successful, status =0.
See:http://www-
01.ibm.com/support/knowledgecenter/SSSA5P_12.3.0/ilog.odms.cplex.help/html/refcallablelibrary/html/functions/CPXXNETcreateprob.html?cp=SSSA5P_12.3.0%2F4-6-2-0-62
http://www.iro.umontreal.ca/~gendron/IFT6551/CPLEX/HTML/refcallablelibrary/html/functions/CPXcreateprob.html
CPXchgobjsen
Changes objective function type : mimimization or maximization
CPXchgobjsen(env, lp, CPX_MAX/CPX_MIN )
Parameters:
env pointer to the CPLEX environment as returned by CPXopenCPLEX.
lp pointer to a CPLEX problem object as returned by CPXcreateprob.
An integer that indicates the new sense of the problem:
CPX_MAX (= -1)
CPX_MIN (=1)
Returns:
This routine does not return a result.
See:
http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.3.0/ilog.odms.cplex.help/html/refcallablelibrary/html/functions/CPXchgobjsen.html?cp=SSSA5P_12.3.0%2F4-6-2-0-394
CPXnewcols
adds empty columns (i.e. variables) to a specified CPLEX LP problem object. This routine may be called any time AFTER a call to CPXcreateprob()
status=CPXnewcols (env, lp, NUMCOLS, obj, lb, ub, ctype, colname);
Parameters:
env, lp....
NUMCOLS Number of variables (columns) to be added
obj An array of length NUMCOLS containing the objective function coefficients of the new variables. In case of NULL, the new objective coefficients are all set to 0.
lb An array of length NUMCOLS containing the lower bound on each of the new variables. In case of NULL, the new lower bounds are all set to 0
ub An array of length NUMCOLS containing the upper bound on each of the new variables. In case of NULL, the new lower bounds are all set to CPX_INFBOUND.
ctype An array type char of length NUMCOLS containing the type of each of the new variables. In case of NULL, the new variables are continuous type.
colname An array type char of length NUMCOLS containing character strings that specify the names of the new columns=variables added to the problem object. In case of NULL, the new columns=variables remain default names.
See:http://www-
01.ibm.com/support/knowledgecenter/SSSA5P_12.3.0/ilog.odms.cplex.help/html/refcallablelibrary/html/functions/CPXnewcols.html
CPXaddrows
status=CPXaddrows (env, lp, NUMCOLS, NUMROWS,NUMNZ, rhs, sense, rmatbeg, rmatind, rmatval, colname, rowname);
Parameters:
rmatbeg An array used to denote the position of each row to be added.
The nonzero elements of every row i must be stored in sequential location from position rmatbeg[i] to rmatbeg[i+1]-1
(or from rmatbeg[i] to NUMNZ -1 if i=NUMROWS-1)
All rows must be contiguous, and rmatbeg[0] =0
rmatind Each entry of the array rmatind[i], specifies the column index (variable) of on the i-th position; rmatind[0]=0,
rmatval The value of the coefficient with the variable rmatind[i], on the position i isequal to rmatval[i].
colname An array of length NUMCOLS containing pointers to character strings that represent the names of the new columns= the new variable names.
rowname An array containing pointers to character strings that represent the names of the new rows, or equivalently, the constraint names.
See:
http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.3.0/ilog.odms.cplex.help/html/refcallablelibrary/html/functions/CPXaddrows.html
CPXaddrows
adds constraints to a specified LP problem object problem object. This routine may be called any time AFTER a call to CPXcreateprob().
status=CPXaddrows (env, lp, NUMCOLS, NUMROWS,NUMNZ, rhs, sense, rmatbeg, rmatind, rmatval, colname, rowname);
Parameters:
NUMCOLS An integer that indicates the number of new columns to be added to the constraint matrix.
NUMROWS An integer that indicates the number of new rows to be added to the constraint matrix
NUMNZ An integer that indicates the number of nonzero constraint coefficients to be added to the constraint matrix.
rhs An array of length NUMROWS containing the right-hand side term for each constraint to be added to the LP problem object. May be NULL, in which case, the new right-hand side values are set to 0.
sense An array of type char length NUMROWS containing the sense of each constraint to be added to the LP problem. May be NULL, in which case, the new constraints are created as equality constraints.
CPXlpopt
finds a solution to that problem using one of CPLEX's optimizers.
status=CPXlpopt (env, lp)
Parameters
The parameter CPX_PARAM_LPMETHOD controls the choice of optimizer controls the choice of optimizer (dual simplex, primal simplex, barrier, network simplex....).
By default settings CPLEX invokes the dual simplex method
Return Value
The routine returns zero unless an error occurred during the optimization. Examples of errors include exhausting available memory (CPXERR_NO_MEMORY) or encountering invalid data in the CPLEX problem object (CPXERR_NO_PROBLEM).
Exceeding a user-specified CPLEX limit, or proving the model infeasible or unbounded, are not considered errors.
See:
http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.3.0/ilog.odms.cplex.help/html/refcallablelibrary/html/functions/CPXlpopt.html
status=CPXprimopt(env, lp) for solving an LP by primal optimizer
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXprimopt.html
status=CPXdualopt(env, lp) for solving an LP by dual optimizer
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXdualopt.html
status=CPXmipopt(env, lp) for Mixed integer programming
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXmipopt.html
status=CPXqpopt(env, lp) for solving a QP by Quadratic program optimizer
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r3/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXqpopt.html
status=CPXbaropt (env, lp) for solving a QP, LP, QCP by Barrier optimizer
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXbaropt.html
status=CPXhybnetopt(env, lp, method) for solving an LP,NP problem by CPLEX Network Optimizer
given a linear program that has been created via a call to CPXcreateprob, extracts an embedded network, uses the CPLEX Network Optimizer to attempt to obtain an optimal basis to the network, and optimizes the entire linear program using one of the CPLEX simplex methods. CPLEX takes the network basis as input for the optimization of the whole linear program.
method= CPX_ALG_PRIMAL for primal Simplex
method= CPX_ALG_DUAL for dual Simplex
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXhybnetopt.html
CPXsolution
The routine CPXsolution() is used to access the solution values produced by the routines CPXlpopt(), CPXprimopt(), CPXdualopt(), CPXbaropt(), CPXhybbaropt(), CPXhybnetopt(), or CPXqpopt().
The solution is maintained until the CPLEX problem object is freed via a call to CPXfreeprob() or the solution is rendered invalid because of a call to one of the problem modification routines.
status=CPXsolution (env, lp, lpstat, objval, x,y, slack, rc)
Parameters
lpstat = pointer to an integer indicating the result of the optimization
obj= objective function value
x= array of the values of the primal variables for the problem
y= array of the values of the dual variables for each of the constraints
slack= the values of the slack variables for each of the constraints
rc=receive the values of the reduced costs for each of the variables.
Return Value
lpstat=integer value (solution status code)
http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.2.0/ilog.odms.cplex.help/Content/Optimization/Documentation/CPLEX/_pubskel/CPLEX1117.html?lang=en
See:
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXsolution.html
CPXchgprobtype
change the current problem to a related problem .
status=CPXchgprobtype (env, lp, type);
Parameters:
type tipa int
0 CPXPROB_LP linear program, no ctype or quadratic data stored.
1 CPXPROB_MILP problem with ctype information.
3 CPXPROB_FIXEDMILP problem with ctype information, integer variables fixed.
5 CPXPROB_QP problem with quadratic data stored.
7 CPXPROB_MIQP problem with quadratic data and ctype information.
8 CPXPROB_FIXEDMIQP problem with quadratic data and ctype information, integer variables fixed.
10 CPXPROB_QCP problem with quadratic constraints.
11 CPXPROB_MIQCP problem with quadratic constraints and ctype information.
The routine returns zero on success and nonzero if an error occurs.
See:
http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r3/index.jsp?topic=%2Filog.odms.cplex.help%2Fhtml%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXchgprobtype.html
CPXfreeprob
removes the specified CPLEX problem object from the CPLEX environment and frees the associated memory used internally by CPLEX.
The routine is used when the user has no need for further access to the specified problem data.
status=CPXlfreeprob (env, lp)
Returns:
The routine returns zero on success and nonzero if an error occurs.
See:
http://www.iro.umontreal.ca/~gendron/IFT6551/CPLEX/HTML/refcallablelibrary/html/functions/CPXfreeprob.html
CPXcloseCPLEX
This routine frees all of the data structures associated with CPLEX and releases the license. It should be the last CPLEX routine called in any Callable Library application.
status=CPXcloseCPLEX(env)
Returns:
The routine returns zero on success and nonzero if an error occurs.
See:
http://www.iro.umontreal.ca/~gendron/IFT6551/CPLEX/HTML/refcallablelibrary/html/functions/CPXcloseCPLEX.html
Useful links:
http://www-01.ibm.com/support/docview.wss?uid=swg27017577
http://www.iro.umontreal.ca/~gendron/IFT6551/CPLEX/HTML/refcallablelibrary/html/index/index.html
ftp://public.dhe.ibm.com/software/websphere/ilog/docs/optimization/cplex/ps_usrmancplex.pdf
Callable library examples:
http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.2.0/ilog.odms.cplex.help/Content/Optimization/Documentation/CPLEX/_pubskel/CPLEX1084.html
Parameter settings:
http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.6.0/ilog.odms.cplex.help/CPLEX/Parameters/topics/introListAlpha.html?lang=en
http://www-01.ibm.com/support/knowledgecenter/SS9UKU_12.5.0/com.ibm.cplex.zos.help/GettingStarted/topics/tutorials/InteractiveOptimizer/settingParams.html
http://www-eio.upc.es/lceio/manuals/cplex-11/html/
Primeri
MPIO-CPLEX
Ovi problemi su doživeli pravu ekspanziju, najviše zahvaljujući svojojširokoj primeni u praksi
Sistemi telekomunikacije, transport putnika ili robe, kargo prevoz, DHL i drugi sistemi brze isporuke, bežične mreže, satelitska komunikacija, itd...
Cilj je zadovoljiti potrebe korisnika uz minimalne troškove
Habovi (hubs) predstavljaju centre konsolidacije i kolekcije protoka u mreži
Neki od čvorova mreže se proglašavaju za habove
Cena transporta između habova je niža po jedinici količine
Koristeći habove kapacitet mreže se može iskoristiti dosta efikasnije i smanjiti ukupni troškovi transporta u mreži, ili smanjiti troškovi transporta za najgori slučaj snabdevač - korisnik
Hab lokacijski problemi
Primer
2
5 36
5
16
6
20
5
16
6
1 4
6
32
5
snabdevač korisnik
habhab
Direktno: 20*1=20
Neka je cena transporta između ne-hab čvorova u mreži je 1, a
između habova 0.25 po jedinici količine robe.
Preko habova: 6*1 + 16*0.25 + 5*1= 15
20
7
5 6
Tipovi hab lokacijskih problema?
Više kriterijuma za klasifikaciju
1. Prema alokacijskoj šemi: single-allocation, multiple allocation
2. Prema funkciji cilja: median, centar
3. Prema kapacitetima: uncapacitated, capacitated (različiti tipovi kapaciteta!)
4. Broj habova koje treba uspostaviti?
5. Fiksirana hab mreža (backbone network)?
6. Fiksni troškovi?
7. Itd...
Većina HLP su NP-teški
Lokacijski i alokacijski deo
Hab lokacijski problemi
Hab lokacijski problem neograničenih
kapaciteta sa jednostrukim alokacijama
The Uncapacitated Single Allocation Hub
Location Problem (USAHLP)
NP- težak problem
Hab lokacijski problem neograničenih
kapaciteta sa jednostrukim alokacijama
Primer: poštanske mreže
U svakom od n mesta 0,1,2,…n-1 nalaze se poštanske jedinice. Među postojećim poštanskim jedinicama potrebno izabrati određeni broj pošta u kojima se će se pošiljke sakupljati i sortirati (pošte-habovi)
Sve pošiljke iz određene poštanske jedinice mesta moraju uvek ići preko iste pošte-haba (hab čvor)
Nije dozvoljen direktan transport između poštanskih jedinica koje nisu pošte-habovi (ne-hab čvorova)
Ne postoji ograničenje u broju (količini) pošiljki koji se sakupljaju u ili transportuju iz neke pošte-haba
Za uspostavljanje svake pošte-haba potreno je izdvojiti određena sredstva
Potrebno je minimizovati sumu transportnih troškova u poštanskoj mreži i fiksnih troškova uspostavljanja pošta-habova
Hab lokacijski problem neograničenih
kapaciteta sa jednostrukim alokacijamaFormulacija problema
I={0,...,n-1} skup različitih čvorova mreže, pri čemu svaki čvor označava
lokaciju korisnika/snabdevača ili potencijalnu lokaciju haba
C ij = cena transporta od i-tog do j-tog čvora (obično jednaka ili prop. rast.)
Wij = količina protoka (robe) koji treba transportovati od i-tog do j-tog čvora
fк = fiksni troskovi uspostavljanja haba na lokaciji (čvoru) k
Promenljive Zik =1 ako je čvor i pridružen habu k, 0 inače,
Zkk =1 ako je čvor k hab, 0 inače.
Y ikl =količina protoka koja polazi iz čvora i, a distribuira se preko habova k i l
Parametri χ, α i δ redom označavaju troškove (cenu) kolekcije, transfera i distribucije robe po jedinici količine
li jk
Cena transporta jedinice količine robe duž puta i k l j je χ*Cik+ α *Ckl+ δ *Clj
Ne gubeći na opštosti, pretpostavimo da je cena jednaka rastojanju, tj Cij=dij=d(i,j)
χ α δ
Matematički model USAHLP:
incoming and outcomig
flow for node i
Hab lokacijski problem ograničenih
kapaciteta sa jednostrukim alokacijama
The Capacitated Single Allocation Hub Location
Problem (CSAHLP)
NP- težak problem
Matematički model CSAHLP:
Problem lokacije centara za produženu
negu pacijenata
Long-Term Care Facility Location Problem
(LTCFLP)
NP- težak problem
Problem lokacije centara za produženu
negu pacijenata
U n gradova (ili datih lokacija) potrebno je izgraditi određeni broj centara za produženu negu pacijenata. Označino sa J={0,1,…,n-1} skup potencijalnihlokacija za izgradnju centara.
Moguće je izgraditi najviše K centara (K<n)
Svaki čvor označava lokaciju jedne grupe pacijenata, odnosno potencijalnu lokaciju centra
Svaka grupa pacijenata se pridružuje najbližem uspostavljenom centru i određena je svojom lokacijom i veličinom (broj pacijanata)
Nema ograničenja kapaciteta centara niti fiksnih troškova uspostavljanja centra
Potrebno je minimizovati maksimalni broj pacijenata koji je pridružen jednom uspostavljenom centru
Primer n=33 regiona u Južnoj Koreji
Primer n=33 regiona u Južnoj Koreji
Matematička formulacija problema LTCFLP
J= {0,1,2…,n-1} skup od n različitih čvorova mreže, pri čemu svaki čvor označava lokaciju grupe pacijenata, odnosno potencijalnu lokaciju centra
dij = rastojanje od i-tog do j-tog čvora
ai = broj pacijenata u grupi i
K=max broj centara koji može biti uspostavljen
M=pozitivna const. (velika vrednost)
Binarne promenljive:
Xij =1 ako je čvor i pridružen čvoru j, 0 inače,
yj =1 ako je centar uspostavljen u čvoru j, 0 inače
(optimizacija modela?)
Nenegativna promenljiva Lmax predstavlja funkciju cilja (max broj pacijenata pridružen jednom uspostavljenom centru)
Matematička formulacija problema LTCFLP