API_Instruction 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Create a new Java Project and add the jars "CpsClassesModelController" and "CpsAlgorithm" to your Build Path.
  2. Then create a new Package and create a new Class.
  3. That Class has to implement the Interface "cpsAlgorithm".
  4. Your Class then has to implement the method RunAlgorithm.
  5. This Method gets a Model and the Controller.
  6. You can access all Data via the Model.
  7. The Controller has several Methods you can use as well.
  8. Your Class should look something like this:
  9. package projectPackage;
  10. import java.awt.Color;
  11. import classes.HolonObject;
  12. import classes.SubNet;
  13. import cpsAlgorithm.CpsAlgorithm;
  14. import ui.controller.Control;
  15. import ui.model.Model;
  16. public class Test implements CpsAlgorithm {
  17. @Override
  18. public void RunAlgorithm(Model model, Control control) {
  19. Color c = Color.RED;
  20. for (SubNet s : control.getSimManager().getSubNets()) {
  21. if (c == Color.RED) {
  22. c = Color.CYAN;
  23. } else if (c == Color.CYAN) {
  24. c = Color.PINK;
  25. } else {
  26. c = Color.RED;
  27. }
  28. for (HolonObject cps : s.getObjects()) {
  29. cps.setBorderColor(c);
  30. controller.addTextToConsole(cps.getName());
  31. }
  32. }
  33. }
  34. }
  35. Then in the program click on the Algorithm Button in the Simulation Menu.
  36. Go to your project and select the folder where your .java files are.
  37. Then you can Select the Algorithm you want to use in the ComboBox.
  38. Then Click on the Simulation Radio Button to switch to Simulation Mode.
  39. Your algorithm will now be used.