Skip to main content

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?

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.


Reply


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

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