Skip to main content

Complex value assignment efficiency problem

  • April 11, 2025
  • 2 replies
  • 44 views

Forum|alt.badge.img+4

Hi I am trying to do a value assignment in AIMMS. Here is the example:

t and i are both the index of set timen and r are the index for set Node. NodeInTime, needed_value are predetermined parameters. scenario is parameter changing in the process. noted_scenarios_index is a subset of Node. path is a mapping between index (r,t) and set Node.

for (n,t)| t<>first(time) and n<=NodeInTime(t) do

   scenario := 1;

   noted_scenarios_index := {r | r <= NodeInTime(t) and path(r, t) = n};

   for r in noted_scenarios_index do

        needed_value(scenario, n, t, i) := value(path(r,i), i);

        scenario := scenario + 1;

   endfor;

endfor;

I used debug move to check and surprisingly, the slowest part is:

needed_value(scenario, n, t, i) := value(path(r,i), i);

when it runs to this line, ‘scenario’, ‘n’, ‘t’ are determined and it took more than 30s to run this line….. So I don’t understand why it’s so slow.

I also tried using an additional parameter like:

addition(i) := value(path(r,i), i);

needed_value(scenario, n, t, i) := addition(i);

and  addition(i) := value(path(r,i), i); runs quite fast.

However, needed_value(scenario, n, t, i) := addition(i); still runs very slow.

Can you give me some suggestion on how to improve the assignment speed?

2 replies

Chris Kuip
AIMMSian
Forum|alt.badge.img+7
  • AIMMSian
  • 125 replies
  • April 16, 2025

Hello Chunyang,

 

The AIMMS parallel sparse execution engine is designed to handle large amounts of sparse data quickly.  As a consequence, each time the execution of an assignment statement starts, there is some preparation time.

The tactic to write efficient code is to avoid for loops - 
let each execution of an assignment handle as much data as possible.

For the example at hand, Inside the for loops the input identifiers nodeInTime, p_value, and path do not change, and the parameter scenario and set noted_scenario_index are merely used as temporaries.

Instead of re-using these temporaries many times, the following code expands their use
over the domain (n,t) of valid tuples; consequently avoiding repeated assignment preparation times.

 

Adapted code


I didn't have data, so I cannot predict the time / memory effect of this code change for your application.  Can you let us know?

With kind regards,

Chris.

PS Please find the project I used enclosed. 
PPS Please use AIMMS 25.3 for testing, as it has an important improvement on Indexed Sets that is used in pr_adapt.


Forum|alt.badge.img+4
  • Author
  • Enthusiast
  • 19 replies
  • April 20, 2025

Hello Chunyang,

 

The AIMMS parallel sparse execution engine is designed to handle large amounts of sparse data quickly.  As a consequence, each time the execution of an assignment statement starts, there is some preparation time.

The tactic to write efficient code is to avoid for loops - 
let each execution of an assignment handle as much data as possible.

For the example at hand, Inside the for loops the input identifiers nodeInTime, p_value, and path do not change, and the parameter scenario and set noted_scenario_index are merely used as temporaries.

Instead of re-using these temporaries many times, the following code expands their use
over the domain (n,t) of valid tuples; consequently avoiding repeated assignment preparation times.

 

Adapted code


I didn't have data, so I cannot predict the time / memory effect of this code change for your application.  Can you let us know?

With kind regards,

Chris.

PS Please find the project I used enclosed. 
PPS Please use AIMMS 25.3 for testing, as it has an important improvement on Indexed Sets that is used in pr_adapt.

 

Hi Chris!

Thank you so much for this great reply! I updatted my AIMMS to 25.3 and tried it on my project. Using my previous method, running needed_value(scenario, n, t, i) := value(path(r,i), i); alone would take 49.2 seconds.

Now, with the method you suggested, p_needed_value(i_scen, n, t, i) | ( i_scen in _is_scenarios(n,t) ) := p_value( ep_path( _ep_nodeOfScenario( n, t, i_scen ), i), i); running this line to exert all the indices at the same time would only took 62.17 seconds!!!

It greatly improved the efficiency. With my previous method, I will need 23*1000*49.2 seconds to do what I need. Now I only need 62.17 seconds which is amazing!

Best,

Chunyang

 



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

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