Deprecated: this webpage is preserved for archival purposes. Please consider visiting the new Reo webpage.

How to use Extensible Automata

The extensible automata model is defined in the plug-in org.ect.ea. For loading and saving *.ea files check out the class org.ect.ea.EA.

If you are using the model outside of Eclipse, you have to register the automata extensions you want use first. You should also enable EA monitoring. This will make sure that your automata model is always consistent. This is how it should look like:

// Init the extension registry. Only needed outside of Eclipse.
IExtensionRegistry reg = EA.getExtensionRegistry();

// Register port names and constraint extensions.
reg.registerExtensionDefinition(AutomatonPortNamesProvider.EXTENSION_DEFINTION);
reg.registerExtensionDefinition(TransitionPortNamesProvider.EXTENSION_DEFINTION);
reg.registerExtensionDefinition(ConstraintExtensionProvider.EXTENSION_DEFINTION);


// Now the registry is initialized and we can create a new automaton.
Automaton automaton = new Automaton("My automaton").

// We have to specify which extensions should be used.
automaton.getUsedExtensionIds().add(AutomatonPortNamesProvider.EXTENSION_ID);
automaton.getUsedExtensionIds().add(TransitionPortNamesProvider.EXTENSION_ID);
automaton.getUsedExtensionIds().add(ConstraintExtensionProvider.EXTENSION_ID);

// Monitor the extensions.
EA.monitorExtensions(automaton, true);

// Now you can modify the automaton...

This looks complicated but it is very generic and helps us to add arbitrary extensions to the automata model. Again, if you are in Eclipse, you don't need to initialize the registry.

How to use Constraint Automata

If you only want to work with standard constraint automata, you can use the org.ect.ea.extensions.constraints.CA class. This could look like this:

// First we create an automaton.
Automaton automaton = new Automaton("Test");

// We need to specify that it is a constraint automaton with memory.
CA.convertToConstraintAutomatonWithMemory(automaton);

State q1 = new State("q1");
State q2 = new State("q2");
automaton.getStates().add(q1);
automaton.getStates().add(q2);

Transition t = new Transition(q1,q2);
automaton.getTransitions().add(t);

System.out.println("Created automaton " + CA.prettyPrint(automaton));

// Setting the portnames, memory cells and constraints.
try {
        CA.setPortNames(automaton, "A,B,C");
        CA.setPortNames(t, "A,B");
        CA.setMemoryCells(q1, "x,y");
        CA.setConstraint(t, "A=B | (A=1 & B=$s.x)");
        CA.setStartState(q1, true);
} 
catch (ParseException e) {
        System.err.println(e);
}

System.out.println("Created automaton " + CA.prettyPrint(automaton));

Automaton product = (new AutomataProduct()).computeProduct(automaton, automaton);
System.out.println("Computed product " + CA.prettyPrint(product));

System.out.println("Saving automata to 'test.ea'...");
try {
        Module module = CA.create("test.ea");
        module.getAutomata().add(automaton);
        module.getAutomata().add(product);
        
        // Save the module.
        CA.save(module);                
}
catch (IOException e) {
        System.err.println(e);
}

For converting a connector to a constraint automaton you can take a look at the class org.ect.codegen.reo2ea.Reo2EA.