Solved

Writing a constraint in AIMMS

  • 12 July 2019
  • 2 replies
  • 188 views

Userlevel 1
Dear Staff,
I need help writing the following constraint using the AIMMS language.
I have two indexes:
c
a

Where "a" indicates years.
I have a variable y(c,a)

I would like to define a summation over "c" and over "a" as less than or equal to a value. But the summation over "a" should be done only from the first year until the current year.

I am trying this formulation but something is wrong with it:

sum((c, a1|(a1="A01") and (a1=ord(a))), y(c,a1)) <= Value

Can you please help me writing this correctly using the AIMMS syntax?

Thank you,
icon

Best answer by mateusarakawa 12 July 2019, 14:35

Hi, @Chibo .



If your year set is for instance { 2016, 2017, 2018, 2019 } and for each year you want to create the summation, I would write:



Constraint_SumYears

Index Domain: (a)

Definition:

code:
sum((c,a_aux) | (ord(a_aux) <= ord(a)), y(c,a_aux)) <= value




With this approach you will create 4 constraints, 1 for each year.

2016 : sum(c, y(c,2016)) <= value

2017: sum(c, y(c,2016)) + sum(c, y(c,2017)) <= value

2018: sum(c, y(c,2016)) + sum(c, y(c,2017)) + sum(c, y(c,2018)) <= value

2019: sum(c, y(c,2016)) + sum(c, y(c,2017)) + sum(c, y(c,2018)) + sum(c, y(c,2019)) <= value



But if you want to create the constraint only for 2019



Constraint_SumYears

IndexDomain:

Definition:

code:
sum((c,a) | (ord(a) <= ord(ElementParameter_CurrentYear)), y(c,a)) 
<= value




So, if your ElementParameter_CurrentYear is '2019' you will create: sum(c, y(c,2016)) + sum(c, y(c,2017)) + sum(c, y(c,2018)) + sum(c, y(c,2019)) <= value



Remark: Check if your year set is ordered, in case it's not a calendar.

Tips:


  • In the second approach you can create a parameterOrdCurrentYear := ord(ElementParameter_CurrentYear) and use it instead.
  • In your code, you should refer to element A01 with single quotation mark 'A01'

Hope it helps!
View original

2 replies

Userlevel 5
Hi, @Chibo .

If your year set is for instance { 2016, 2017, 2018, 2019 } and for each year you want to create the summation, I would write:

Constraint_SumYears
Index Domain: (a)
Definition:
code:
sum((c,a_aux) | (ord(a_aux) <= ord(a)), y(c,a_aux)) <= value


With this approach you will create 4 constraints, 1 for each year.
2016 : sum(c, y(c,2016)) <= value
2017: sum(c, y(c,2016)) + sum(c, y(c,2017)) <= value
2018: sum(c, y(c,2016)) + sum(c, y(c,2017)) + sum(c, y(c,2018)) <= value
2019: sum(c, y(c,2016)) + sum(c, y(c,2017)) + sum(c, y(c,2018)) + sum(c, y(c,2019)) <= value

But if you want to create the constraint only for 2019

Constraint_SumYears
IndexDomain:
Definition:
code:
sum((c,a) | (ord(a) <= ord(ElementParameter_CurrentYear)), y(c,a)) 
<= value


So, if your ElementParameter_CurrentYear is '2019' you will create: sum(c, y(c,2016)) + sum(c, y(c,2017)) + sum(c, y(c,2018)) + sum(c, y(c,2019)) <= value

Remark: Check if your year set is ordered, in case it's not a calendar.
Tips:
  • In the second approach you can create a parameterOrdCurrentYear := ord(ElementParameter_CurrentYear) and use it instead.
  • In your code, you should refer to element A01 with single quotation mark 'A01'
Hope it helps!
Userlevel 1
Thank you so much! You are right, it is very straightforward with your formulation. I am trying the first one and it seems it is working fine.
Thank you very very much for your help! Very kind of you

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator