Amtul Samie Maqbool
Amtul Samie Maqbool

Reputation: 3

comparing variables from different turtles in netlogo

I am starting with a simple model of two agents (industries) and I want to print the smaller of the two variables (belonging to each of the agents). I am not really sure how to compare two variables from different agents and print the value. The relevant part of the code is pasted below:

to setup-turtles  
 create-I1 1 [  
  setxy 0 7  
  set shape "factory"  
  create-active-links-to I2  
  set color 125  
   set product product-I1  
  set raw-material 0.35 * product-I1  
  set waste (0.003 * product-I1)  
  ]  

  create-I2 1 [  
  set shape "factory"  
  create-active-links-to I1  
  set color 55  
  set product product-I2  
  set raw-material 0.102 * product-I2  
  set waste 0.032 * product-I2  
  ]  

end  

*the problem is here  
to-report E1-2 min [waste of I2 or raw-material of I1]  
  report E1-2  
end  

Upvotes: 0

Views: 111

Answers (1)

JenB
JenB

Reputation: 17678

are you trying to compare the value of I2's waste to the value of I1's raw-material? It looks like I1 and I2 are both turtle breeds and there is only one turtle of each breed. If this is correct, then the following code will work.

to-report E1-2
  report min (list [waste] of one-of I2 [raw-material] of one-of I1)
end

Note that I have added one-of into your attempt. NetLogo doesn't know that you will only ever have one T1 and one T2 so you have to tell NetLogo to select one turtle from all the T1s and one from all the T2s to compare. The list is not necessary in this case because you only have two values to compare, but I included it in case you want to take the minimum over more values.

Upvotes: 1

Related Questions