User Tools

Site Tools


solution_of_15._script

The Capsis training online

Back to the table of contents

Solution: Solution: 15. Script

Try to work with the helping elements before looking at the solution…

Helping elements

  • we work in training.myscripts.SimpleScript
  • you can copy your new data file in capsis4/data/training/ and change the input file name and location by analogy with the existing code
  • before script.init (ip), add a line to change the value of ip.regenerationMax to 5
  • script.init (ip) triggers the initialisation process (buildInitScene() + initializeModel()), just after, the root step is available
  • you can get references to many objects in the simulation by asking script:
    • script.getRoot () returns the root step
    • script.getProject () returns the project
    • script.getModel () returns the model connected to the project (here an instance of TraModel)
    • script.getRootDir () returns the location of the capsis4/ installation directory
  • To trigger an evolution, use script.evolve()
  • To trigger an intervention, use script.runIntervener (intervener, step)
  • To trigger an export, use script.runOFormat (export, step, fileName)
  • Check all these methods in the GScript superclass of C4Script
  • after script.init (ip), make a loop for 100 years in which you may:
    • run an evolution stage of 25 years
    • trigger an intervention
  • Adapt the evolution stage you will find in SimpleScript
  • to run the intervention, adapt this code:
import capsis.kernel.extensiontype.*;
import capsis.extension.intervener.*; 
 
(...)
 
// Intervention: cut tree between 5 and 15m height
Intervener thinner = new DHAThinner (DHAThinner.HEIGHT, 5, 15);
step = s.runIntervener (thinner, step);
  • keep the project saving at the end of the script to check the result with the DETimeN graph in Capsis' user interface
  • compile, then launch the script in the terminal, from the capsis4/ directory
  • the commands to launch the script can be found in the comment at the top of SimpleScript
  • Open Capsis in GUI mode, and open the saved project, open the DETimeN graph to check the simulation

A possible solution

Pieces of solution, to help adapt the script Reopen the save project in capsis graphical user interface to check the number of trees over time graph

Back to the table of contents

solution_of_15._script.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1