From UBC Wiki

Prolog ecological food web

Authors: Dennis Truong and Ivan Gill

What is the problem?

We will determine if logic programming is suitable for modelling the stability of population abundances within the regulatory framework of an animal food web consisting of the following user-defined attributes:

  • A list of distinct animal species populations and their abundances
  • A list of predator-prey relationships
  • A description of how much prey each predator needs to survive

More specifically, we will develop a logic program that can answer the following questions:

  • Does every predator in the user-defined food web framework currently have enough prey to survive?
  • If you change the abundance of one prey population, what cascading changes are required in predator populations to ensure enough prey for every predator?

This will be a relatively simplistic food web framework, as we will be ignoring various real-world factors that contribute to population abundances outside a predator-prey context, such as competition between herbivores for resources. However, we hope that determining the suitability of logic programming for our food web will also enable us to provide a reasonable assessment on whether such factors could be easily integrated into our application.

What is the something extra?

The amount of information we require from users to develop our food web will make it tedious for users to define the knowledge base as we have previously done on our assignments by editing or commenting out our program predicates. We believe it would be easier for the user to provide their definitions in csv files with a common template. We also believe it would be easier to report cascading population abundance changes in a csv file as well, particularly when there are many populations to model. Therefore, we will explore how to use SWI-Prolog for both reading and writing query results to csv files.

What did we learn from doing this?

What did we do?

We modelled the following food web, without plants:


Rather than hard-code these relationships into clauses, we stored information on the above relationships in the following csv files:

File Description
animal_abundances.csv List of animals in our food web, and their population abundances
animal_consumption_relationships.csv Predator-prey interactions
animal_produced_energies.csv Arbitrary values for energy produced by each individual animal in the food web
animal_consumed_energies.csv Arbitrary values for energy consumed by each individual animal in the food web

We wrote clauses to parse the above csv files using the SWI-Prolog csv library.

The major clauses we wrote are system_ok and cascading_abundance_changes(Animal, NewAbundance, CascadingAbundances). system_ok determines if every predator in the food web has enough prey to survive, by calculating whether the total energy requirements of predators at a population level are equal to or below the total energy production values of their prey populations. cascading_abundance_changes(Animal, NewAbundance, CascadingAbundances) outputs the cascading changes to the abundances of predator populations when the query is supplied a new abundance for a specific prey animal. To calculate these cascading changes, we iterate through the food web in an appropriate order, calculating the maximum population abundance of each population we visit in the food web, based on the maximum population abundances of populations we have already visited.

Is logic programming suitable for modelling food webs?

There are several real-world factors we did not model in our program, which could be modelled with varying degrees of difficulty. First, we did not model competition between herbivores for plant resources. However, we could extend our program to model herbivore competition by modelling plants similar to how we currently model herbivores, and modelling herbivore-plant relationships similar to how we currently model predator-prey relationships. Second, we did not model intraspecific competition between animals in the same population. One solution for integrating intraspecific competition would be to model a food web of individuals instead of populations, but this would require exceptionally large csv files. Another solution would be to use more sophisticated, non-linear equations for modelling maximum population abundances, instead of the linear equations we are currently using.

However, we ultimately concluded that logic programming is not suitable for modelling the relationship between populations in a food web, because we cannot determine a method for extending our program to model dynamic relationships such as predator-prey cycles or bidirectional predator relationships. Implementing bidirectional relationships in our food web would result in an infinite loop when calculating cascading abundance changes. Such a limitation negates the usefulness of logic programming for modelling a food web in any real-world ecological setting. Therefore, logic programming may be better suited for webs without bidirectional relationships, such as manufacturing supply chains, where altered production costs would be unidirectionally reflected higher in the supply chain.

Links to code etc