문제

I am writing a multi-agent system in 2APL. In my agent file, I have the following call in a PC-rules function:

B(zoekBod(Location,Destination,Amount,PriceCorrection,PrevOrders,Price));

In a beliefs file, I have defined this prolog function as follows:

  zoekBod(Afz, Best, Aant, PC, [], Bod) :-
    Max is abs(Best-Afz)*Aant*PC,
    random( 1, Max, Bod ).

  zoekBod(Afz, Best, Aant, PC, [opdracht(_,Aantal,Afzender,Bestemming,Prijs)|_], Bod) :-
    OudeMaat=abs(Bestemming-Afzender)*Aantal,
    Maat=abs(Best-Afz)*Aant,
    0.75=<(Maat/OudeMaat),
    (Maat/OudeMaat)=<1.33,
    Bod=PC*Prijs.

  zoekBod(Afz, Best, Aant, PC, [opdracht(_,Aantal,Afzender,Bestemming,_)|R], Bod) :-
    OudeMaat=abs(Bestemming-Afzender)*Aantal,
    Maat=abs(Best-Afz)*Aant,
    (0.75>(Maat/OudeMaat); (Maat/OudeMaat)>1.33),
    zoekBod(Afz, Best, Aant, PC, [R], Bod).

It's in Dutch, but essentially the goal is that based on any previous orders, it calculates a price for the new order. When this belief is tested in 2APL, it gives me an error:

[STEP: Execute all plans]
Failed to execute:
B(zoekBod(1, 3, 15, 1, [], Prijs))

If I test it in gprolog with trace on, I get this result:

| ?- zoekBod(1,3,15,1,[],Prijs).
      1    1  Call: zoekBod(1,3,15,1,[],_17) ? 
      2    2  Call: _101 is abs(3-1)*15*1 ? 
      2    2  Exit: 30 is abs(3-1)*15*1 ? 
      3    2  Call: random(1,30,_17) ? 
      3    2  Exit: random(1,30,25) ? 
      1    1  Exit: zoekBod(1,3,15,1,[],25) ? 

Prijs = 25 ? 

(2 ms) yes
{trace}
| ?- 

Which is exactly as intended. My relevant mas section looks like this:

<agent name="v1" file="vervoerder_voorbeeld.2apl">
      <beliefs file="vervoerderext_voorbeeld.pl" shadow="true"/>
</agent>

I am completely stumped why it fails to execute. Could anyone help me out a bit here? Thanks in advance!

Sorry, found the answer:

zoekBod(Afz, Best, Aant, PC, [], Bod) :-
Max is abs(Best-Afz)*Aant*PC,
random( 1, Max, Bod ).

should be:

zoekBod(Afz, Best, Aant, PC, [], Bod) :-
Max is abs(Best-Afz)*Aant*PC,
Bod is int(random(Max)+0.5).
도움이 되었습니까?

해결책

Sorry, found the answer:

zoekBod(Afz, Best, Aant, PC, [], Bod) :- Max is abs(Best-Afz)*Aant*PC, random( 1, Max, Bod ).

should be:

zoekBod(Afz, Best, Aant, PC, [], Bod) :- Max is abs(Best-Afz)*Aant*PC, Bod is int(random(Max)+0.5).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top