Victor,
I’ll be glad to work with you on this. APMonitor converts inequality constraints into equality constraints with slack variables. Lagrange multipliers for constraints are available is you set diaglevel to 2 and retrieve the file ‘apm_lam.txt’. Below is some code that should work to retrieve the Lagrange multipliers:
apm_option(s,a,’nlc.diaglevel’,2);
apm(s,a,’solve’);
apm_get(s,a,’apm_lam.txt’)
You’ll have the apm_lam.txt file in your working directory that will contain all of your Lagrange multipliers.
Let me know if you have any additional questions.
Best regards,
John Hedengren
Dear Saurabh,
You can access Lagrange multipliers if the solver reports them. If you set the diagnostic level to 2 and look in your run directory, there is a file called apm_lam.txt that contains the Lagrange multipliers.
m.options.IMODE = 3 #steady state optimization
m.options.SOLVER = 1 # APOPT solver
m.options.DIAGLEVEL = 2 # diagnostic level
#solve simulation
m.solve()
# retrieve lagrange multipliers from apm_lam.txt
print(m.path) # apm_lam.txt is in local directory
However, some solvers do not report the Lagrange multipliers so I recommend using the APOPT solver because it does report the Lagrange multipliers and solves MINLPs. You’ll need to parse the apm_lam.txt file in Python, unfortunately.
Best regards,
John Hedengren
- To unsubscribe, send email to apmonitor+unsubscribe@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmonitor+unsubscribe@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor
---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+unsubscribe@googlegroups.com.
Dear Mr. Beal
Thanks for the inputs. Now, I am able to access the file apm_lam.txt by following your instructions. The issue is that it always shows 0 values for the Lagrangian multipliers. I am using this NLP:
Original problem:
minimize sum_ i in C: x_i^-0.3565 * p_i^0.8340 + x_i
subject to:
x_i <= ub_i
x_i >= lb_i
p_i == eb_i
x_i, p_i >= 0
I have attached the python code to solve this NLP for your reference and also the Lagrangian multipliers file for the NLP, which shows all LMs to be 0. This should not be happening as some constraints do have non-zero dual values. To estimate true values of LMs, I have rerun the NLP after incrementing the RHS of different constraints, which shows changes in the value of the objective, which implies for some constraints the dual variables should be non-zero. Please suggest how can I get correct LM values of the NLP constraints.
Best regards
Saurabh Chandra
The following are the run prints in the Python shell.
('Error:', 'At line 7248 of file files.f90\nTraceback: not available, compile with -ftrace=frame or -ftrace=full\nFortran runtime error: Deallocated a bad pointer\n')
c:\users\scp\appdata\local\temp\tmp7omlb3gk_model0
X[ 1 ] = 2500.0
P[ 1 ] = 100000.0
X[ 2 ] = 2500.0
P[ 2 ] = 100000.0
SPobj= 6240.07729719
>>> ### incrementing x-ub constraint by 1
>>> ### i.e. m.Equation(x[i-1] - ub[i-1] <= 1)
>>> ================================ RESTART ================================
>>>
('Error:', 'At line 7248 of file files.f90\nTraceback: not available, compile with -ftrace=frame or -ftrace=full\nFortran runtime error: Deallocated a bad pointer\n')
c:\users\scp\appdata\local\temp\tmpiauy8lgk_model0
X[ 1 ] = 2500.0
P[ 1 ] = 100000.0
X[ 2 ] = 2500.0
P[ 2 ] = 100000.0
SPobj= 6240.07729719
>>> ### incrementing x-lb constraint rhs by 1
>>> ### i.e. m.Equation(-x[i-1] + lb[i-1] <= 1)
>>> ================================ RESTART ================================
>>>
('Error:', 'At line 7248 of file files.f90\nTraceback: not available, compile with -ftrace=frame or -ftrace=full\nFortran runtime error: Deallocated a bad pointer\n')
c:\users\scp\appdata\local\temp\tmpnck0jjgk_model0
X[ 1 ] = 2499.0
P[ 1 ] = 100000.0
X[ 2 ] = 2499.0
P[ 2 ] = 100000.0
SPobj= 6238.25423228
>>> ### incrementing p-eb constraint rhs by 1
>>> ### i.e. m.Equation(p[i-1] - eb[i-1] == 1)
>>> ================================ RESTART ================================
>>>
('Error:', 'At line 7248 of file files.f90\nTraceback: not available, compile with -ftrace=frame or -ftrace=full\nFortran runtime error: Deallocated a bad pointer\n')
c:\users\scp\appdata\local\temp\tmpofxblegk_model0
X[ 1 ] = 2500.0
P[ 1 ] = 100001.0
X[ 2 ] = 2500.0
P[ 2 ] = 100001.0
SPobj= 6240.08763943
Dear Saurabh,
Attached is a script that displays the LMs. I told you earlier that it is the APOPT solver that returns the LMs but it is only the BPOPT and IPOPT solvers. I apologize for the incorrect information. If you need the LMs with the APOPT solver, I could add that to the list of development items.
# print Lagrange multipliers
# available with SOLVER = 2 (BPOPT) and 3 (IPOPT)
lm = np.loadtxt(m.path+'\\apm_lam.txt')
print(lm)
Best regards,
John Hedengren