Dear AMPL group I take an example from AMPL site. This example is as follows clear all;clc;close all ampl=AMPL('C:\amplide.mswin64'); ampl.eval('param 2d{1..3, 1..2};'); values = eye(3,2); d = ampl.getParameter('2d'); d.setValues(values); d.getValues ampl.close and the following error is displayed Error using Parameter/setValues (line 61) No method 'setValues' with matching signature found for class 'com.ampl.Parameter'. Error in Entity/subsref (line 84) builtin('subsref',self,key); Error in test2 (line 7) d.setValues(values); I use AMPL and AMPL-API on matlab 2018b and my OS is WIN10. Moreover, some examples provided in the following address are run without error but some other examples stop with error. Thank you in advance M. Shamsi You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
Dear Shamsi,
{#HS:807873636-39006#}
Thanks for reporting this issue. The method setValues expects a DataFrame, and therefore instead of "d.setValues(values);", you should use a DataFrame as follows: ampl = AMPL; ampl.eval('param 2d{1..3, 1..2};'); df = DataFrame(2,'i', 'j', '2d'); I = {1, 2, 3}; J = {1, 2}; values = eye(3,2); df.setMatrix(values, I, J); df ampl.setData(df); ampl.eval('display 2d;'); However, we have now noticed that there is an odd issue with two dimensional DataFrames generated from matrices that results in an automatic convertion of numbers into strings which causes the code shown above to fail (since the indices are expected to be numbers), while the following (with 3 indices) works: ampl = AMPL; ampl.eval('param 3d{1..3, 1..2, 3..6};'); df = DataFrame(3, 'i', 'j', 'k', '3d'); I = {1, 2, 3}; J = {1, 2}; K = {3, 5, 6}; values = randn(3, 2, 3); df.setMatrix(values, I, J, K); df ampl.setData(df); ampl.eval('display 3d;'); This is related to some of the examples that are failing. Alternatively you can initialize the DataFrame as follows: ampl = AMPL; ampl.eval('param 2d{1..3, 1..2};'); df = DataFrame(2, 'i', 'j', '2d'); df.addRow(1, 1, 1) df.addRow(1, 2, 0) df.addRow(2, 1, 0) df.addRow(2, 2, 1) df.addRow(3, 1, 0) df.addRow(3, 2, 0) df ampl.setData(df); ampl.eval('display 2d;'); or from a matrix as follows: ampl = AMPL; ampl.eval('param 2d{1..3, 1..2};'); df = DataFrame(2, 'i', 'j', '2d'); values = eye(3,2); for i = 1:3 for j =1:2 df.addRow(i, j, values(i,j)) end end df ampl.setData(df); ampl.eval('display 2d;'); The MATLAB API has not been updated in a while and it is currently quite behind some of other APIs we provide such as Python and R that are considerably more intuitive and robust. A substancial refactoring of this API is planned to happen during this year, until then the workaround shown above may be necessary in some cases. Best regards, Filipe -- Filipe Brandão [hidden email]
On Thu, Mar 21, 2019 at 9:12 PM UTC, Ampl Modeling Language <[hidden email]> wrote:
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
Dear Filipe Thank you so much for your complete and useful reply. I have another question, please. Let a variable (with indices) is defined in a mod file. How we can construct a DataFrame correspond to this variable? For example, let wh have a mod file named "amplmod.mod" and the following commands are in this file ... ... param n; var S{1..n}; var T{1..n,0..n+1,1..4} ... ... Now, how we can construct DataFrames correspond to the variables 'S' and 'T'? My final aim is to write a Matlab code that initializes the variables. Regards Mostafa On Fri, Mar 22, 2019 at 2:18 PM AMPL Google Group <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
You can define the DataFrames for variables as follows:
{#HS:807873636-39006#}
ampl = AMPL; ampl.eval('param n;'); ampl.eval('var S{1..n};'); ampl.eval('var T{1..n,0..n+1,1..4};'); % set n=5 ampl.getParameter('n').set(5); ampl.eval('display n;') % DataFrame for variable S df = DataFrame(1, 'i', 'S'); df.addRow(1, 4); df.addRow(2, 3); df.addRow(3, 2); df.addRow(5, 1); df.addRow(4, 1); % Set values for variable S ampl.setData(df) ampl.eval('display S;'); % DataFrame for variable T df = DataFrame(3, 'i', 'j', 'k', 'T'); for i = 1:5 for j = 0:6 for k = 1:4 df.addRow(i, j, k, i+j+k) end end end % Set values for variable T ampl.setData(df) ampl.eval('display T;'); Best regards, Filipe -- Filipe Brandão [hidden email]
On Fri, Mar 22, 2019 at 11:09 PM UTC, Ampl Modeling Language <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |