Package org.kigalisim

Class KigaliSimFacade

java.lang.Object
org.kigalisim.KigaliSimFacade

public class KigaliSimFacade extends Object
Entry point into the Kigali platform when used as a library.

Facade which helps facilitate common operations within the Kigali simulation platform when used as a library. It also provides a unified interface for WASM and the command-line tool.

  • Constructor Details

    • KigaliSimFacade

      public KigaliSimFacade()
      Constructs a new KigaliSimFacade.
  • Method Details

    • parse

      public static ParseResult parse(String code)
      Parse a QubecTalk script.
      Parameters:
      code - String code to parse as a QubecTalk source.
      Returns:
      The parse result containing either the parse tree or errors.
    • interpret

      public static ParsedProgram interpret(ParseResult parseResult)
      Interpret a parsed QubecTalk script to Java objects which can run the simulation.
      Parameters:
      parseResult - The parse result from parsing the QubecTalk source.
      Returns:
      The parsed program which can be used to run a specific simulation.
    • parseAndInterpret

      public static ParsedProgram parseAndInterpret(String filePath) throws IOException
      Parse and interpret a QubecTalk script from a file.
      Parameters:
      filePath - The path to the QubecTalk script file.
      Returns:
      The parsed program which can be used to run a specific simulation.
      Throws:
      IOException - If there is an error reading the file.
    • getNumberTotalTrials

      public static int getNumberTotalTrials(ParsedProgram program)
      Calculate the total number of trials across all scenarios in a program.
      Parameters:
      program - The parsed program containing scenarios.
      Returns:
      The total number of trials across all scenarios.
    • runScenario

      public static Stream<EngineResult> runScenario(ParsedProgram program, String scenarioName, ProgressReportCallback progressCallback)
      Run a scenario from the provided program and return results.

      Creates and executes a simulation using the provided program and simulation name where this name refers to a scenario indicating the set of policies to be stacked. The simulation will iterate through all years from the scenario's start year to end year and collect results for all applications and substances for each year.

      Parameters:
      program - The parsed program containing the simulation to run.
      scenarioName - The name of the simulation to execute from the program.
      progressCallback - Callback for reporting progress, called after each trial completes.
      Returns:
      Stream of EngineResult objects containing the simulation results
    • getDetailedErrorMessage

      public static String getDetailedErrorMessage(ParseResult parseResult)
      Get a formatted error message from a ParseResult.

      Extracts detailed error information from a ParseResult and formats it for display to the user, including line numbers and error messages.

      Parameters:
      parseResult - The ParseResult containing errors.
      Returns:
      A formatted string with detailed error information, or null if no errors.
    • validate

      public static boolean validate(String filePath)
      Validate a QubecTalk script.

      Parse and interpret a QubecTalk script to check for syntax errors.

      Parameters:
      filePath - The path to the QubecTalk script file.
      Returns:
      True if the script is valid, false otherwise.
    • convertResultsToCsv

      public static String convertResultsToCsv(List<EngineResult> results)
      Convert a list of EngineResult objects to a CSV string.
      Parameters:
      results - The list of EngineResult objects to convert.
      Returns:
      A CSV string representation of the results.