From Optflux
Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 92: Line 92:
 
##:[[Image:release8.png]]
 
##:[[Image:release8.png]]
 
# To understand the structure and contents of the plugin.xml file, please refer to the [[The_Plugin.xml_File]] section.
 
# To understand the structure and contents of the plugin.xml file, please refer to the [[The_Plugin.xml_File]] section.
#: [[Image:release9.png]]
+
##: [[Image:release9.png]]
 
# Filling the sub-directory structure with rational packages is the next step. Since AIBench/OptFlux development is based on 3 main artifacts we usually sub-divide our java classes by those 3 artifacts.
 
# Filling the sub-directory structure with rational packages is the next step. Since AIBench/OptFlux development is based on 3 main artifacts we usually sub-divide our java classes by those 3 artifacts.
 
## This means that '''we should create 3 sub-packages''', one for the OPERATIONS, one for the VIEWS and one for our DATATYPES.
 
## This means that '''we should create 3 sub-packages''', one for the OPERATIONS, one for the VIEWS and one for our DATATYPES.
Line 143: Line 143:
 
  }
 
  }
 
 
 
 
  '''@Port(direction=Direction.OUTPUT,order=3)'''                ''// use the port annotation with Direction = OUTPUT to note that this is an output of the operation''
+
  '''@Port(direction=Direction.OUTPUT,order=3)'''                "''// use the port annotation with Direction = OUTPUT to note that this is an output of the operation''"
 
  public int result(){
 
  public int result(){
 
  return this.x + this.y;
 
  return this.x + this.y;
Line 299: Line 299:
  
 
* The ''@Datatype'' annotation contains several properties that can be specified. Please refer [[Developers#AIBench_Datatypes | here]] for that.
 
* The ''@Datatype'' annotation contains several properties that can be specified. Please refer [[Developers#AIBench_Datatypes | here]] for that.
* You don't need to declare the Datatypes in the '''plugin.xml''' file. These will be captured automatically by AIBench/OptFlux when used in Operations or placed in the Clipboard.
+
* You don't need to declare the Datatypes in the '''plugin.xml''' file. This will be capture automatically by AIBench/OptFlux when used in Operations or placed in the Clipboard.
  
 
== Creating your first View ==
 
== Creating your first View ==
Line 366: Line 366:
  
 
Now we will create a more complex operation to interact with the recently created Datatypes and View:
 
Now we will create a more complex operation to interact with the recently created Datatypes and View:
 
We will name it ''MyMapOperation'' and place it inside the operations sub-package.
 
  
 
The code for the operation goes as follows:
 
The code for the operation goes as follows:
Line 377: Line 375:
 
  int[] elements;
 
  int[] elements;
 
 
 
 
  @Port(name="Operation",direction=Direction.INPUT,order=1)         '' // deciding on the operator to use - INPUT''
+
  @Port(name="Operation",direction=Direction.INPUT,order=1)         // deciding on the operator to use - INPUT
 
  public void setOperator(OperationEnumeration operation){
 
  public void setOperator(OperationEnumeration operation){
 
  this.operation = operation;
 
  this.operation = operation;
 
  }
 
  }
 
 
 
 
  @Port(name="Elements",direction=Direction.INPUT,order=2)            ''// defining the list of elements on which to apply the operator - INPUT''
+
  @Port(name="Elements",direction=Direction.INPUT,order=2)            // defining the list of elements on which to apply the operator - INPUT
 
  public void setList(int[] elements){
 
  public void setList(int[] elements){
 
  this.elements = elements;
 
  this.elements = elements;
 
  }
 
  }
 
 
 
 
  @Port(direction=Direction.OUTPUT,order=3)                                        ''// the output port''
+
  @Port(direction=Direction.OUTPUT,order=3)                                        // the output port (explained bellow)
 
  public MyComplexDatatype getResult(){
 
  public MyComplexDatatype getResult(){
 
  int res = elements[0];
 
  int res = elements[0];
Line 403: Line 401:
 
  List<MySimpleDatatype> listOfSimples = new ArrayList<MySimpleDatatype>();
 
  List<MySimpleDatatype> listOfSimples = new ArrayList<MySimpleDatatype>();
 
  for(int elem: elements)
 
  for(int elem: elements)
  listOfSimples.add(new MySimpleDatatype(elem));                    ''// create a list of MySimpleDatatype, one for each integer''
+
  listOfSimples.add(new MySimpleDatatype(elem));                    // create a list of MySimpleDatatype, one for each integer
 
 
 
 
  MyListDatatype list = new MyListDatatype(listOfSimples);              ''// create an instance of MyListDatatype. A wrapper for the list created above''
+
  MyListDatatype list = new MyListDatatype(listOfSimples);              // create an instance of MyListDatatype. A wrapper for the list created above
 
 
 
 
  MySimpleDatatype result = new MySimpleDatatype(res);                ''// create an instance of MySimpleDatatype to store the result''
+
  MySimpleDatatype result = new MySimpleDatatype(res);                // create an instance of MySimpleDatatype to store the result
 
 
 
 
  MyComplexDatatype toReturn = new MyComplexDatatype(list, operation, result); ''// create an instance of MyComplexDatatype to hold all the the information above''
+
  MyComplexDatatype toReturn = new MyComplexDatatype(list, operation, result); // create an instance of MyComplexDatatype to hold all the the information above
 
 
 
 
 
  return toReturn;  ''// return the instance of MyComplexDatatype to the Clipboard''
 
  return toReturn;  ''// return the instance of MyComplexDatatype to the Clipboard''
Line 415: Line 413:
 
   
 
   
 
  }
 
  }
 
The above example should be self-explanatory to any Java developer. We are applying the selected operation sequentially from the first element of the list to the next one, until the list of elements end.
 
 
=== Declaring the new operation in the plugin.xml file ===
 
 
We can not forget to declare the new operation in the '''plugin.xml''' file:
 
 
<extension
 
        uid="aibench.core"
 
        name="aibench.core.operation-definition"
 
        class="myplugin4optflux.operations.MyMapOperation">
 
        <operation-description
 
                  name="My Map Operation"
 
                  uid= "myplugin_mymapoperation"
 
                  path="20@Plugins/2@MyOperations"
 
          />
 
</extension>
 
 
If everything went well, we should now be able to run OptFlux using the [[Developers_First_Plugin#Creating_a_Run_Configuration_to_run_OptFlux_from_within_Eclipse | previously defined Run Configuration]] and test our new Operation:
 
 
=== Testing the new operation ===
 
 
* After running OptFlux, we should now be able to see a new operation in the menu:
 
*: [[Image:complex1.png]]
 
* The Input dialog for the new operation is generated and we will use it with the options depicted bellow:
 
*: [[Image:complex2.png]]
 
* We can now observe the Clipboard containing an instance of our '''MyComplexDatatype''':
 
*: [[Image:complex3.png]]
 
** Notice the structure of the complex datatype being reflected in the Clipboard. The instance contains three levels at the root:
 
*** An ''Operation'' of the type: OperationEnumeration;
 
*** A ''List of Elements'' of the type: MyListDatatype;
 
**** The list of elements list all the instances of ''MySimpleDatatype'' therein contained;
 
*** A ''Result'' of the type: MySimpleDatatype;
 
** This structure perfectly reflects the one that we defined in the Java code. This structure can be as complex as the programmer wishes.
 
* Finally by pressing one of the instances of ''MySimpleDatatype'' in the Clipboard, the new View will be launched in the right panel. You can see that the default view is also there. The programmer can add as many different views as desired to a given Datatype
 
*: [[Image:complex4.png]]
 

Please note that all contributions to Optflux may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Optflux:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)