Package jline.io

Class SRVN2LQNX

java.lang.Object
jline.io.SRVN2LQNX

public final class SRVN2LQNX extends Object
SRVN input format (the LQNS .in / .lqn text grammar) for LayeredNetwork.

The reader translates an SRVN document into the LQN XML interchange and hands that to LayeredNetwork.parseXML, so loading model.in builds exactly the model that loading the .lqnx written by lqn2xml -Oxml model.in builds. The translation is deterministic and is reproduced byte for byte by the MATLAB (srvn2lqnx.m), Python (line_solver.io.srvn_io) and C++ (line::lqn::srvn2lqnx) twins, which is what their parity tests compare.

Grammar covered (LQNS 6): the G, P, U, T, E, A and R sections; processor, task, group, entry and activity declarations with every option LQNS accepts; fan-in/fan-out (I/O); semaphore and rwlock entries; activity precedence (sequence, AND/OR fork and join, quorum join, loop, reply lists); #pragma lines; and SPEX scalar parameters ($x = expr), which are substituted. A SPEX sweep ($x = [ ... ]) used by the model is refused, since one LayeredNetwork carries one value per parameter. SPEX observations (%u $U), histogram requests (H) and the R result list are requests for output, not model content, and are skipped.

Errors: a syntax or reference error raises LineInputException with id LINE:input:Format; a used SPEX sweep raises LineUnsupportedException with id LINE:unsupported:Format.

  • Method Details

    • formatNumber

      public static String formatNumber(double x)
      Shortest C %g spelling that round-trips x; the four codebases share this rule. Integers below 1e15 in magnitude print as %d.
      Parameters:
      x - the value
      Returns:
      its spelling
    • translate

      public static String translate(String src, String name)
      Translates SRVN text into an LQN XML document.
      Parameters:
      src - the SRVN document text
      name - the model name written to <lqn-model name=...>
      Returns:
      the LQN XML document, newline-terminated
      Throws:
      LineInputException - (LINE:input:Format) on a syntax or reference error
      LineUnsupportedException - (LINE:unsupported:Format) when the model uses a SPEX sweep
    • readText

      public static String readText(String path) throws IOException
      Reads a file as text the way Python's text mode does: UTF-8 with malformed bytes replaced, and \r\n / \r line ends read as \n.
      Parameters:
      path - the file path
      Returns:
      the file text
      Throws:
      IOException - if the file cannot be read
    • modelName

      public static String modelName(String path)
      The model name of a file: its basename without the extension.
      Parameters:
      path - the file path
      Returns:
      the name
    • translateFile

      public static String translateFile(String path) throws IOException
      Translates an SRVN file into an LQN XML document, naming the model after the file's basename without its extension.
      Parameters:
      path - the SRVN file
      Returns:
      the LQN XML document
      Throws:
      IOException - if the file cannot be read
    • isSrvnFile

      public static boolean isSrvnFile(String path)
      True when the file holds SRVN text rather than XML: its first non-blank character is not '<'.
      Parameters:
      path - the file path
      Returns:
      whether the file is SRVN text