|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[AMPL 2797] indexing expressionsHi, I have a variable, say a[i,j] where i and j reside in sets A and B. Suppose now that i create an index parameter which I call "point" defined as follows param k_ default 1; for {i in A}{ for {j in B}{ let point[k_]:={(i,j)}; let k_:=k_+1; }} delete k_; Next, I want to evaulate a[] at point. I tried a[point[k]] , however this doesnt seem to work as point[k] is of the form (i,j) but apparently you need to index variables with comma-separated lists. The following ugly trick worked: ( j is fixed ) sum{(k,l) in point[j]} a[k,l] .... this evaulated a[] at the correct point (the sum is over one single element only because j is fixed) Is there a better way to do this? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To post to this group, send email to ampl@... To unsubscribe from this group, send email to ampl+unsubscribe@... For more options, visit this group at http://groups.google.com/group/ampl?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
[AMPL 2798] Re: indexing expressionsThis is probably uglier but, in my opinion, more readable: define TWO indexed parameters, point1 and point2. Then param k_ default 1; for {i in A} { for {j in B} { let point1 [k_] := i; let point2 [k_] := j; let k_ := k_ + 1; } } Now "a [point1 [k], point2 [k]]" is what you look for. Hope this helps. On Sep 7, 3:13 am, pioneer <spencer.m...@...> wrote: > Hi, > > I have a variable, say a[i,j] where i and j reside in sets A and B. > > Suppose now that i create an index parameter which I call "point" > defined as follows > > param k_ default 1; > for {i in A}{ > for {j in B}{ > let point[k_]:={(i,j)}; > let k_:=k_+1;}} > > delete k_; > > Next, I want to evaulate a[] at point. I tried a[point[k]] , however > this doesnt seem to work as point[k] is of the form (i,j) but > apparently you need to index variables with comma-separated lists. The > following ugly trick worked: > > ( j is fixed ) > sum{(k,l) in point[j]} a[k,l] .... this evaulated a[] at the correct > point (the sum is over one single element only because j is fixed) > > Is there a better way to do this? > > Thanks You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To post to this group, send email to ampl@... To unsubscribe from this group, send email to ampl+unsubscribe@... For more options, visit this group at http://groups.google.com/group/ampl?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |