Michael Doorley writes:
Hi Christopher
Thanks for adding me to the list.
1. Can I use Ptolemy II by calling methods in the API that would
create a model, populate it, run a simulation and extract the results?
As a bonus for the advanced user I would like to save the model as an
XML file that could be opened in Ptolemy II GUI tools (e.g. Vergil),
but that is not a priority.
Yes. See ptolemy/actor/gui/MoMLSimpleApplication.java and
ptolemy/actor/gui/PtExecuteApplication.java, which both instantiate and
run
a model.
I have looked at MoMLSimpleApplication.java and my problem with it is that
it seems to require a file as input. I am looking for a solution where I
can create and populate model in memory directly from my program. The
closest thing I have found is the Dining Philosophers demo of the CSP
domain, which does not seem to have a file dependency, unless I am missing
it.
I am currently trying build an equivalent of that program for DE. Do you
know if any similar sample already exists?
Thanks for your help,
Michael
Sorry, I thought you wanted to _read_ a MoML file.
You could do something similar to how the
ptII/ptolemy/domains/ct/demo/Helicopter/Helicopter.java
works.
You could create a similar model with domain polymorphic or DE
actors and using the DE Director
Note that if you call
System.out.println(exportMoML());
from within a TypedCompositeActor, then you will get the MoML output.
See also:
ct/demo/Lorenz/Lorenz.java
ct/demo/SigmaDelta/SigmaDelta.java
ct/demo/SquareWave/SquareWave.java
ct/demo/StickyMasses/StickyMasses.java
ct/demo/Thermostat/Thermostat.java
sdf/demo/Butterfly/Butterfly.java
For example, to run the last demo, you would do
java -classpath ptolemy.actor.gui.CompositeActorApplication -class
ptolemy.domains.sdf.demo.Butterfly.Butterfly
The shallow code generator will read in certain models and generate
java files.
(See
http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/codegen.htm)
Below I ran the shallow code generator on
ptII/ptolemy/domains/de/lib/test/auto/Queue.xml
and added throws lines so that it would compile
The file is in the ptolemy/copernicus/shallow/cg/Queue
directory, so it is in the ptolemy.copernicus.shallow.cg.Queue package.
[EMAIL PROTECTED] 66% pwd
/vol/maury/maury2/cxh/ptII/ptolemy/copernicus/shallow/cg/Queue
[EMAIL PROTECTED] 67% cat CGQueue.java
/* CGQueue - Decompiled by JODE
* Visit http://jode.sourceforge.net/
*/
package ptolemy.copernicus.shallow.cg.Queue;
import ptolemy.actor.IOPort;
import ptolemy.actor.TypedCompositeActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.actor.TypedIORelation;
import ptolemy.actor.gui.LocationAttribute;
import ptolemy.actor.gui.SizeAttribute;
import ptolemy.actor.lib.Clock;
import ptolemy.actor.lib.Test;
import ptolemy.data.expr.Parameter;
import ptolemy.domains.de.kernel.DEDirector;
import ptolemy.domains.de.kernel.DEIOPort;
import ptolemy.domains.de.lib.Queue;
import ptolemy.kernel.ComponentPort;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.attributes.VersionAttribute;
import ptolemy.kernel.util.Settable;
import ptolemy.kernel.util.Workspace;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.moml.Documentation;
import ptolemy.moml.Vertex;
public class CGQueue extends TypedCompositeActor
{
public VersionAttribute A_createdBy;
public SizeAttribute A_vergilSize;
public LocationAttribute A_vergilLocation;
public DEDirector ADE;
public Parameter ADE_startTime;
public Parameter ADE_stopTime;
public Parameter ADE_stopWhenQueueIsEmpty;
public Parameter ADE_synchronizeToRealTime;
public Parameter ADE_isCQAdaptive;
public Parameter ADE_minBinCount;
public Parameter ADE_binCountFactor;
public ComponentPort PQueue_input;
public ComponentPort PQueue_output;
public ComponentPort PQueue_trigger;
public ComponentPort PClock_output;
public ComponentPort PClock_trigger;
public Parameter AClock_stopTime;
public Parameter AClock_period;
public Parameter AClock_offsets;
public Parameter AClock_values;
public Parameter AClock_numberOfCycles;
public Documentation AClock__doc;
public ComponentPort PClock2_output;
public ComponentPort PClock2_trigger;
public Parameter AClock2_stopTime;
public Parameter AClock2_period;
public Parameter AClock2_offsets;
public Parameter AClock2_values;
public Parameter AClock2_numberOfCycles;
public Documentation AClock2__doc;
public ComponentPort PTest_input;
public ComponentPort PTest_output;
public Parameter ATest_correctValues;
public Parameter ATest_tolerance;
public Parameter ATest_trainingMode;
public Vertex Arelation5_vertex1;
public CGQueue(Workspace workspace) throws IllegalActionException,
NameDuplicationException {
super(workspace);
__CGInit();
}