Position of a maximum value

1,140 views
Skip to first unread message

fabs

unread,
May 28, 2014, 10:34:16 AM5/28/14
to ai...@googlegroups.com
Hello everybody,

I have the following task to solve and I do not know how:
In my model I have a variable v(i,t) and I want to calculate the position t of the maximum value v in each row i, not the value v itself (what e.g. max(t,v(i,t)) would do). In other words: I want to know the value of t, where this maximum occurs.

Thanks for any help!

Franco Peschiera

unread,
May 28, 2014, 10:38:59 AM5/28/14
to ai...@googlegroups.com
I think you are looking for the "ArgMax" operator.


Franco Peschiera
Jefe de proyectos
baobab soluciones


--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

fabs

unread,
May 28, 2014, 11:52:09 AM5/28/14
to ai...@googlegroups.com
Thanks for the hint! That's exactly what I need! :-)
But I encountered another problem: I want to calculate with the result of the ArgMax and want to do something like the following:

( Val(t) - Val(ArgMax(t,v(i,t)) ) * ConstTerm

It does only work as a definition for a parameter. If I switch the object type to a variable (I need that as the value of argmax depends on the objective function and is changing during solving the model), AIMMS says the error message: "Within a constraint, the arguments of the operator "argmax" cannot involve variables". I do not understand why it says "constraint" as I want to define a variable!? Does anybody know what to do? Thanks in advance :-)

Chris Kuip

unread,
Jun 2, 2014, 7:48:24 AM6/2/14
to ai...@googlegroups.com
Hi,

Re: working with a maximum that involves variables.
- in a CP model, instead of using val(argmax(...)) you may want to use max(...).
- in a MIP model, you can create a set of linear constraints: for all (i,t): maxvar(i) >= v(i,t), and
  then add a term to the objective to minimize the maxvar(i) variables.

Re: confusion error message: filling in the definition attribute of a variable in AIMMS is actually a shorthand for creating a defining constraint for that variable.  
This defining constraint has the name of the variable with "_definition" appended to it.  In addition, it has the same index domain and unit attributes as the variable.

Hope this helps,

Chris Kuip
AIMMS Client Support


Op woensdag 28 mei 2014 17:52:09 UTC+2 schreef fabs:

fabs

unread,
Jun 2, 2014, 8:36:28 AM6/2/14
to ai...@googlegroups.com
Hi Chris,

thanks for your suggestions and also for the explanation of the constraint/variable confusion!
But I think that is exactly what I can't do because I do not need the maximum, but the position of the maximum in time t. So I do not want to calculate with the maximum of v(i,t) for each i, but with the t for each i, for that v(i,t) has a maximum. So I think I need the argmax function as Franco suggested as argmax(v(i,t)) returns a list with the t's I need. But somwhow it does not work within a variable declaration... Btw I am using a NLP model.

Best regards
Fabian

Chris Kuip

unread,
Jun 2, 2014, 9:42:18 AM6/2/14
to ai...@googlegroups.com
Hi Fabian,

Is the v a parameter v(i,t) or is v(i) a continuous function over t, or something else?
Is the t where this maximum occurs a continuous variable, an element variable, an integer variable, or something else?

Thanks,

Chris.


Op maandag 2 juni 2014 14:36:28 UTC+2 schreef fabs:

fabs

unread,
Jun 2, 2014, 9:59:47 AM6/2/14
to ai...@googlegroups.com
Hi Chris,

the whole thing has to do with forest management. So v(i,t) is a variable for the areas of a special treatment in different forest stands i at different points in time t (The optimisation problem is to allocate the stand areas to certain treatments). So i and t are defined as sets. i are stand numbers like R1, R2,....(imported from Excel with spreadsheet::RetrieveSet(...)) and t are time periods 0, 1, 2, 3, ... and so on. For the definition of the set t I am using the ElementRange function so I think it's an element variable. :-)

Best regards
Fabian

fabs

unread,
Jun 27, 2014, 8:36:11 AM6/27/14
to ai...@googlegroups.com
It's me again. There is actually no solution of the problem I can figure out so far. In the moment I use an iterative approach. Solving the problem, recalculation the parameter wirth the argmax function, solving the problem again,... until there is no difference in the solution. But that's not really a straight forward design. So does anybody know how to use the argmax function in a variable or how to implement a program code that does the same as the argmax function?

Best regards,
Fabian

Franco Peschiera

unread,
Jun 27, 2014, 9:27:50 AM6/27/14
to ai...@googlegroups.com
Hello Fabian,

The specific logic to get the functionality you want really depends on the details of the mathematical formulation you are using:
a) What values can v(i,t) get? Integer values? any value? (0. 1) values?
b) What are the constraints (or variable definitions) that include this particular variable? Could you provide them as text so we have an idea of why you want to use something similar to argmax?

regards,


Franco Peschiera
Jefe de proyectos
baobab soluciones


--

fabs

unread,
Jun 27, 2014, 9:51:21 AM6/27/14
to ai...@googlegroups.com
Hi Franco,

a) v(i,t) is a decision variable in the model, that can get any nonnegative real value.
b) These are the only two contraints: nonnegative and the sum[t,v(i,t)] = m(i). m(i) is a parameter containing a total value of each object i that has to split up over time by the model.
So I want to figure out the time period t, to that the relative maximum of m(i) is assigned to (= maximum of v(i,t)), to calculate some other variables over time t that depend on this t(i) where v(i,t) has its maximum. In other words: I need this t(i) as a starting point for calculating the development of other values over t. Hope that makes things more clear.

In the moment the parameter definition p(i,t) with argmax is as follows (k is a second index for time t):

if ( t - argmax(k,v(i,k)) ) < 0
then 0
else
        t - argmax(k,v(i,k))
endif

With that I get a period counter p(i,t) starting with 1 in the period after the maximum of v(i,t) is reached.

Best regards,
Fabian

Franco Peschiera

unread,
Jun 27, 2014, 12:12:22 PM6/27/14
to ai...@googlegroups.com
Given that you cannot use argmax inside the model, I'd suggest something around the following lines:

1. Create a binary variable named "IsPeriod_t_maximum_in_i(t,i)" that should store the value "1" when the period "t" has the maximum of variable v(t,i) on each "i" and 0 in all other periods "t" for that "i".
You need to relate this variable to your v(t,i) variable with some constraint in an intelligent way so that this binary variable *only* gets the value 1 when that period is the maximum of v(t,i).

2. Your period counter "p" should be a variable and should be related to the binary variable "IsPeriod_t_maximum_in_i" via another clever constraint.

You need to keep the constraints lineal.

If you think you need help on building those constraints, feel free to ask the group for help, I'm sure someone here could come up with them given enough time.

regards,


Franco Peschiera
Jefe de proyectos
baobab soluciones


Reply all
Reply to author
Forward
0 new messages