How to redefine a set between runs in AMPL - optimization

I have a model in AMPL. This model must run three times and in each iteration the result must redefine the size of a previously defined set.
Example:
set item := 1..12;
...
var out{other_set} >=0 integer;
The model would run and get me the solution in out. Then I want to redefine the item set as:
set item := 1..out.
Is this possible?
In page 462 of the manual I found this:
Recursive definitions of indexed sets are allowed, so long as the assigned
values can be computed in a sequence that only references previously computed values.
Am I right in thinking this is what I want?
Thanks

You can assign a new value to a set. To do so first make sure that it doesn't have a := in the declaration. You can replace it with the default clause:
set item default 1..12;
Then use the let statement to assign the new value:
let item := 1..out;
Note that in your example out is indexed over a set so you'll need to provide a subscript out[...].

Related

How to use variable while creating HotString in my script (AutoHotKey)

I'm trying to create a hotstring which needs to take a variable value as it's key
Example:
b := "btw"
::%b%::
Send, By the way
return
When i type btw and space, it must replace the text with "By the way"
Per the documentation: "[v1.1.28+]: Hotstrings can be created dynamically by means of the Hotstring function, which can also modify, disable, or enable the script's existing hotstrings individually."
Untested example:
b := "::btw"
Hotstring(b,"by the way")

Jmeter -- how to combine variable name & counter()

I've got the following problem:
I do gather that ProductId variable is assigned with the first value and then only that value is used when I refer to ${productId}.
I was trying to apply ${__counter()} to reference name in RegexExtractor,
but then BeanShellAssertion fails to set the property.
How should I properly work this around?
You can use __V() function in order to combine 2 variables.
I.e. if you have 2 variables like:
productId
counter
And would like to evaluate i.e. ${productId_1}, ${productId_2}, etc.
It should be as simple as:
${__V(productId${counter})}
Same approach applies to __counter() function:
${__V(productId_${__counter(,)})}
Demo:
See How to Use JMeter Functions posts series for comprehensive information on above and other functions
ProdGroup
please store the product Id property as prod_id_1, prod_id_2,...prod_id_n or according to you convenience
How to to that ?
in post processor "Parameters" section use ${__counter(FALSE,)} and in the script part try getting that String counter = arg[0] and convert that to integer and store it to a script variable by default arg[0] value is String
int c= arg[0] as Integer //this is groovystyle check in your way to convert as int
now props.put("prod_id_"+c,"extractedfrom_response")
BID:
In you Bid group add a user defined variable section add the variable
"prod_id" and value is empty
Define a counter start with the same counter 1 and give counter reference name [if your counter value in prod group was 0 then here also it must start with zero]
script sampler convert all the props to the variables
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String propertyName = e.nextElement().toString();
if (propertyName.startsWith("prod_id_")) {
vars.put(propertyName, props.getProperty(propertyName));
}
}
With this you have converted properties to variables named prod_id_1 ...to ... prod_id_n
In http sampler user reference as ${__V(prod_id_${counterreference in step 2})} will do your job
For each thread the counter will increment by default
user ${__threadNum} or ${counter reference name} in sampler labels for debugging.
Hope this helps. Please let us know if still problem is there.

Ampl syntax: return value at a specific position in set. AKA: use a set as an INDEX on another set

My question is this:
How can I use SUBSET (a discontinuous set) to refer to an index location in another set as opposed to an actual value? I see that ord() can be used to return the position of a value in a set, but I want the reverse of this...
my reason for needing this:
I have a model in which some of the set and data statements are roughly:
set ALL_TIME := {0..20000};
param DATA {ALL_TIME}; #read from file in later data statement;
set myTIME := {0...1000};
I am looping over the myTIME set and each time solving the model and then incrementing the start and end by 1: {1..1001}, {2..1002}, {3..1003}, etc.
I have another discontinuous set being read in from a file that looks something like this (yes below is bad syntax, the "...." is just there to mean that the pattern continues until it hits 1000 so I don't have to type it all) :
set SUBSET := {6,7,8,9,10, 16,17,18,19,20, 26,27.....}
Once myTIME increments such that it no longer contains "6", I get a subscript undefined error from a constraint which I understand to be because myTIME in this case is {7..1007} and thus in the following, tSUB=6 causes ALPHA[6] and is undefined:
subject to CONSTRAINT {tSUB in SUBSET}:
ALPHA [tSUB] = ALPHA[last(tSUB)];
What I want is to be able to use SUBSET to always refer to the same index location of ALPHA, DATA, etc.
So:
SUBSET[0] (which equals 6) should always be the 6th value of for example DATA:
{tSUB in SUBSET}: DATA[tSUB]. when tSUB is 0, I want the 6th value of DATA.
(I am new to Ampl and have a hard time wrapping my head around how indexing and sets work - if anything didn't make sense, please ask and I'll try to clarify. If you think it would be more helpful to see my actual code I'll try to sanitize the company data out and post it). Also, some of the code bits above have abysmal syntax. They are not copied from my code, just approximated to try to explain my problem. :)
You can get i-th member of set S with member(i, S), where i is a 1-based index and S is an ordered set. This is described in section 5.6 Ordered sets of the AMPL book.

Use single value of parameter List in queryString

I am using JasperStudio 5.6.0.final and the report is not generated dynamically from java code.
I have a problem with getting single value from parameter.
In the report I have a parameter A of a type List.
It is not a problem to use it in a clause as IN statement:
AND $X{IN, USER.ID_USER, A}
But I have a problem to get a single value from that list.
I know that my List has always 10 values.
So I want to use it in query, but I don't know how to write the statement:
AND USER.ID_USER = *first_value_of_list_A*
e.g.
AND USER.ID_USER = $P!{Atrybuty}.get(1)
doesn't work
I tried also to assign parameter value to a variable, but as I know it isn't possible to use variables in queryString.
So my question: How to get single value from parameter List in queryString.
What you need to do for this is use
AND $X{IN, USER.ID_USER, A}
Set A type as Collection and that will allow you to even have a single selection or multi selection or just a single value.
Hope that this helps.

How to use LOOP AT itab INTO <fieldsymbol>

As I rarely loop into a field symbol, I often forget to use ASSIGNING instead of INTO which will promptly cause an abend. Is there a valid use of INTO with <fieldsymbol> or is this something that the syntax checker really ought to catch?
LOOP...INTO is perfectly valid but it will work differently. LOOP...INTO transports the values to the structure provided but ASSIGNING assigns the field symbol to the actual table rows.
The only difference is if you are going to change the table contents. See the following:
* Changes all entries in the CARRID column of lt_flights to 50.
LOOP AT lt_flights ASSIGNING <flight>.
<flight>-carrid = 50.
ENDLOOP.
* Does not change the entries in lt_flights (MODIFY...FROM would be required).
ASSIGN <flight> TO ls_flight.
LOOP AT lt_flights INTO <flight>.
<flight>-carrid = 50.
ENDLOOP.
LOOP...INTO with a field symbol would be useless unless you had some kind of dynamic programming requirement.
It is valid when <fieldsymbol> was previously assigned to a structure which has the type of the lines of the table you loop over.
It is a perfectly valid statement:
APPEND INITIAL LINE TO lt_foo ASSIGNING <ls_foo>.
READ TABLE lt_bar INTO <ls_foo> INDEX 1.
A field symbol just takes the place of a variable - at almost any point - so the syntax check can't flag this as invalid. It might issue a warning, though...