# Fruit selling From - Steffen Michels, Arjen Hommersom, Peter J. F. Lucas, Marina Velikova: A new probabilistic constraint logic programming language based on a generalised distribution semantics. Artif. Intell. 228: 1-44 (2015) We want to compute the likelihood of a consumer to buy a certain fruit. The price of the fruit depends on its yield, that is modeled with a Gaussian distribution.
:- use_module(library(mcintyre)). :- if(current_predicate(use_rendering/1)). :- use_rendering(c3). :- use_rendering(graphviz). :- endif. :- mc. :- begin_lpad. yield(apple,Y): gaussian(Y,12000.0, 1000.0). yield(banana,Y): gaussian(Y,10000.0, 1500.0).
The government may or may not support the market, this is modeled with discrete random variables.
support(apple): 0.3. support(banana):0.5.
The basic price is computed on the basis of the yield with a linear function.
basic_price(apple,B):- yield(apple,Y), {B=:=250-0.007 * Y}. basic_price(banana,B):- yield(banana,Y), {B=:=200-0.006 * Y}.
The actual price is computed from the basic price by raising by a fixed amount in case of government support:
price(Fruit,P):- basic_price(Fruit,B), support(Fruit), {P=:=B+50}. price(Fruit,B):- basic_price(Fruit,B), \+ support(Fruit).
A customer buys a certain fruit provided that its price is below a maximum:
buy(Fruit):- price(Fruit,P), max_price(Fruit,M),{P =< M}.
The maximum price follows a gamma distribution:
max_price(apple,M):gamma(M,10.0, 18.0). max_price(banana,M): gamma(M,12.0, 10.0). :- end_lpad.
We can now ask for the probability of the customer of buying a certain fruit.
mc_sample(buy(apple),1000,Prob).
mc_sample(buy(banana),1000,Prob).