<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Frepple / Python Interpreter</title> <link rel='stylesheet' href='../styles.css' type='text/css' /> <!--PageHeaderFmt--> </head> <body> <div id="container"> <div id="menubar"> <div id="logo" align="center"> <br/><img src='../frepple.bmp' alt="frepple" /><br/> <a href='http://www.frepple.com/'> <strong>a Free<br/>Production Planning<br/>Library</strong> </a></div> <div id="menu"> <br/> <h3><a href='../Main/HomePage.html'>Main</a></h3> <h3><a href='../UI/Main.html'>User Manual</a></h3> <h3><a href='../Tutorial/Main.html'>Tutorial</a></h3> <h3><a href='Main.html'>Reference Manual</a></h3> <h3><a href='../Main/FAQ.html'>FAQ</a></h3> <h3><a href='../reference/index.html'>C++ API</a></h3> <br/><div> </div> </div> </div> <div id="content"> <br/> <!--PageText--> <div id='wikitext'> <p><a class='wikilink' href='../Main/HomePage.html'>Main</a> > <span class='wikitrail'><a class='wikilink' href='Main.html'>Reference Manual</a> > <a class='wikilink' href='Modeling.html'>Modeling</a> > <a class='selflink' href='Python.html'>Python Interpreter</a></span> </p> <p class='vspace'>FrePPle embeds an interpreter for the Python language.<br />The full capabilities of this scripting language are accessible from frePPLe, and Python also has access to the frePPLe objects in memory.<br />Python is thus a very powerful way to interact with frePPLe. </p> <p class='vspace'>Python code can be executed in two ways: </p><ul><li>A <strong>XML processing instruction</strong> in XML data files. </li></ul><pre> <?xml version="1.0" encoding="UTF-8" ?> <plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;> ... <?python Your python code goes here. ?> ... </plan> </pre><ul><li>Python code in a <strong>file init.py</strong>, located in one of the frePPLe directories, is executed automatically when frePPLe starts. This provides a clean mechanism to define global Python functions and classes you application needs. </li></ul><p class='vspace'>The interpreter is multi-threaded. Multiple python scripts can run in parallel. However, Python internally executes only one thread at a time and the interpreter switches between the active threads.<br />A single, global interpreter instance is used. A global Python variable or function is thus visible across multiple invocations of the Python interpreter. </p> <p class='vspace'>A number of Python functions are defined: </p><ul><li><a href='Python.html#LOADMODULE'>loadmodule</a> dynamically loads an extension module. </li><li><a href='Python.html#READXMLFILE'>readXMLfile</a> processes a XML-file from the local file system. </li><li><a href='Python.html#READXMLDATA'>readXMLdata</a> processes a XML-formatted string. </li><li><a href='Python.html#ERASE'>erase</a> removes part of the model or plan from memory. </li><li><a href='Python.html#SAVEXNMLFILE'>saveXMLfile</a> saves the model to an XML-formatted file. </li><li><a href='Python.html#SAVEPLAN'>saveplan</a> saves the most important plan information to a file. </li><li><a href='Python.html#PRINTSIZE'>printsize</a> prints information about the memory size of the model and other system parameters. </li></ul><p class='vspace'><a name='LOADMODULE' id='LOADMODULE'></a> </p><h2>loadmodule</h2> <p>This command dynamically loads an extension module. </p> <div class='vspace'></div> <table border='1' width='100%' ><tr><td width='20%' valign='top'><strong>Field</strong> </td><td width='20%' valign='top'><strong>Type</strong> </td><td width='60%' valign='top'><strong>Description</strong> </td></tr><tr><td valign='top'>filename </td><td valign='top'>normalizedString </td><td valign='top'> <p>Name of the shared library file to be loaded.<br />The operating system should allow frePPLe to locate the file. The directories listed in the following environment variable should include the module shared library. </p><ul><li>LD_LIBRARY_PATH variable for Linux, Solaris </li><li>LIBPATH for AIX </li><li>SHLIB_PATH for HPUX </li><li>PATH for windows and cygwin </li></ul></td></tr><tr><td valign='top'>parameter </td><td valign='top'>parameter </td><td valign='top'> <p>Initialization and configuration values that are passed to the module's initialization routine.<br />A parameter consists of a PARAMETER and VALUE pair, as shown in the example below. </p></td></tr></table> <p class='vspace'>Example code: </p><pre> <?python frepple.loadmodule("your_module.so", parameter1="string value", parameter2=100, parameter3=True) ?> </pre><p class='vspace'><a name='READXMLFILE' id='READXMLFILE'></a> </p><h2>readXMLfile</h2> <p>This command reads and processes a XML-file from the local file system. </p> <div class='vspace'></div> <table border='1' width='100%' ><tr><td width='20%' valign='top'><strong>Field</strong> </td><td width='20%' valign='top'><strong>Type</strong> </td><td width='60%' valign='top'><strong>Description</strong> </td></tr><tr><td valign='top'>filename </td><td valign='top'>normalizedString </td><td valign='top'>Name of the data file to be loaded. </td></tr><tr><td valign='top'>validate </td><td valign='top'>boolean </td><td valign='top'> <p>When set to true, the XML data are validated against the XML-schema.<br />The default value is true, for security reasons.<br />When parsing large files with a trusted structure setting this field to false will speed up the import. </p></td></tr></table> <p class='vspace'>Example code: </p><pre> <?python frepple.readXMLfile("input.xml",True,True) ?> </pre><p class='vspace'><a name='READXMLDATA' id='READXMLDATA'></a> </p><h2>readXMLdata</h2> <p>This command processes a XML-formatted data string. </p> <div class='vspace'></div> <table border='1' width='100%' ><tr><td width='20%' valign='top'><strong>Field</strong> </td><td width='20%' valign='top'><strong>Type</strong> </td><td width='60%' valign='top'><strong>Description</strong> </td></tr><tr><td valign='top'>data </td><td valign='top'>string </td><td valign='top'>XML-formatted data to be processed. </td></tr><tr><td valign='top'>validate </td><td valign='top'>boolean </td><td valign='top'> <p>When set to true, the XML data are validated against the XML-schema.<br />The default value is true, for security reasons.<br />When processing large data strings with a trusted structure setting this field to false will speed up the execution. </p></td></tr></table> <p class='vspace'>Example code: </p><pre> <?python frepple.readXMLdata(''' <plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <locations> <location name="Location 1" action="R"/> </locations> </plan>''',True,True) ?> </pre><p class='vspace'><a name='ERASE' id='ERASE'></a> </p><h2>erase</h2> <p>Use this command to erase the plan or the entire model from memory. </p> <div class='vspace'></div> <table border='1' width='100%' ><tr><td width='20%' valign='top'><strong>Field</strong> </td><td width='20%' valign='top'><strong>Type</strong> </td><td width='60%' valign='top'><strong>Description</strong> </td></tr><tr><td valign='top'>mode </td><td valign='top'>boolean </td><td valign='top'> <p>When set to true the complete model is erased. You will again have a completely empty model.<br />When set to false only the plan information is erased, ie only the operationplans with their load- and flowplans are removed (except the ones that are locked). </p></td></tr></table> <p class='vspace'>Example code: </p><pre> <?python frepple.erase(False) ?> </pre><p class='vspace'><a name='SAVEXMLFILE' id='SAVEXMLFILE'></a> </p><h2>saveXMLfile</h2> <p>This commands saves the model into an XML-formatted file. </p> <div class='vspace'></div> <table border='1' width='100%' ><tr><td width='20%' valign='top'><strong>Field</strong> </td><td width='20%' valign='top'><strong>Type</strong> </td><td width='60%' valign='top'><strong>Description</strong> </td></tr><tr><td valign='top'>filename </td><td valign='top'>normalizedString </td><td valign='top'> <p>Name of the output file. </p></td></tr><tr><td valign='top'>content </td><td valign='top'> <p>STANDARD<br />PLAN<br />PLANDETAIL </p></td><td valign='top'> <p>Controls the level of detail in the output: </p><ul><li>STANDARD plan information is sufficient for restoring the model from the output file.<br /> This is the default mode. </li><li>PLAN adds more detail about its plan with each entity.<br /> A buffer will report on its flowplans, a resource reports on its loadplans, and a demand on its delivery operationplans. </li><li>PLANDETAIL goes even further and includes full pegging information the output.<br /> A buffer will report how the material is supplied and which demands it satisfies, a resource will report on how the capacity used links to the demands, and a demand shows the complete supply path used to meet it. </li></ul></td></tr><tr><td valign='top'>headerstart </td><td valign='top'>string </td><td valign='top'> <p>The first line of the XML output.<br />The default value is: </p><pre> <?xml version="1.0" encoding="UTF-8"?> </pre></td></tr><tr><td valign='top'>headeratts </td><td valign='top'>string </td><td valign='top'>Predefined attributes of the XML root-element.<br />The default value is: <pre> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" </pre></td></tr></table> <p class='vspace'>Example code: </p><pre> <?python frepple.saveXMLfile("output.xml") frepple.saveXMLfile("detailedoutput.xml","PLANDETAIL") ?> </pre><p class='vspace'><a name='SAVEPLAN' id='SAVEPLAN'></a> </p><h2>saveplan</h2> <p>This command saves the most important plan information to a file.<br />It is used for the unit tests, but its' usefullness in a real-life implementation is probably limited. </p> <div class='vspace'></div> <table border='1' width='100%' ><tr><td width='20%' valign='top'><strong>Field</strong> </td><td width='20%' valign='top'><strong>Type</strong> </td><td width='60%' valign='top'><strong>Description</strong> </td></tr><tr><td valign='top'>filename </td><td valign='top'>normalizedString </td><td valign='top'> <p>Name of the output file. </p></td></tr></table> <p class='vspace'>Example code: </p><pre> <?python frepple.saveplan("output.xml") ?> </pre><p class='vspace'><a name='PRINTSIZE' id='PRINTSIZE'></a> </p><h2>printsize</h2> <p>This command prints information about the memory size of the model and other sytem parameters. </p> <p class='vspace'>Example code: </p><pre> <?python frepple.printsize() ?> </pre> </div> <!--PageFooterFmt--> <!--HTMLFooter--> </div></div> </body> </html>