Advertisement
Guest User

Untitled

a guest
May 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.88 KB | None | 0 0
  1. % Modules
  2. :- use_module(library(lists)).
  3.  
  4. % Files to include
  5. :- ensure_loaded('iterator.pl').
  6. :- ensure_loaded('formulation.pl').
  7. :- ensure_loaded('choices2.pl').
  8. :- ensure_loaded('iconics.pl').
  9. :- ensure_loaded('utilities.pl').
  10.  
  11. %--------------------------------------------
  12.  
  13. policy_value(Species, Policy_value) :-
  14.     species_policy(Species, Policy),
  15.     create_tarcs(Policy),
  16.     discount(Gamma),
  17.     all_nodes(Nodes),
  18.     values(Nodes, Gamma, Values),
  19.     average(Values, Policy_value).
  20.  
  21. create_tarcs(Policy) :-
  22.     retractall(tarc(_, _, _, _)),
  23.     forall(arc(X, A, Y), add_tarc(X, A, Y, Policy)).
  24.  
  25. add_tarc(Icon, _, _, _) :-
  26.     iconic_goal(Icon), !.
  27. add_tarc((StateN, Perception), A, (StateDestN, PerceptionDest),
  28.         Policy) :-
  29.     member((Perception, A), Policy), !,
  30.     state(StateDestN, StateDest),
  31.     reward(StateDestN, PerceptionDest, Reward),
  32.     probability(A, StateDest, PerceptionDest, Probability),
  33.     assert(tarc((StateN, Perception),
  34.                 Probability, Reward,
  35.                 (StateDestN, PerceptionDest))).
  36. add_tarc(_, _, _, _).
  37.  
  38. reward(State, Perception, Reward) :-
  39.     iconic_goal((State, Perception)), !,
  40.     jackpot(Reward).
  41. reward(_, _, Reward) :- penalty(Reward).
  42.  
  43. probability(dr, _, _, 1) :- !.
  44. probability(gr, _, _, 1) :- !.
  45. probability(_, State, Perception, 1) :-
  46.     length(State, 0), perc(Perception, (s(0), _)), !.
  47. probability(_, _, Perception, 0.5) :-
  48.     perc(Perception, (s(0), _)), !.
  49. probability(_, State, Perception, Probability) :-
  50.     perc(Perception, (s(T), _)),
  51.     length(State, StateL), count_occurences(T, State, Count),
  52.     Probability is (0.5 * (StateL / Count)).
  53.  
  54. count_occurences(E, List, Count) :-
  55.     findall(Element, (member(Element, List), Element == E), Bag),
  56.     length(Bag, Count).
  57.  
  58. average(List, Average) :-
  59.     sumlist(List, 0, Sum),
  60.     length(List, Length),
  61.     Average is (Sum / Length).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement