24.05.2014 Views

pdf: 600KB - Potsdam Institute for Climate Impact Research

pdf: 600KB - Potsdam Institute for Climate Impact Research

pdf: 600KB - Potsdam Institute for Climate Impact Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

31<br />

6.8 Representation of the model in Prolog<br />

Prolog ("Programming in logic") is a computer language that was developed <strong>for</strong> representing and<br />

reasoning with statements in a particular <strong>for</strong>m of logic, called 'first-order predicate logic'. It<br />

represents an approach to computer programming that is totally different from that of most<br />

computer languages. In Prolog, a computer program consists of a collection of statements, which<br />

are taken to be true statements about some subset of the world. These statements can either be<br />

facts (rabbits eat grass) or rules (X is a herbivore if X eats grass). An introduction to Prolog is<br />

given in Appendix A2.<br />

Why is this relevant to declarative modelling? First, declarative modelling involves making lots<br />

of factual statements about a model: "The model contains a compartment called biomass and a<br />

flow called photosynthesis", <strong>for</strong> example. Prolog provides a compact way of capturing these<br />

statements. Second, a lot of the work we do as modellers involves reasoning about models:<br />

following influence chains through the model, interrogating the model structure, or finding models<br />

with certain properties. Some of these operations can be done in XSLT, but Prolog rules provide<br />

a far more powerful mechanism <strong>for</strong> doing this type of reasoning with models. Prolog is thus an<br />

ideal language <strong>for</strong> representing models declaratively (as a set of facts), and also <strong>for</strong> reasoning with<br />

models so represented. Muetzelfeldt et al (1989) discuss the utility of Prolog <strong>for</strong> ecological<br />

modelling; Robertson et al (1991) report on research into the representation of ecological models<br />

as logical statements in Prolog; and McIntosh et al (2003) presents a rule-based model,<br />

implemented in Prolog, <strong>for</strong> vegetation dynamics.<br />

Box 6.6 shows one way of representing the grass/water model in Prolog, using System Dynamics<br />

concepts.<br />

Box 6.6 The grass/water model represented in Prolog<br />

compartment(grass, 10).<br />

compartment(water, 20).<br />

flow(growth, outside, grass, 0.01*grass*water).<br />

flow(rain, outside, water, 10).<br />

flow(transpiration, water, outside, 0.02*grass*water).<br />

We state here that the model has 2 compartments and 3 flows. The 'compartment' predicate has<br />

two arguments, representing the compartment name and its initial value. The 'flow' predicate has<br />

4 arguments, representing the flow name, the source and destination compartments <strong>for</strong> the flow,<br />

and the equation used <strong>for</strong> calculating its value. Note the close similarity to the relational database<br />

representation: in fact, Prolog can be considered as a relational language.<br />

Prolog can be used <strong>for</strong> interrogating and reporting on model structure, in much the same way as<br />

using XML and XSLT, or the model in an Access database. However, the real power of Prolog<br />

comes when we want to do some <strong>for</strong>m of reasoning with the model design, going beyond<br />

interrogation or reporting. For example, we might want to:<br />

• trace through influence or flow networks, <strong>for</strong> example finding all flows directly or indirectly<br />

influenced by a certain parameter, or all compartments on a particular flow network;<br />

• check model syntax, i.e. that the model design adheres to rules of System Dynamics (e.g. no<br />

flows pointing to variables);<br />

• generate a C++ program from the model representation - this is exactly what Simile does when<br />

you want to run a model;<br />

• trans<strong>for</strong>m a model - e.g. collapse a complex part of the model into something simpler<br />

(Muetzelfeldt and Yanai, 1996);<br />

• automatically compare two models - perhaps each derived from a parent model by two<br />

separate groups over a 6-month period.<br />

Such tasks can also be programmed in other languages, but Prolog is especially suited <strong>for</strong> it: it is a<br />

symbolic reasoning language, and thus ideal <strong>for</strong> reasoning with a symbolically-represented model.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!