Browse Source

VI51 - TP5

master
Skia 3 years ago
parent
commit
41a3029de6
11 changed files with 41 additions and 68 deletions
  1. +25
    -30
      VI51-TP5-Boids/src/main/generated-sources/sarl/fr/utbm/info/vi51/labwork5/agent/Fish.java
  2. +0
    -1
      VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/framework/agent/skill.sarl
  3. +1
    -1
      VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/labwork5/MainProgram.java
  4. +7
    -17
      VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/labwork5/agent/fish.sarl
  5. +1
    -1
      VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/labwork5/environment/WorldModel.java
  6. BIN
      VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/framework/agent/StandardPhysicEnvironment.class
  7. +0
    -1
      VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/framework/agent/skill.sarl
  8. BIN
      VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/MainProgram.class
  9. BIN
      VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/agent/Fish.class
  10. +7
    -17
      VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/agent/fish.sarl
  11. BIN
      VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/environment/WorldModel.class

+ 25
- 30
VI51-TP5-Boids/src/main/generated-sources/sarl/fr/utbm/info/vi51/labwork5/agent/Fish.java View File

@@ -24,7 +24,6 @@ import com.google.common.base.Objects;
import fr.utbm.info.vi51.framework.agent.AbstractAnimat;
import fr.utbm.info.vi51.framework.environment.PerceptionEvent;
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady;
import fr.utbm.info.vi51.framework.math.MathUtil;
import fr.utbm.info.vi51.framework.math.Point2f;
import fr.utbm.info.vi51.framework.math.Vector2f;
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour;
@@ -81,7 +80,7 @@ public class Fish extends AbstractAnimat {
@Percept
public void _handle_PerceptionEvent_1(final PerceptionEvent occurrence) {
fr.utbm.info.vi51.framework.environment.Percept body = occurrence.body;
float direction = 0f;
Vector2f direction = new Vector2f();
Random random = new Random();
Vector2f barycenter = new Vector2f();
Vector2f f = new Vector2f();
@@ -96,12 +95,8 @@ public class Fish extends AbstractAnimat {
Point2f _position_1 = body.getPosition();
Vector2f _minus = _position.operator_minus(_position_1);
barycenter.operator_add(_minus);
float _direction = direction;
float _angle = o.getAngle();
float _angle_1 = body.getAngle();
float _plus = (_angle + _angle_1);
float _divide = (_plus / 2f);
direction = (_direction + _divide);
Vector2f _direction = o.getDirection();
direction.operator_add(_direction);
Point2f _position_2 = body.getPosition();
Point2f _position_3 = o.getPosition();
Vector2f _minus_1 = _position_2.operator_minus(_position_3);
@@ -111,9 +106,9 @@ public class Fish extends AbstractAnimat {
Vector2f _minus_2 = _position_4.operator_minus(_position_5);
float _length = _minus_2.length();
double _power = Math.pow(_length, 1);
double _plus_1 = (_power + 1);
Vector2f _divide_1 = _multiply.operator_divide(((float) _plus_1));
f.operator_add(_divide_1);
double _plus = (_power + 1);
Vector2f _divide = _multiply.operator_divide(((float) _plus));
f.operator_add(_divide);
} else {
Serializable _type_1 = o.getType();
boolean _equals_1 = Objects.equal(_type_1, "TARGET");
@@ -123,41 +118,41 @@ public class Fish extends AbstractAnimat {
Vector2f _minus_3 = _position_6.operator_minus(_position_7);
Vector2f _multiply_1 = _minus_3.operator_multiply(5);
barycenter.operator_add(_multiply_1);
Point2f _position_8 = body.getPosition();
Point2f _position_9 = o.getPosition();
Point2f _position_8 = o.getPosition();
Point2f _position_9 = body.getPosition();
Vector2f _minus_4 = _position_8.operator_minus(_position_9);
Vector2f _unitVector = _minus_4.toUnitVector();
direction.operator_add(_minus_4);
Point2f _position_10 = body.getPosition();
Point2f _position_11 = o.getPosition();
Vector2f _minus_5 = _position_10.operator_minus(_position_11);
float _length_1 = _minus_5.length();
Vector2f _unitVector = _minus_5.toUnitVector();
Point2f _position_12 = body.getPosition();
Point2f _position_13 = o.getPosition();
Vector2f _minus_6 = _position_12.operator_minus(_position_13);
float _length_1 = _minus_6.length();
double _power_1 = Math.pow(_length_1, 8);
double _plus_2 = (_power_1 + 1);
Vector2f _divide_2 = _unitVector.operator_divide(((float) _plus_2));
f.operator_add(_divide_2);
double _plus_1 = (_power_1 + 1);
Vector2f _divide_1 = _unitVector.operator_divide(((float) _plus_1));
f.operator_add(_divide_1);
}
}
}
Vector2f _barycenter = barycenter;
int _size_1 = occurrence.perceptions.size();
double _divide_3 = (1.0 / _size_1);
barycenter = _barycenter.operator_multiply(((float) _divide_3));
float _clampRadian = MathUtil.clampRadian(direction);
direction = _clampRadian;
float _direction_1 = direction;
int _size_2 = occurrence.perceptions.size();
direction = (_direction_1 / _size_2);
Vector2f _plus_3 = barycenter.operator_plus(f);
float _angle_2 = body.getAngle();
float _minus_6 = (direction - _angle_2);
this.influenceSteering(_plus_3, _minus_6);
double _divide_2 = (1.0 / _size_1);
barycenter = _barycenter.operator_multiply(((float) _divide_2));
direction.operator_add(barycenter);
Vector2f _plus_2 = barycenter.operator_plus(f);
Vector2f _direction_1 = body.getDirection();
float _signedAngle = _direction_1.signedAngle(direction);
this.influenceKinematic(_plus_2, _signedAngle);
} else {
int _nextInt = random.nextInt();
int _nextInt_1 = random.nextInt();
Vector2f linear = new Vector2f(((float) _nextInt), ((float) _nextInt_1));
double _nextGaussian = random.nextGaussian();
float angular = ((float) _nextGaussian);
this.influenceSteering(linear, angular);
this.influenceKinematic(linear, angular);
}
}

+ 0
- 1
VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/framework/agent/skill.sarl View File

@@ -32,7 +32,6 @@ import io.sarl.core.DefaultContextInteractions
import io.sarl.lang.core.Address
import io.sarl.util.OpenEventSpace
import java.lang.reflect.Array
import java.util.Random
import java.util.UUID

skill StandardPhysicEnvironment implements PhysicEnvironment {

+ 1
- 1
VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/labwork5/MainProgram.java View File

@@ -39,7 +39,7 @@ public class MainProgram {

private static float WORLD_SIZE_X = 500;
private static float WORLD_SIZE_Y = 500;
private static int AGENT_COUNT = 200;
private static int AGENT_COUNT = 300;

/** Main program.
*

+ 7
- 17
VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/labwork5/agent/fish.sarl View File

@@ -24,7 +24,6 @@ import fr.utbm.info.vi51.framework.^agent.AbstractAnimat
import fr.utbm.info.vi51.framework.^agent.PhysicEnvironment
import fr.utbm.info.vi51.framework.environment.PerceptionEvent
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady
import fr.utbm.info.vi51.framework.math.MathUtil
import fr.utbm.info.vi51.framework.math.Vector2f
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour
import fr.utbm.info.vi51.motionbehavior.KinematicAlignBehaviour
@@ -58,7 +57,7 @@ agent Fish extends AbstractAnimat {

on PerceptionEvent {
var body = occurrence.body
var direction = 0f
var direction = new Vector2f
var random = new Random
var barycenter = new Vector2f
var f = new Vector2f
@@ -67,30 +66,21 @@ agent Fish extends AbstractAnimat {
for ( o : occurrence.perceptions ) {
if (o.type == "FISH") {
barycenter += o.position - body.position
direction += (o.angle + body.angle) / 2f;
direction += o.direction;
f += (body.position - o.position) * 4 / ((body.position - o.position).length ** 1 + 1) as float
}/* else if(o.type == "WALL") {
barycenter += body.position - o.position
f += (body.position - o.position).toUnitVector() * 10 / ((body.position - o.position).length ** 3 + 1) as float
} */ else if(o.type == "TARGET") {
} else if(o.type == "TARGET") {
barycenter += (o.position - body.position) * 5
direction += (o.position - body.position)
f += (body.position - o.position).toUnitVector() / ((body.position - o.position).length ** 8 + 1) as float
}
}
barycenter *= (1.0 / occurrence.perceptions.size) as float
direction = MathUtil.clampRadian(direction)
direction /= occurrence.perceptions.size
// println("Barycenter: " + barycenter)
// println("f: " + f)
// println("Sum: " + (barycenter + f))
influenceSteering(barycenter+f, direction-body.angle)
direction += barycenter
influenceKinematic(barycenter+f, body.direction.signedAngle(direction))
} else {
var linear = new Vector2f(random.nextInt() as float, random.nextInt() as float)
var angular = random.nextGaussian() as float
influenceSteering(linear, angular)
influenceKinematic(linear, angular)
}
}
}



+ 1
- 1
VI51-TP5-Boids/src/main/sarl/fr/utbm/info/vi51/labwork5/environment/WorldModel.java View File

@@ -54,7 +54,7 @@ import fr.utbm.info.vi51.framework.util.LocalizedString;
public class WorldModel extends AbstractEnvironment implements WorldModelStateProvider {

private final static float FISH_SIZE = 2f;
private final static float RADIUS = 20f;
private final static float RADIUS = 60f;
private MouseTarget mouseTarget = null;

BIN
VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/framework/agent/StandardPhysicEnvironment.class View File


+ 0
- 1
VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/framework/agent/skill.sarl View File

@@ -32,7 +32,6 @@ import io.sarl.core.DefaultContextInteractions
import io.sarl.lang.core.Address
import io.sarl.util.OpenEventSpace
import java.lang.reflect.Array
import java.util.Random
import java.util.UUID

skill StandardPhysicEnvironment implements PhysicEnvironment {

BIN
VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/MainProgram.class View File


BIN
VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/agent/Fish.class View File


+ 7
- 17
VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/agent/fish.sarl View File

@@ -24,7 +24,6 @@ import fr.utbm.info.vi51.framework.^agent.AbstractAnimat
import fr.utbm.info.vi51.framework.^agent.PhysicEnvironment
import fr.utbm.info.vi51.framework.environment.PerceptionEvent
import fr.utbm.info.vi51.framework.environment.SimulationAgentReady
import fr.utbm.info.vi51.framework.math.MathUtil
import fr.utbm.info.vi51.framework.math.Vector2f
import fr.utbm.info.vi51.motionbehavior.AlignBehaviour
import fr.utbm.info.vi51.motionbehavior.KinematicAlignBehaviour
@@ -58,7 +57,7 @@ agent Fish extends AbstractAnimat {

on PerceptionEvent {
var body = occurrence.body
var direction = 0f
var direction = new Vector2f
var random = new Random
var barycenter = new Vector2f
var f = new Vector2f
@@ -67,30 +66,21 @@ agent Fish extends AbstractAnimat {
for ( o : occurrence.perceptions ) {
if (o.type == "FISH") {
barycenter += o.position - body.position
direction += (o.angle + body.angle) / 2f;
direction += o.direction;
f += (body.position - o.position) * 4 / ((body.position - o.position).length ** 1 + 1) as float
}/* else if(o.type == "WALL") {
barycenter += body.position - o.position
f += (body.position - o.position).toUnitVector() * 10 / ((body.position - o.position).length ** 3 + 1) as float
} */ else if(o.type == "TARGET") {
} else if(o.type == "TARGET") {
barycenter += (o.position - body.position) * 5
direction += (o.position - body.position)
f += (body.position - o.position).toUnitVector() / ((body.position - o.position).length ** 8 + 1) as float
}
}
barycenter *= (1.0 / occurrence.perceptions.size) as float
direction = MathUtil.clampRadian(direction)
direction /= occurrence.perceptions.size
// println("Barycenter: " + barycenter)
// println("f: " + f)
// println("Sum: " + (barycenter + f))
influenceSteering(barycenter+f, direction-body.angle)
direction += barycenter
influenceKinematic(barycenter+f, body.direction.signedAngle(direction))
} else {
var linear = new Vector2f(random.nextInt() as float, random.nextInt() as float)
var angular = random.nextGaussian() as float
influenceSteering(linear, angular)
influenceKinematic(linear, angular)
}
}
}



BIN
VI51-TP5-Boids/target/classes/fr/utbm/info/vi51/labwork5/environment/WorldModel.class View File


Loading…
Cancel
Save