Indexing Data 2D-Matrix in Parameter

955 views
Skip to first unread message

khan

unread,
Oct 21, 2014, 10:17:28 AM10/21/14
to am...@googlegroups.com
Hello Every one,

I am new here in AMPL. I want to know how can I index 2-D data matrix in a parameter. Like in my case I have 32X65 Matrix. And I want to read and Index this matrix in the objective function so that can be utlized. 

Also how can I represent this 32X65 matrix in .dat file?

Your suggestion are already appreciated alot.

Thanking you in anticipation.

khan

unread,
Oct 22, 2014, 4:30:34 AM10/22/14
to am...@googlegroups.com
anyone?

victor.z...@gmail.com

unread,
Oct 22, 2014, 9:53:21 AM10/22/14
to am...@googlegroups.com
Creating a parameter representing a two-dimensional matrix is pretty straightforward:

  param M;
  param N;
  param A{1..M, 1..N};

  data;
  param M := 32;
  param N := 65;
  param A
  :  1  2  3 ... 65 :=
  1 <row1-elements>
  2 <row2-elements>
  ...
  32 <row32-elements>;

HTH,
Victor

-- 
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 ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.

For more options, visit https://groups.google.com/d/optout.

Robert Fourer

unread,
Oct 22, 2014, 10:21:02 AM10/22/14
to am...@googlegroups.com
The best way to learn about this topic is to read the relevant sections in the AMPL book (http://ampl.com/resources/the-ampl-book/chapter-downloads/). There's an example of a 2-dimensional parameter and its data in Chapter 2 -- see particularly the parameter "amt" in Figure 2-1 and the data for it in Figure 2-2 -- and there are several more examples in Chapters 3 and 4.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages