Existence020.java

Package: existence/
File: Existence020.java

  1. package existence;
  2.  
  3. import coupling.Experiment;
  4. import coupling.Result;
  5. import coupling.interaction.Interaction020;
  6.  
  7. /**
  8.  * An Existence020 is a sort of Existence010 in which each Interaction has a predefined Valence.
  9.  * When a given Experience is performed and a given Result is obtained, the corresponding Interaction is considered enacted.
  10.  * The Existence020 is PLEASED when the enacted Interaction has a positive or null Valence, and PAINED otherwise.
  11.  * An Existence020 is still a single entity rather than being split into an explicit Agent and Environment.
  12.  * An Existence020 demonstrates a rudimentary decisional mechanism and a rudimentary learning mechanism.
  13.  * It learns to choose the Experience that induces an Interaction that has a positive valence.
  14.  * Try to change the Valences of interactions and the method giveResult(experience)
  15.  * and observe that the Existence020 still learns to enact interactions that have positive valences.
  16.  */
  17. public class Existence020 extends Existence010 {
  18.  
  19. @Override
  20. protected void initExistence(){
  21. Experiment e1 = addOrGetExperience(LABEL_E1);
  22. Experiment e2 = addOrGetExperience(LABEL_E2);
  23. Result r1 = createOrGetResult(LABEL_R1);
  24. Result r2 = createOrGetResult(LABEL_R2);
  25. /** Change the valence of interactions to change the agent's motivation */
  26. addOrGetPrimitiveInteraction(e1, r1, -1);
  27. addOrGetPrimitiveInteraction(e1, r2, 1);
  28. addOrGetPrimitiveInteraction(e2, r1, -1);
  29. addOrGetPrimitiveInteraction(e2, r2, 1);
  30. this.setPreviousExperience(e1);
  31. }
  32.  
  33. @Override
  34. public String step() {
  35.  
  36. Experiment experience = this.getPreviousExperience();
  37. if (this.getMood() == Mood.PAINED)
  38. experience = getOtherExperience(experience);
  39.  
  40. Result result = returnResult010(experience);
  41.  
  42. Interaction020 enactedInteraction = (Interaction020)this.addOrGetPrimitiveInteraction(experience, result);
  43.  
  44. if (enactedInteraction.getValence() >= 0)
  45. this.setMood(Mood.PLEASED);
  46. else
  47. this.setMood(Mood.PAINED);
  48.  
  49. this.setPreviousExperience(experience);
  50.  
  51. return experience.getLabel() + result.getLabel() + " " + this.getMood();
  52. }
  53.  
  54. /**
  55. * Create an interaction as a tuple <experience, result>.
  56. * @param experience: The experience.
  57. * @param result: The result.
  58. * @param valence: the interaction's valence
  59. * @return The created interaction
  60. */
  61. protected Interaction020 addOrGetPrimitiveInteraction(Experiment experience, Result result, int valence) {
  62. String label = experience.getLabel() + result.getLabel();
  63. if (!INTERACTIONS.containsKey(label)){
  64. Interaction020 interaction = createInteraction(label);
  65. interaction.setExperience(experience);
  66. interaction.setResult(result);
  67. interaction.setValence(valence);
  68. INTERACTIONS.put(label, interaction);
  69. }
  70. Interaction020 interaction = (Interaction020)INTERACTIONS.get(label);
  71. return interaction;
  72. }
  73.  
  74. @Override
  75. protected Interaction020 createInteraction(String label){
  76. return new Interaction020(label);
  77. }
  78.  
  79. @Override
  80. protected Interaction020 getInteraction(String label){
  81. return (Interaction020)INTERACTIONS.get(label);
  82. }
  83.  
  84. }
  85.  

See public discussions about this page or start a new discussion by clicking on the Google+ Share button. Please type the #IDEALMOOCExistence020 hashtag in your post: