I was trying to create a list with the values of a set of variables that are calculated each go procedure based of other variables. In this case I am trying to create a list of utility values which will cause the decision for the agent which runs the procedure to change their TIME variable. All the caulculations part is correct, the only problem comes when trying to create the list for the utilities and choosing the maximum value from it to continue the procedure. Does anyone know what I can do to avoid this problem? Cheers
to utility-runway
let feepKG7 [feepKG] of runway1
let feepKG8 [feepKG] of runway2
let feepKG9 [feepKG] of runway3
let feepKG10 [feepKG] of runway4
let feepKG11 [feepKG] of runway5
let feepKG12 [feepKG] of runway6
let feepKG13 [feepKG] of runway7
let feepKG14 [feepKG] of runway8
let feepKG15 [feepKG] of runway9
let feepKG16 [feepKG] of runway10
let feepKG17 [feepKG] of runway11
let feepKG18 [feepKG] of runway12
let feepKG19 [feepKG] of runway13
let feepKG20 [feepKG] of runway14
let feepKG21 [feepKG] of runway15
let feepKG22 [feepKG] of runway16
let feepKG23 [feepKG] of runway17
set utility7 ( ( previous-business1 + previous-leisure1 + previous-business2 + previous-leisure2 ) / feepKG7 )
set utility8 ( ( previous-business1 + previous-leisure1 + previous-business2 + previous-leisure2 + previous-business3 + previous-leisure3 ) / feepKG8 )
set utility9 ( ( previous-business2 + previous-leisure2 + previous-business3 + previous-leisure3 + previous-business4 + previous-leisure4 ) / feepKG9 )
set utility10 ( ( previous-business3 + previous-leisure3 + previous-business4 + previous-leisure4 + previous-business5 + previous-leisure5 ) / feepKG10 )
set utility11 ( ( previous-business4 + previous-leisure4 + previous-business5 + previous-leisure5 + previous-business6 + previous-leisure6 ) / feepKG11 )
set utility12 ( ( previous-business5 + previous-leisure5 + previous-business6 + previous-leisure6 + previous-business7 + previous-leisure7 ) / feepKG12 )
set utility13 ( ( previous-business6 + previous-leisure6 + previous-business7 + previous-leisure7 + previous-business8 + previous-leisure8 ) / feepKG13 )
set utility14 ( ( previous-business7 + previous-leisure7 + previous-business8 + previous-leisure8 + previous-business9 + previous-leisure9 ) / feepKG14 )
set utility15 ( ( previous-business8 + previous-leisure8 + previous-business9 + previous-leisure9 + previous-business10 + previous-leisure10 ) / feepKG15 )
set utility16 ( ( previous-business9 + previous-leisure9 + previous-business10 + previous-leisure10 + previous-business11 + previous-leisure11 ) / feepKG16 )
set utility17 ( ( previous-business10 + previous-leisure10 + previous-business11 + previous-leisure11 + previous-business12 + previous-leisure12 ) / feepKG17 )
set utility18 ( ( previous-business11 + previous-leisure11 + previous-business12 + previous-leisure12 + previous-business13 + previous-leisure13 ) / feepKG18 )
set utility19 ( ( previous-business12 + previous-leisure12 + previous-business13 + previous-leisure13 + previous-business14 + previous-leisure14 ) / feepKG19 )
set utility20 ( ( previous-business13 + previous-leisure13 + previous-business14 + previous-leisure14 + previous-business15 + previous-leisure15 ) / feepKG20 )
set utility21 ( ( previous-business14 + previous-leisure14 + previous-business15 + previous-leisure15 + previous-business16 + previous-leisure16 ) / feepKG21 )
set utility22 ( ( previous-business15 + previous-leisure15 + previous-business16 + previous-leisure16 + previous-business17 + previous-leisure17 ) / feepKG22 )
set utility23 ( ( previous-business16 + previous-leisure16 + previous-business17 + previous-leisure17) / feepKG23 )
set utility-list [ utility7 utility8 utility9 utility10 utility11
utility12 utility13 utility14 utility15 utility16
utility17 utility18 utility19 utility20 utility21 utility22 utility23 ]
let max-utility max-one-of utility-list
if max-utility = utility7 [set time 7]
if max-utility = utility8 [set time 8]
if max-utility = utility9 [set time 9]
if max-utility = utility10 [set time 10]
if max-utility = utility11 [set time 11]
if max-utility = utility12 [set time 12]
if max-utility = utility13 [set time 13]
if max-utility = utility14 [set time 14]
if max-utility = utility15 [set time 15]
if max-utility = utility16 [set time 16]
if max-utility = utility17 [set time 17]
if max-utility = utility18 [set time 18]
if max-utility = utility19 [set time 19]
if max-utility = utility20 [set time 20]
if max-utility = utility21 [set time 21]
if max-utility = utility22 [set time 22]
if max-utility = utility23 [set time 23]
end
First, I assume that each runway# is a turtle or link of breed runway. A much better way to structure this code is by applying the same operations to all the values at once. To do this, first we create a list of the feepKG values:
let feepKGs map [ [ feepKG ] of ? ] sort runways
The sort in front of runways makes it so that the first item of feepKGs corresponds to the first runway and so forth. Unfortunately, since you sort returns a list, you have to use map instead of of to get a list of the feepKGs.
Next, we need to get our list of utilities from the list of feepKGs. It looks like your calculation for utility7 may be incorrect, since it's the only one different. Anyway, to apply the same operation to each item in a list, we use map:
let utilities map [(previous-business1 + previous-leisure1 + previous-business2 + previous-leisure2 + previous-business3 + previous-leisure3 ) / ?] feepKGs
map applies that big expression to each element of feepKGs (where the ? is the element). So utilities here is the same as your utility-list (assuming that your expression for utility7 is in fact wrong). To get the value of the max utility, you can just use max:
let max-utility max utilities
Then, we get the index of the max-utility to find out which one it was. Since your utility numbers start at 7, and list indices start at 0, we have to add 7 to the index:
set time 7 + position max-utility utilities
Related
im using a sorted list in netlogos but when i run my code i get an error message that it can't find element 3 because the lenght of the list is 3, that sounds really strange and counter intuative to me. what goes wrong
globals [
allehøjder
min_højde
nedre_højde
median_højde
øvre_højde
max_højde
]
breed [personer en_person]
personer-own [højde skostørrelse]
to setup ; runs when the button "setup" is pressed
clear-all
;kom alle højder ind i højde
;sorter højde listen
;find 5 kvartil værdien ud fra højder[]
create-personer 3
[
set color white
set højde (150 + ( random ( 190 - 150 )))
set skostørrelse (38 + (random ( 47 - 38 )) )
setxy random-xcor random-ycor
set size 10
]
set allehøjder [højde] of personer
set alleskostørrelser [skostørrelse] of personer
show sort allehøjder
show sort alleskostørrelser
;sætter de 5 kvartilværdier for højde
; sætter min
set min_højde item 1 (sort allehøjder)
;sætter max
**bold** set max_højde item 3 (sort allehøjder)
; sætter median
ifelse 3 mod 2 = 0
;lige antal
[
set median_højde item ((3 + 1 / 2) ) (sort allehøjder)
]
;ulige antal
[
set median_højde ((item ((3 + 1) / 2) (sort allehøjder) + item (((3 + 1) / 2) + 1) (sort allehøjder)) / 2)
]
reset-ticks
end
regards morten
The indexing of lists' items starts from 0, hence the third element will have index 2.
The NetLogo Programming Guide and the NetLogo Dictionary linked above should have you covered with this type of problems.
I am trying to pass the formBuyerAggressiveness into a bidTargetPrice procedure. It is giving a "Expected reporter" error message. Here is my code thus far.
to bidTargetPrice [tradeID]
let buyerAggressiveness [formBuyerAggresiveness] of tradeID
; if ( buyerAggresiveness <= 1 ) [
ifelse (- 1 < buyerAggresiveness) and (buyerAggresiveness <= 0)
[report equilibriumPrice * (1 - ( ( ( e ^ (- buyerAggresiveness * theta ) ) - 1) / (e ^ theta - 1) ) )
]
[report equilibriumPrice + ( (value - equilibriumPrice) * ( ( (e ^ (buyerAggresiveness * theta) ) - 1 ) / ( (e ^ theta) - 1) ) )
]
; ]
The following is the procedure which I call in the above procedure. I intend to pass the buyers aggressiveness parameter into a procudere that helps form the price.
to formBuyerAggresiveness
;define some local parameters
ifelse (transactionPrice > 0.0 )
[ ifelse (bidTargetPrice >= transactionPrice)
[ let desiredAggressiveness ( ( (1 - C2 ) * rshout) - C1 ) ;rshout is the degree of aggressiveness that would form a price equal to the last bid
report buyerAggressiveness (degreeOfAggressiveness + B1 * (desiredAggressiveness - degreeOfAggressiveness) ) ;degreeOfAggressiveness is a random of individual trader aggressiveness from -1 to 1 range. *defined during init user/buyer
]
[ let desiredAggressiveness ( ( (1 + C2 ) * rshout) + C1 ) ;buyer must be more aggresive
report degreeOfAggressiveness + B1 * (desiredAggressiveness - degreeOfAggressiveness)
]
]
[ if (bid?) and (bidTargetPrice <= bestBid)
[let desiredAggressiveness ( ( (1 + C2 ) * rshout) + C1 )
report degreeOfAggressiveness + B1 * (desiredAggressiveness - degreeOfAggressiveness)
]
]
end
The problem is with the line let buyerAggressiveness [formBuyerAggresiveness] of tradeID. There error message is telling you that [formBuyerAggresiveness] is not a reporter. The phrase [attrA] of myagent only works when myagent (i) is an agent and (ii) has this attribute.
To fix this, you have at least two choices.
give your agent an aggressiveness attribute and write a procedure to set it, so you can then access it with [aggressiveness] of myagent, or
write a reporter that takes an agent as an argument and returns an aggressiveness value for that agent
I'm trying to figure out if there is an easy way to convert numbers into words take 9 and convert it to nine.
There is an excellent library for .NET called Humanizer that can do exactly this. I haven't tried this yet, but it looks like there is a PowerShell wrapper for it. I suspect this will do exactly what you need.
This has been asked about .NET/C#; you could put this in a class and use Add-Type in powershell to make this work.
.NET convert number to string representation (1 to one, 2 to two, etc...)
Maybe something like this (untested):
$class = #"
public class Num2Word
{
public static string NumberToText( int n)
{
if ( n < 0 )
return "Minus " + NumberToText(-n);
else if ( n == 0 )
return "";
else if ( n <= 19 )
return new string[] {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen"}[n-1] + " ";
else if ( n <= 99 )
return new string[] {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy",
"Eighty", "Ninety"}[n / 10 - 2] + " " + NumberToText(n % 10);
else if ( n <= 199 )
return "One Hundred " + NumberToText(n % 100);
else if ( n <= 999 )
return NumberToText(n / 100) + "Hundreds " + NumberToText(n % 100);
else if ( n <= 1999 )
return "One Thousand " + NumberToText(n % 1000);
else if ( n <= 999999 )
return NumberToText(n / 1000) + "Thousands " + NumberToText(n % 1000);
else if ( n <= 1999999 )
return "One Million " + NumberToText(n % 1000000);
else if ( n <= 999999999)
return NumberToText(n / 1000000) + "Millions " + NumberToText(n % 1000000);
else if ( n <= 1999999999 )
return "One Billion " + NumberToText(n % 1000000000);
else
return NumberToText(n / 1000000000) + "Billions " + NumberToText(n % 1000000000);
}
}
#"
Add-Type -TypeDefinition $class
[Num2Word]::NumberToText(555)
There's no reason you couldn't write this as pure powershell, but this was already written!
I am trying to find out how to do the Progress equivalent of a "GROUP BY" function. I am trying to write a procedure that will list product inventory information for multiple locations. Right now, it is listing the product information twice; once for each location. I have tried the BREAK BY functional unsuccessfully. My current & desired output and code is below:
Current Output:
Desired Output:
DEF INPUT PARAMETER ip-um AS CHARACTER NO-UNDO.
MESSAGE
"ProdCode" + "^" +
"ProdName" + "^" +
"ProdUM" + "^" +
"GrossPkgdWeight" + "^" +
"QtyOH - LOC1" + "^" +
"QtyOH - LOC2"
SKIP.
FOR EACH product-um WHERE
product-um.gross-pkgd-weight <= 0.0000
NO-LOCK,
EACH product WHERE
product.product-key = product-um.product-key AND
product.can-be-sold = YES
NO-LOCK,
EACH inventory WHERE
inventory.product-key = product.product-key AND
inventory.qoh > 0 AND
inventory.level = 2
NO-LOCK,
EACH um WHERE
um.um-key = product-um.um-key AND
um.um = ip-um
NO-LOCK
BREAK BY product.product-code:
MESSAGE
product.product-code + "^" +
product.product-name + "^" +
um.um-code + "^" +
STRING(product-um.gross-pkgd-weight) + "^" +
IF inventory.level-key-2 = '00000001' THEN STRING(inventory.qoh) ELSE "0"
+ "^" + IF inventory.level-key-2 = '00000002' THEN STRING(inventory.qoh) ELSE "0"
SKIP.
END.
because you accumulate invesntory.qoh in dependency of inventory.level-key-2 the ACCUMULATE stmt is not realy feasible so coding the accumulation manually would be the best choise
DEFINE VARIABLE loc1 AS INTEGER NO-UNDO.
DEFINE VARIABLE loc2 AS INTEGER NO-UNDO.
FOR EACH product-um NO-LOCK
WHERE product-um.gross-pkgd-weight <= 0.0000
,
EACH product NO-LOCK
WHERE product.product-key = product-um.product-key
AND product.can-be-sold = YES
,
EACH inventory NO-LOCK
WHERE inventory.product-key = product.product-key
AND inventory.product-code = product.product-code
AND inventory.qoh > 0
AND inventory.level = 2
,
EACH um NO-LOCK
WHERE um.um-key = product-um.um-key
and um.um = ip-um
BREAK
BY product.product-code:
CASE (inventory.level-key-2):
WHEN "00000001"
THEN loc1 = loc1 + inventory.qoh.
WHEN "00000002"
THEN loc2 = loc2 + inventory.qoh.
END CASE.
IF LAST-OF(product.product-code)
THEN DO:
MESSAGE
product.product-code + "^" +
product.product-name + "^" +
um.um-code + "^" +
STRING(product-um.gross-pkgd-weight) + "^" +
STRING(loc1) + "^" +
STRING(loc2)
SKIP.
ASSIGN
loc1 = 0
loc2 = 0
.
END.
END.
BREAK BY tells the compiler to mark when the FOR EACH has come to the start or end of a break group.To detect these changes you'll need to use one of these functions to detect that change: FIRST(table.field), FIRST-OF(table.field), LAST(table.field), and LAST-OF(table.field).
Once the required function returns true, you can use the ABL supplied functions like ACCUMULATE, COUNT, TOTAL, etc. to display the desired results. Personally I find the concepts a bit hard to get my head around, so I declare some local variables and do the totals that way.
I have this program, something related with statistic.
maximo = max(muestra);
minimo = min(muestra);
rango = maximo - minimo;
num_intervalo = round(1 + 3.322*log(length(muestra)));
amplitud = rango/num_intervalo;
rango_intervalo = [];
for i=1 : num_intervalo + 1
if i == 1
rango_intervalo(i: num_intervalo + 1) = minimo;
else
rango_intervalo(i: num_intervalo + 1) = rango_tabulado(i) + amplitud;
end
if i == num_intervalo + 1
rango_intervalo(i: num_intervalo + 1) = maximo;
end
end
rango_intervalo = rango_intervalo';
the intention is to create nine (or k intervals) intervals, where each interval has it ranges:
[1.580 - 2.587]
[2.587 - 3.594]
.
.
[9.636 - 10.650]
With code that I've programmed, it is resulting in 10 data not nine as per the intention.
Any idea, the improve this code?
Thanks.
How about:
intervals = linspace(minimo, maximo, num_intervalo + 1 );
intervals = [ intervals(1:end-1); intervals(2:end) ]';