AMPL: "Bad suffix .npool for Initial" error with poolstub - ampl

I need to find a pool of solutions with AMPL (I am relatively new to it) using the option "poolstub" but I get an error when I try to retrive them. I will try to explain everything step by step. This is my code:
option solver cplex;
model my_model.mod;
data my_data.dat;
option cplex_options 'poolstub=multmip poolcapacity=10 populate=1 poolintensity=4 poolreplace=1';
solve;
At this point AMPLE gives me this:
CPLEX 20.1.0.0: poolstub=multmip
poolcapacity=10
populate=1
poolintensity=4
poolreplace=1
CPLEX 20.1.0.0: optimal solution; objective 4.153846154
66 dual simplex iterations (0 in phase I)
It seems like AMPL has not stored the solutions in the pool.
And in fact, if I try to retrive them with this code
for {i in 1..Current.npool} {
solution ('multmip' & i & '.sol');
display _varname, _var;
}
I get this error:
Bad suffix .npool for Initial
context: for {i in >>> 1..Current.npool} <<< {
Possible suffix values for Initial.suffix:
astatus exitcode message relax
result sstatus stage
for{...} { ? ampl: for{...} { ? ampl:
I have no integer variables, only real ones and I read that CPLEX doesn't support the populate method for linear programs. Could this be the problem or is something else missing? Thank you in advance

You have identified your problem correctly. Entity Initial does not have the npool suffix, which means the solver (in your case CPLEX) did not return one.
Gurobi can return that information for linear programs, but it seems to be identical to the optimal solution, so it would not give you any extra information (more info on AMPL-Gurobi options).
Here is an example AMPL script:
model net1.mod;
data net1.dat;
option solver gurobi;
option gurobi_options 'ams_stub=allopt ams_mode=1';
solve;
for {n in 1..Total_Cost.npool} {
solution ("allopt" & n & ".sol");
display Ship;
}
Output (on my machine):
Gurobi 9.1.1: ams_stub=allopt
ams_mode=2
ams_epsabs=0.5
Gurobi 9.1.1: optimal solution; objective 1819
1 simplex iterations
Alternative MIP solution 1, objective = 1819
1 alternative MIP solutions written to "allopt1.sol"
... "allopt1.sol".
Alternative solutions do not include dual variable values.
Best solution is available in "allopt1.sol".
suffix npool OUT;
Alternative MIP solution 1, objective = 1819
Ship :=
NE BOS 90
NE BWI 60
NE EWR 100
PITT NE 250
PITT SE 200
SE ATL 70
SE BWI 60
SE EWR 20
SE MCO 50
;
The files net1.mod and net1.dat are from the AMPL book.
When solving a MIP the solver can store sub-optimal solutions that it found along the way as they might be interesting for some reason to the modeler.
In terms of your LP, are you interested in the vertices the simplex algorithm visits?

Related

Getting "DUAL_INFEASIBLE" when solving a very simple linear programming problem

I am solving a simple LP problem using Gurobi with dual simplex and presolve. I get the model is unbounded but I couldn't see why such a model is unbounded. Can anyone help to tell me where goes wrong?
I attached the log and also the content in the .mps file.
Thanks very much in advance.
Kind regards,
Hongyu.
The output log and .mps file:
Link to the .mps file: https://studntnu-my.sharepoint.com/:u:/g/personal/hongyuzh_ntnu_no/EV5CBhH2VshForCL-EtPvBUBiFT8uZZkv-DrPtjSFi8PGA?e=VHktwf
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (mac64[arm])
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 1 rows, 579 columns and 575 nonzeros
Coefficient statistics:
Matrix range [3e-02, 5e+01]
Objective range [7e-01, 5e+01]
Bounds range [0e+00, 0e+00]
RHS range [7e+03, 7e+03]
Iteration Objective Primal Inf. Dual Inf. Time
0 handle free variables 0s
Solved in 0 iterations and 0.00 seconds (0.00 work units)
Unbounded model
The easiest way to debug this is to put a bound on the objective, so the model is no longer unbounded. Then inspect the solution. This is a super easy trick that somehow few people know about.
When we do this with a bound of 100000, we see:
phi = 100000.0000
gamma[11] = -1887.4290
(the rest zero). Indeed we can make gamma[11] as negative as we want to obey R0. Note that gamma[11] is not in the objective.
More advice: It is also useful to write out the LP file of the model and study that carefully. You probably would have caught the error and that would have prevented this post.

How do I obtain Monte Carlo error in R2OpenBugs?

Has anyone managed to obtain a Monte Carlo error for a parameter when running bayesian model un R2OpenBugs?
It is provided in a standard output of OpenBugs, but when run under R2OpenBugs, the log file doesn't have MC error.Is there a way to ask R2OpenBugs to calculate MC error? Or maybe there is a way to calculate it manually? Please, let me know if you heard of any way to do that. Thank you!
Here is the standard log output of R2OpenBugs:
$stats
mean sd val2.5pc median val97.5pc sample
beta0 1.04700 0.13250 0.8130 1.03800 1.30500 1500
beta1 -0.31440 0.18850 -0.6776 -0.31890 0.03473 1500
beta2 -0.05437 0.05369 -0.1648 -0.05408 0.04838 1500
deviance 588.70000 7.87600 575.3000 587.50000 606.90000 1500
$DIC
Dbar Dhat DIC pD
t 588.7 570.9 606.5 17.78
total 588.7 570.9 606.5 17.78
A simple way to calculate Monte Carlo standard error (MCSE) is to divide the standard deviation of the chain by the square root of the effective number of samples. The standard deviation is provided in your output, but the effective sample size should be given as n.eff (the rightmost column) when you print the model output - or at least that is the impression I get from:
https://cran.r-project.org/web/packages/R2OpenBUGS/vignettes/R2OpenBUGS.pdf
I don't use OpenBugs any more so can't easily check for you, but there should be something there that indicates the effective sample size (this is NOT the same as the number of iterations you have sampled, as it also takes into account the loss of information due to correlation within the chains).
Otherwise you can obtain it yourself by extracting the raw MCMC chains and then either computing the effective sample size using the coda package (?coda::effectiveSize) or just use LaplacesDemon::MCSE to calculate the Monte Carlo standard error directly. For more information see:
https://rdrr.io/cran/LaplacesDemon/man/MCSE.html
Note that some people (including me!) would suggest focusing on the effective sample size directly rather than looking at the MCSE, as the old "rule of thumb" that MCSE should be less than 5% of the sample standard deviation is equivalent to saying that the effective sample size should be at least 400 (1/0.05^2). But opinions do vary :)
The MCMC-error is named Time-series SE, and can be found in the statistics section of the summary of the coda object:
library(R2OpenBUGS)
library(coda)
my_result <- bugs(...., codaPg = TRUE)
my_coda <- read.bugs(my_result)
summary(my_coda$statistics)

GAMS: Using variables in logical conditions

I got a question about GAMS. I'm kind of a beginner with GAMS.
I'm using minlp with scip solver.
I'm trying to model a system for a thermal energy storage of a concentrated solar power plant.
I'm right now stuck on modeling the equations for the tank operation strategy, so whether it's on discharging or charging mode. I'm modelling a thermocline tank, where while charging the hot htf enters from the top of the tank and pushes out cold htf from the bottom. For the discharging process it's the other way around.
The operational strategies dependent on the mass flows from the receiver or the power block, which are decision variables. For the different operational strategies the inlet and outlet temperature of the thermal energy storage changes. So there are some equations which logically depent on the values of decision variables.
The thing is, that if I try to use logical conditions (either with the if operator or the $ operator) with variables in it for the definition of equations, I get the errors 52 or 53 "Endogenous $-control operations not allowed". This seems to be an error you get with the solve statements, because it is not possible to put in logical conditions with decision variables. After doing some research on the internet I found these threats, where it is explained quite nicely:
https://forum.gamsworld.org/viewtopic.php?f=13&t=6795
Use variable in GAMS dollar
So ouf of this problem I got some questions:
Does anyone know a possible way, where I can model equations, which logically depend on decision variables? Or is this not possible with GAMS, so that I would need to switch to another language to solve this problem?
These would be the important equations:
e_charge(i+1)$(m_rc_ts(i+1) > 0) .. dec(i+1) =e= 1;
e_discharge(i+1)$(m_pb_ts(i+1)) .. dec(i+1) =e= 2;
e_no_use(i+1)$(m_rc_ts(i+1) = 0 and m_pb_ts(i+1) = 0) .. dec(i+1) =e= dec(i);
e_m_rc_ts_restrict(i+1)$(dec(i+1) = 2) .. m_rc_ts(i+1) =e= 0;
e_m_pb_ts_restrict(i+1)$(dec(i+1) = 1) .. m_pb_ts(i+1) =e= 0;
e_T_ti_charge(nfirst,i+1)$(dec(i+1)= 1) .. T_fl(nfirst,i+1) =e= T_ro;
e_T_ti_discharge(nfirst,i+1)$(dec(i+1)= 2) .. T_fl(nfirst,i+1) =e= T_po(i+1);
Thanks for your help!
Cheers
You cannot use the variable per se, but you are able to use its attributes:
so you cannot write
$(dec(i+1))
but
$(dec.l(i+1))
works (it is the level of the variable).

Get variable results from failed run in neos using bonmin for a MINLP

I'm using the neos-server to solve a highly constrained MINLP, using the bonmin algorithm. Solving using either a Branch and Bound or the hybrid method. The input code is AMPL
I want to know if it's possible to output variable results for a failed run?
I've tried just about every bonmin option listed here
https://projects.coin-or.org/Bonmin/browser/stable/1.7/Bonmin/doc/BONMIN_UsersManual.pdf?format=raw
I don't know enough about optimization solvers to really understand all of these options.
I've tried different AMPL options but these only work if I have a successful run.
Ultimately, I want to output all the variables in my model with the values from the latest failed run.
This is my commands file
options bonmin_options "bonmin.bb_log_level 4 \
bonmin.algorithm B-BB print_level 6";
solve;
option display_precision 10;
display solve_result_num, solve_result;
display cost.result;
display _varname, _var;
Below is a the header output from a failed run. This provides outputs for all my variables but they are all 0
Solver : minco:Bonmin:AMPL
Start : 2017-08-30 11:20:12
End : 2017-08-30 11:26:34
Host : NEOS HTCondor Pool
Disclaimer:
This information is provided without any express or
implied warranty. In particular, there is no warranty
of any kind concerning the fitness of this
information for any particular purpose.
*************************************************************
File exists
You are using the solver bonmin-ampl.
Executing AMPL.
processing data.
processing commands.
Executing on prod-exec-1.neos-server.org
Presolve eliminates 20629 constraints and 18794 variables.
Substitution eliminates 8664 variables.
Adjusted problem:
12175 variables:
7093 nonlinear variables
5082 linear variables
10647 constraints; 63680 nonzeros
2553 nonlinear constraints
8094 linear constraints
8084 equality constraints
2563 inequality constraints
1 linear objective; 17 nonzeros.
Setting $presolve_fixeps >= 1.41e-14 could change presolve results.
Bonmin 1.8.4 using Cbc 2.9.6 and Ipopt 3.12.4
bonmin: bonmin.bb_log_level 4
bonmin.algorithm B-BB
print_level 6
Start reading options from stream.
Finished reading options from file.
Cbc3007W No integer variables - nothing to do
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************
NLP0012I
Num Status Obj It time Location
NLP0014I 1 INFEAS 2.2729823 1144 178.86781
NLP0014I 2 INFEAS 2.2729823 1144 176.90811
Cbc3007W No integer variables - nothing to do
Cbc0006I The LP relaxation is infeasible or too expensive
"Finished"
bonmin: Infeasible problem
solve_result_num = 220
solve_result = infeasible
cost.result = infeasible

How to determine which constraints or variable bounds are rendering a GAMS model infeasible?

The solve summary in my GAMS model (NLP) is returning the following:
**** SOLVER STATUS 1 Normal Completion
**** MODEL STATUS 19 Infeasible - No Solution
**** OBJECTIVE VALUE NA
THE bounds on one of my variables are:
y.lo = 0, y.up = 0.15
if I change the bounds to:
y.lo = 0, y.up = 0.12
the model then converges and gives the following:
**** SOLVER STATUS 1 Normal Completion
**** MODEL STATUS 2 Locally Optimal
**** OBJECTIVE VALUE 66013164.0000
It turns out that the final variable level is
y.l = 0.12
how can it be that GAMS determined the model to be infeasible in the first case (upper bound = 0.15) even though the solution (0.12) was within the search space? (btw, I am using ANTIGONE solver)
Additionally, are there any methodical ways to identify which constraints/variable bounds are causing the model to be infeasible?
In order to find this (seemingly illogical) error, I had to spend hours guessing and checking arbitrary details within the model with no rhyme or reason. There has to be a better way, right?
That issue is not GAMS fault, but the solver you're using. Have you tried with CONOPT?
You can see the infeasible constraint in the lst file. Some equations should have (***INFES) mark
Also, to solve your problem, I would try to provide the NLP solver an initial solution that is somehow close enough to the optimal one, or at least feasible.
I would also try to check the options of the solvers you are using to start the solution procedure with a feasible starting point.
Non-convex optimization is not easy.
I hope this helps.