Skip to content
Snippets Groups Projects
Commit 6de6ab93 authored by dansl's avatar dansl
Browse files

Commit completed assignment 7

parent b44c54ef
No related branches found
No related tags found
No related merge requests found
Showing
with 700 additions and 65 deletions
......@@ -6,20 +6,63 @@ import simkit.random.RandomVariate;
import simkit.smd.Mover;
/**
*
* @author dansl
* The SimpleConstantRateMediator class represents a mediator that manages the
* interactions between a Mover object and a SimpleConstantRateSensor object. It
* extends the SimEntityBase class, which provides basic simulation entity
* functionality.
*/
public class SimpleConstantRateMediator extends SimEntityBase {
public final class SimpleConstantRateMediator extends SimEntityBase {
public RandomVariate exponentialGenerator;
/**
* Constructs a SimpleConstantRateMediator object with the specified
* exponential generator.
*
* @param exponentialGenerator the exponential generator to be used by the
* mediator
*/
public SimpleConstantRateMediator(RandomVariate exponentialGenerator1) {
setExponentialGenerator(exponentialGenerator1);
}
protected RandomVariate exponentialGenerator;
public void doEnterRange(Mover target, SimpleConstantRateSensor sensor) {
/**
* Constructs a SimpleConstantRateMediator object with the specified
* exponential generator.
*
* @param exponentialGenerator the exponential generator to be used by the
* mediator
*/
public void SimpleConstantRateMediator(RandomVariate exponentialGenerator) {
setExponentialGenerator(exponentialGenerator);
}
/**
* Performs the necessary actions when a Mover object enters the range of a
* SimpleConstantRateSensor object. If the target is not already detected by
* the sensor, it waits for a detection delay generated by the exponential
* generator.
*
* @param target the Mover object that entered the sensor's range
* @param sensor the SimpleConstantRateSensor object that detected the
* target
*/
public void doEnterRange(Mover target, SimpleConstantRateSensor sensor) {
if (!sensor.getContacts().contains(target)) {
sensor.waitDelay("Detection", exponentialGenerator.generate(), target);
}
}
/**
* Performs the necessary actions when a Mover object exits the range of a
* SimpleConstantRateSensor object. If the target is not already undetected
* by the sensor, it waits for an undetection delay generated by the
* exponential generator.
*
* @param target the Mover object that exited the sensor's range
* @param sensor the SimpleConstantRateSensor object that lost contact with
* the target
*/
public void doExitRange(Mover target, SimpleConstantRateSensor sensor) {
if (!sensor.getContacts().contains(target)) {
sensor.waitDelay("Undetection", exponentialGenerator.generate(), target);
......@@ -27,14 +70,18 @@ public class SimpleConstantRateMediator extends SimEntityBase {
}
/**
* @return the exponentialGenerator
* Retrieves the exponential generator used by the mediator.
*
* @return the exponential generator used by the mediator
*/
public RandomVariate getExponentialGenerator() {
return exponentialGenerator;
}
/**
* @param exponentialGenerator the exponentialGenerator to set
* Sets the exponential generator for the mediator.
*
* @param exponentialGenerator the exponential generator to be set
*/
public void setExponentialGenerator(RandomVariate exponentialGenerator) {
this.exponentialGenerator = exponentialGenerator;
......
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package mv3302;
import mv3302.sensor.SimpleConstantTimeSensor;
......@@ -9,22 +5,37 @@ import simkit.SimEntityBase;
import simkit.smd.Mover;
/**
*
* @author dansl
* The SimpleConstantTimeMediator class represents a mediator between a target
* Mover object and a SimpleConstantTimeSensor object. It extends the
* SimEntityBase class, which provides basic simulation entity functionality.
*/
public class SimpleConstantTimeMediator extends SimEntityBase {
/**
* Performs the necessary actions when the target Mover enters the range of
* the sensor.
*
* @param target The Mover object that entered the range of the sensor.
* @param sensor The SimpleConstantTimeSensor object responsible for
* detecting the target.
*/
public void doEnterRange(Mover target, SimpleConstantTimeSensor sensor) {
if (!sensor.getContacts().contains(target)) {
sensor.waitDelay("Detection", sensor.getTimeToDetect(), target);
}
}
/**
* Performs the necessary actions when the target Mover exits the range of
* the sensor.
*
* @param target The Mover object that exited the range of the sensor.
* @param sensor The SimpleConstantTimeSensor object responsible for
* detecting the target.
*/
public void doExitRange(Mover target, SimpleConstantTimeSensor sensor) {
if (!sensor.getContacts().contains(target)) {
sensor.waitDelay("Undetection", 0.0, target);
}
}
}
......@@ -5,18 +5,36 @@ import simkit.SimEntityBase;
import simkit.smd.Mover;
/**
*
* @author dansl
* The SimpleCookieCutterMediator class represents a mediator that interacts
* with a SimpleCookieCutterSensor to handle the detection and undetection of a
* Mover object. It extends the SimEntityBase class, which is a base class for
* simulation entities in SimKit.
*/
public class SimpleCookieCutterMediator extends SimEntityBase {
/**
* Handles the event when a Mover enters the range of the
* SimpleCookieCutterSensor. If the Mover is not already in the sensor's
* contacts, it waits for a "Detection" event to occur.
*
* @param target The Mover object that entered the sensor's range.
* @param sensor The SimpleCookieCutterSensor responsible for detection.
*/
public void doEnterRange(Mover target, SimpleCookieCutterSensor sensor) {
if (!sensor.getContacts().contains(target)) {
sensor.waitDelay("Detection", 0.0, target);
}
}
/**
* Handles the event when a Mover exits the range of the
* SimpleCookieCutterSensor. If the Mover is not already in the sensor's
* contacts, it waits for an "Undetection" event to occur. If the Mover is
* still not detected, it interrupts the ongoing "Detection" event.
*
* @param target The Mover object that exited the sensor's range.
* @param sensor The SimpleCookieCutterSensor responsible for detection.
*/
public void doExitRange(Mover target, SimpleCookieCutterSensor sensor) {
if (!sensor.getContacts().contains(target)) {
sensor.waitDelay("Undetection", 0.0, target);
......
......@@ -8,7 +8,7 @@ import simkit.smd.Mover;
* Instead of stopping at the end, return to the first and cycle through again
* until stopped by an external component.
*
* @author ahbuss
* @author dansl
*/
public class SimplePatrolMoverManager extends SimplePathMoverManager {
......
......@@ -8,31 +8,51 @@ import simkit.SimEntityBase;
import static simkit.smd.Math2D.ZERO;
import simkit.smd.Mover;
import simkit.smd.Sensor;
/**
*
* @author dsloan
*/
The SimpleReferee class represents a referee in a simulation. It extends the SimEntityBase class,
which provides basic functionality for simulation entities.
*/
public final class SimpleReferee extends SimEntityBase {
private List<Sensor> sensors;
private List<Mover> targets;
/**
Constructs a SimpleReferee object with an empty list of sensors and targets.
*/
public SimpleReferee() {
}
/**
Constructs a SimpleReferee object with the specified lists of sensors and targets.
@param sensors the list of sensors to set
@param targets the list of targets to set
*/
public SimpleReferee(List<Sensor> sensors, List<Mover> targets) {
setSensors(sensors);
setTargets(targets);
}
/**
Performs the run logic for the referee. If there are sensors present, it waits for the "InitSensor"
event with zero delay.
*/
public void doRun() {
if (!sensors.isEmpty()) {
waitDelay("InitSensor", 0.0, 0);
}
}
/**
Initializes a sensor at the specified index. Adds the sensor as a simulation event listener.
If there are more sensors to initialize, it waits for the "InitSensor" event for the next index.
@param i the index of the sensor to initialize
*/
public void doInitSensor(int i) {
sensors.get(i).addSimEventListener(this);
......@@ -43,6 +63,14 @@ public final class SimpleReferee extends SimEntityBase {
waitDelay("InitTarget", 0.0, i, 0);
}
/**
Initializes a target at the specified indices. Adds the target as a simulation event listener.
If there are more targets to initialize, it waits for the "InitTarget" event for the next indices.
Checks if the target is within range of the sensor and waits for the "EnterRange" event if necessary.
@param i the index of the sensor
@param j the index of the target
*/
public void doInitTarget(int i, int j) {
targets.get(j).addSimEventListener(this);
if (j < targets.size() - 1) {
......@@ -55,6 +83,14 @@ public final class SimpleReferee extends SimEntityBase {
}
}
}
/**
Updates a sensor with a target. Checks if the sensor and target are different and calculates
the enter and exit times. Handles different cases based on the number of times calculated.
If there are more sensors to update, it waits for the "UpdateSensor" event for the next index.
@param i the index of the sensor
@param target the target to update the sensor with
*/
public void doUpdateSensor(int i, Mover target) {
Sensor sensor = sensors.get(i);
......@@ -77,16 +113,39 @@ public final class SimpleReferee extends SimEntityBase {
if (i < sensors.size() - 1) {
waitDelay("UpdateSensor", 0.0, i + 1, target);
}
}
/**
* Notifies the referee that a target is starting to move. Initiates the "UpdateSensor" event
* with zero delay for the specified target.
*
* @param target the target that is starting to move
*/
public void doStartMove(Mover target) {
waitDelay("UpdateSensor", 0.0, 0, target);
}
/**
* Notifies the referee that a target has stopped. Initiates the "UpdateSensor" event
* with zero delay for the specified target.
*
* @param target the target that has stopped
*/
public void doStop(Mover target) {
waitDelay("UpdateSensor", 0.0, 0, target);
}
/**
* Updates a target with a sensor. Checks if the target and sensor are different and calculates
* the enter and exit times. Handles different cases based on the number of times calculated.
* If there are more targets to update, it waits for the "UpdateTarget" event for the next index.
*
* @param i the index of the target
* @param sensor the sensor to update the target with
*/
public void doUpdateTarget(int i, Sensor sensor) {
Mover target = targets.get(i);
double[] times = getEnterExitTimes(target, sensor);
......@@ -108,13 +167,35 @@ public final class SimpleReferee extends SimEntityBase {
}
}
/**
* Notifies the referee that a sensor is starting to move. Initiates the "UpdateTarget" event
* with zero delay for the specified sensor.
*
* @param sensor the sensor that is starting to move
*/
public void doStartMove(Sensor sensor) {
waitDelay("UpdateTarget", 0.0, 0, sensor);
}
/**
* Notifies the referee that a sensor has stopped. Initiates the "UpdateTarget" event
* with zero delay for the specified sensor.
*
* @param sensor the sensor that has stopped
*/
public void doStop(Sensor sensor) {
waitDelay("UpdateTarget", 0.0, 0, sensor);
}
/**
* Performs the actions when a target enters the range of a sensor. Calculates the enter and exit times
* and waits for the "ExitRange" event if necessary.
*
* @param target the target that entered the range
* @param sensor the sensor that detected the target
*/
public void doEnterRange(Mover target, Sensor sensor) {
double[] times = getEnterExitTimes(target, sensor);
......@@ -125,9 +206,25 @@ public final class SimpleReferee extends SimEntityBase {
}
}
/**
* Performs the actions when a target exits the range of a sensor.
*
* @param target the target that exited the range
* @param sensor the sensor that lost track of the target
*/
public void doExitRange(Mover target, Sensor sensor) {
}
/**
* Calculates the enter and exit times for a target and a sensor based on their relative locations
* and velocities. Returns an array of the calculated times.
*
* @param target the target to calculate times for
* @param sensor the sensor to calculate times for
* @return an array of the enter and exit times, or an empty array if no times were calculated
*/
private double[] getEnterExitTimes(Mover target, Sensor sensor) {
double[] times;
......@@ -166,32 +263,38 @@ public final class SimpleReferee extends SimEntityBase {
return times;
}
/**
* @return the sensors
*/
/**
* Returns a new list containing the sensors in the simulation.
* @return a list of sensors
*/
public List<Sensor> getSensors() {
return new ArrayList<>(sensors);
}
/**
* @param sensors the sensors to set
*/
/**
* Sets the list of sensors for the simulation.
*
* @param sensors the list of sensors to set
*/
public void setSensors(List<Sensor> sensors) {
this.sensors = new ArrayList<>(sensors);
}
/**
* @return the targets
*/
/**
* Returns a new list containing the targets in the simulation.
*
* @return a list of targets
*/
public List<Mover> getTargets() {
return new ArrayList<>(targets);
}
/**
* @param targets the targets to set
*/
/**
* Sets the list of targets for the simulation.
*
* @param targets the list of targets to set
*/
public void setTargets(List<Mover> targets) {
this.targets = new ArrayList<>(targets);
}
}
\ No newline at end of file
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.Arrays;
import mv3302.SimpleConstantRateMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.SimpleConstantRateSensor;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantRate1Mover {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
RandomVariate exponentialGenerator = RandomVariateFactory.getInstance("Exponential", .7);
Mover[] targets = new Mover[]{
new SimpleMover(new Point2D.Double(30.0, 40.0), 20.0),
new SimpleMover(new Point2D.Double(0, 0), 20.0)
};
Point2D[] targetPath = new Point2D[]{new Point2D.Double(-30.0, -40.0), new Point2D.Double(60.0, 80.0)};
Point2D[] sensorPath = new Point2D[]{new Point2D.Double(30.0, 40.0)};
SimplePathMoverManager[] targetMoverManager = new SimplePathMoverManager[]{
new SimplePathMoverManager(targetPath, true),
new SimplePathMoverManager(sensorPath, true)
};
Sensor[] sensors = new Sensor[targets.length];
double meanTimeToDetect = 5.0;
sensors[0] = new SimpleConstantRateSensor(targets[0], 30, meanTimeToDetect);
sensors[1] = new SimpleConstantRateSensor(targets[1], 40, meanTimeToDetect);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
for (Sensor sensor : sensors) {
sensor.addPropertyChangeListener(simplePropertyDumper);
}
for (int i = 0; i < targets.length; ++i) {
targets[i].addSimEventListener(targetMoverManager[i]);
targetMoverManager[i].addSimEventListener(targets[i]);
}
SimpleReferee simpleReferee = new SimpleReferee(Arrays.asList(sensors),
Arrays.asList(targets));
System.out.println(simpleReferee);
SimpleConstantRateMediator simpleConstantRateMediator = new SimpleConstantRateMediator(exponentialGenerator);
simpleReferee.addSimEventListener(simpleConstantRateMediator);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import mv3302.SimpleConstantRateMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.AbstractSimpleSensor;
import mv3302.sensor.SimpleConstantRateSensor;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantRate2Movers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
RandomVariate exponentialGenerator = RandomVariateFactory.getInstance("Exponential", .7);
SimpleMover mover1 = new SimpleMover(new Point2D.Double(-20.0, 0.0), 30.0);
AbstractSimpleSensor sensor1 = new SimpleConstantRateSensor(mover1, 20.0, 5.0);
Point2D[] moverPath1 = new Point2D[]{
new Point2D.Double(100.0, 0.0)
};
SimplePathMoverManager moverManager1 = new SimplePathMoverManager(moverPath1, true);
mover1.addSimEventListener(moverManager1);
moverManager1.addSimEventListener(mover1);
SimpleMover mover2 = new SimpleMover(new Point2D.Double(50.0, 0.0), 40.0);
AbstractSimpleSensor sensor2 = new SimpleConstantRateSensor(mover2, 30.0, 5.0);
Point2D[] moverPath2 = new Point2D[] {
new Point2D.Double(-100.0, 0.0)
};
SimplePathMoverManager moverManager2 = new SimplePathMoverManager(moverPath2, true);
mover2.addSimEventListener(moverManager2);
moverManager2.addSimEventListener(mover2);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
mover1.addPropertyChangeListener(simplePropertyDumper);
moverManager1.addPropertyChangeListener(simplePropertyDumper);
sensor1.addPropertyChangeListener(simplePropertyDumper);
mover2.addPropertyChangeListener(simplePropertyDumper);
moverManager2.addPropertyChangeListener(simplePropertyDumper);
sensor2.addPropertyChangeListener(simplePropertyDumper);
List<Mover> targets = new ArrayList<>();
targets.add(mover1);
targets.add(mover2);
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
SimpleReferee referee = new SimpleReferee(sensors, targets);
SimpleConstantRateMediator mediator1 = new SimpleConstantRateMediator(exponentialGenerator);
referee.addSimEventListener(mediator1);
System.out.println(mover1.paramString());
System.out.println(moverManager1);
System.out.println(sensor1.paramString());
System.out.println(mover2.paramString());
System.out.println(moverManager2);
System.out.println(sensor2.paramString());
System.out.println(referee);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.Arrays;
import mv3302.SimpleConstantTimeMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.SimpleConstantTimeSensor;
import simkit.Schedule;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantTime1Mover {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Mover[] targets = new Mover[]{
new SimpleMover(new Point2D.Double(30.0, 40.0), 20.0),
new SimpleMover(new Point2D.Double(0, 0), 20.0)
};
Point2D[] targetPath = new Point2D[]{new Point2D.Double(-30.0, -40.0), new Point2D.Double(60.0, 80.0)};
Point2D[] sensorPath = new Point2D[]{new Point2D.Double(30.0, 40.0)};
SimplePathMoverManager[] targetMoverManager = new SimplePathMoverManager[]{
new SimplePathMoverManager(targetPath, true),
new SimplePathMoverManager(sensorPath, true)
};
Sensor[] sensors = new Sensor[targets.length];
double timeToDetect = 5.0;
sensors[0] = new SimpleConstantTimeSensor(targets[0], 30, timeToDetect);
sensors[1] = new SimpleConstantTimeSensor(targets[1], 40, timeToDetect);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
for (Sensor sensor: sensors) {
sensor.addPropertyChangeListener(simplePropertyDumper);
}
for (int i = 0; i < targets.length; ++i) {
targets[i].addSimEventListener(targetMoverManager[i]);
targetMoverManager[i].addSimEventListener(targets[i]);
}
SimpleReferee simpleReferee = new SimpleReferee(Arrays.asList(sensors),
Arrays.asList(targets));
System.out.println(simpleReferee);
SimpleConstantTimeMediator simpleConstantTimeMediator = new SimpleConstantTimeMediator();
simpleReferee.addSimEventListener(simpleConstantTimeMediator);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import mv3302.SimpleConstantTimeMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.AbstractSimpleSensor;
import mv3302.sensor.SimpleConstantTimeSensor;
import simkit.Schedule;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantTime2Movers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SimpleMover mover1 = new SimpleMover(new Point2D.Double(-20.0, 0.0), 30.0);
AbstractSimpleSensor sensor1 = new SimpleConstantTimeSensor(mover1, 20.0, 5.0);
Point2D[] moverPath1 = new Point2D[]{
new Point2D.Double(100.0, 0.0)
};
SimplePathMoverManager moverManager1 = new SimplePathMoverManager(moverPath1, true);
mover1.addSimEventListener(moverManager1);
moverManager1.addSimEventListener(mover1);
SimpleMover mover2 = new SimpleMover(new Point2D.Double(50.0, 0.0), 40.0);
AbstractSimpleSensor sensor2 = new SimpleConstantTimeSensor(mover2, 30.0, 5.0);
Point2D[] moverPath2 = new Point2D[] {
new Point2D.Double(-100.0, 0.0)
};
SimplePathMoverManager moverManager2 = new SimplePathMoverManager(moverPath2, true);
mover2.addSimEventListener(moverManager2);
moverManager2.addSimEventListener(mover2);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
mover1.addPropertyChangeListener(simplePropertyDumper);
moverManager1.addPropertyChangeListener(simplePropertyDumper);
sensor1.addPropertyChangeListener(simplePropertyDumper);
mover2.addPropertyChangeListener(simplePropertyDumper);
moverManager2.addPropertyChangeListener(simplePropertyDumper);
sensor2.addPropertyChangeListener(simplePropertyDumper);
List<Mover> targets = new ArrayList<>();
targets.add(mover1);
targets.add(mover2);
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
SimpleReferee referee = new SimpleReferee(sensors, targets);
SimpleConstantTimeMediator mediator1 = new SimpleConstantTimeMediator();
referee.addSimEventListener(mediator1);
System.out.println(mover1.paramString());
System.out.println(moverManager1);
System.out.println(sensor1.paramString());
System.out.println(mover2.paramString());
System.out.println(moverManager2);
System.out.println(sensor2.paramString());
System.out.println(referee);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mv3302.run;
import java.awt.geom.Point2D;
......@@ -20,7 +17,7 @@ import simkit.util.SimplePropertyDumper;
*
* @author dansl
*/
public class Assignment7 {
public class Assignment7CookieSensor1Mover {
/**
* @param args the command line arguments
......
......@@ -16,7 +16,7 @@ import simkit.util.SimplePropertyDumper;
/**
*
* @author ahbuss
* @author dansl
*/
public class Assignment7CookieSensor2Movers {
......
package mv3302.run;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;
......
......@@ -5,12 +5,15 @@ import java.util.HashSet;
import java.util.Set;
import simkit.SimEntityBase;
import simkit.smd.Mover;
import simkit.smd.Sensor;
/**
* An abstract class representing a simple sensor. It extends the SimEntityBase
* class and implements the Sensor interface. Provides common functionality for
* sensors that detect and track movers. Subclasses need to implement specific
* detection algorithms.
*
* @author ahbuss
* @author dansl
*/
public abstract class AbstractSimpleSensor extends SimEntityBase implements Sensor {
......@@ -20,26 +23,48 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
protected Set<Mover> contacts;
/**
* Constructs a new AbstractSimpleSensor with an empty contacts set.
*/
public AbstractSimpleSensor() {
contacts = new HashSet<>();
}
/**
* Constructs a new AbstractSimpleSensor with the specified mover and
* maximum range. The contacts set is initialized as an empty set.
*
* @param mover the mover associated with the sensor
* @param maxRange the maximum range of the sensor
*/
public AbstractSimpleSensor(Mover mover, double maxRange) {
this();
setMover(mover);
setMaxRange(maxRange);
}
/**
* Resets the sensor to its initial state. Clears the contacts set.
*/
@Override
public void reset() {
super.reset();
contacts.clear();
}
/**
* Runs the sensor and fires a property change event for the contacts set.
*/
public void doRun() {
firePropertyChange("contacts", getContacts());
}
/**
* Performs detection of a target mover. Adds the target mover to the
* contacts set and fires property change events for contacts and detection.
*
* @param target the mover to be detected
*/
public void doDetection(Mover target) {
Set<Mover> oldContacts = getContacts();
contacts.add(target);
......@@ -48,6 +73,12 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
firePropertyChange("detection", target);
}
/**
* Removes a target mover from the contacts set. Fires property change
* events for contacts and undetection.
*
* @param target the mover to be undetected
*/
public void doUndetection(Mover target) {
Set<Mover> oldContacts = getContacts();
contacts.remove(target);
......@@ -56,16 +87,31 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
firePropertyChange("undetection", target);
}
/**
* Initiates the start move action for the specified mover. Delays the
* action for the current simulation time.
*
* @param mover the mover to start moving
*/
public void doStartMove(Mover mover) {
waitDelay("StartMove", 0.0, this);
}
/**
* Initiates the stop action for the specified mover. Delays the action for
* the current simulation time.
*
* @param mover the mover to stop
*/
public void doStop(Mover mover) {
waitDelay("Stop", 0.0, this);
}
/**
* @param mover the mover to set
* Initiates the stop action for the specified mover. Delays the action for
* the current simulation time.
*
* @param mover the mover to stop
*/
public void setMover(Mover mover) {
this.mover = mover;
......@@ -73,6 +119,8 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
}
/**
* Returns the maximum range of the sensor.
*
* @return the maxRange
*/
@Override
......@@ -81,6 +129,8 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
}
/**
* Sets the maximum range of the sensor.
*
* @param maxRange the maxRange to set
*/
public void setMaxRange(double maxRange) {
......@@ -91,6 +141,8 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
}
/**
* Sets the contacts of the sensor.
*
* @return the contacts
*/
@Override
......@@ -98,33 +150,68 @@ public abstract class AbstractSimpleSensor extends SimEntityBase implements Sens
return new HashSet<>(contacts);
}
/**
* Returns the mover associated with the sensor.
*
* @return the mover
*/
@Override
public Mover getMover() {
return mover;
}
/**
* Returns current location the mover associated with the sensor.
*
* @return the mover.currentLocation
*/
@Override
public Point2D getCurrentLocation() {
return mover.getCurrentLocation();
}
/**
* Returns velocity of the mover associated with the sensor.
*
* @return the movers velocity
*/
@Override
public Point2D getVelocity() {
return mover.getVelocity();
}
/**
* empty method for implementation
*/
@Override
public void doStartMove(Sensor sensor) {
}
/**
* empty method for implementation
*/
@Override
public void doStop(Sensor sensor) {
}
/**
* Returns a string representation of the AbstractSimpleSensor object. This
* method is overridden from the superclass to provide a customized string
* representation.
*
* @return a string representation of the AbstractSimpleSensor object
*/
public String paramString() {
return super.toString();
}
/**
* Returns a string representation of the AbstractSimpleSensor object. The
* string format includes the name, current location, velocity, and maximum
* range of the sensor.
*
* @return a string representation of the AbstractSimpleSensor object
*/
@Override
public String toString() {
return String.format("%s %s %s %,.4f", getName(), mover.getCurrentLocation(), mover.getVelocity(),
......
......@@ -6,7 +6,9 @@ import simkit.SimEntity;
import simkit.smd.Mover;
/**
*
*The Sensor interface represents a sensor entity in a simulation. It extends the SimEntity interface.
A sensor can provide information about its current location, velocity, and maximum range.
It can also start and stop moving, retrieve the mover associated with it, and get a set of contacts.
* @author dansl
*/
interface Sensor extends SimEntity {
......
package mv3302.sensor;
import simkit.smd.Mover;
/**
*
* @author dansl
* A simple constant rate sensor that detects objects within a maximum range
* based on a mean time to detect. Inherits from AbstractSimpleSensor.
*/
public class SimpleConstantRateSensor extends AbstractSimpleSensor {
public final class SimpleConstantRateSensor extends AbstractSimpleSensor {
private double meanTimeToDetect;
/**
* Constructs a SimpleConstantRateSensor object with default values.
*/
public SimpleConstantRateSensor() {
super();
}
/**
*
* Constructs a SimpleConstantRateSensor object with the specified mover,
* maximum range, and mean time to detect.
*
* @param mover the mover associated with the sensor
* @param maxRange the maximum range of the sensor
* @param meanTimeToDetect the mean time taken by the sensor to detect an
* object
*/
public SimpleConstantRateSensor(Mover mover, double maxRange, double meanTimeToDetect) {
super(mover, maxRange);
setMeanTimeToDetect(meanTimeToDetect);
}
/**
*
* Returns the mean time to detect an object.
*
* @return the mean time to detect an object
*/
public double getMeanTimeToDetect() {
return meanTimeToDetect;
}
/**
*
* Sets the mean time to detect an object.
*
* @param meanTimeToDetect the mean time to detect an object
* @throws IllegalArgumentException if the meanTimeToDetect value is less
* than 0.0
*/
public void setMeanTimeToDetect(double meanTimeToDetect) {
if (meanTimeToDetect < 0.0) {
throw new IllegalArgumentException("meanTimeToDetect must be >= 0.0: " + meanTimeToDetect);
......
package mv3302.sensor;
import java.util.HashSet;
import simkit.smd.Mover;
/**
*
* @author dansl
* A simple constant time sensor that detects objects in a given time frame. It
* extends the AbstractSimpleSensor class.
*/
public class SimpleConstantTimeSensor extends AbstractSimpleSensor {
public final class SimpleConstantTimeSensor extends AbstractSimpleSensor {
private double timeToDetect;
protected double timeToDetect;
/**
* Creates a new instance of SimpleConstantTimeSensor with default values.
*/
public SimpleConstantTimeSensor() {
super();
super();
}
/**
* Creates a new instance of SimpleConstantTimeSensor with the specified
* parameters.
*
* @param mover the mover object associated with the sensor
* @param maxRange the maximum range of the sensor
* @param timeToDetect the time taken by the sensor to detect an object
*/
public SimpleConstantTimeSensor(Mover mover, double maxRange, double timeToDetect) {
super(mover, maxRange);
setTimeToDetect(timeToDetect);
}
/**
*
* Returns the time taken by the sensor to detect an object.
*
* @return the time to detect an object
*/
public double getTimeToDetect() {
return timeToDetect;
}
/**
*
* Sets the time taken by the sensor to detect an object.
*
* @param timeToDetect the time to detect an object (must be >= 0.0)
* @throws IllegalArgumentException if the provided timeToDetect is less
* than 0.0
*/
public void setTimeToDetect(double timeToDetect) {
if (timeToDetect < 0.0) {
throw new IllegalArgumentException("timeToDetect must be >= 0.0: " + timeToDetect);
......
package mv3302.sensor;
import simkit.smd.Mover;
/**
*
* @author ahbuss
* A simple implementation of a cookie cutter sensor for detecting objects using
* a mover and a maximum range. Extends the AbstractSimpleSensor class.
*/
public class SimpleCookieCutterSensor extends AbstractSimpleSensor {
/**
* Constructs a new instance of SimpleCookieCutterSensor with default
* values.
*/
public SimpleCookieCutterSensor() {
super();
}
/**
* Constructs a new instance of SimpleCookieCutterSensor with the specified
* mover and maximum range.
*
* @param mover the mover object associated with the sensor
* @param maxRange the maximum range at which the sensor can detect objects
*/
public SimpleCookieCutterSensor(Mover mover, double maxRange) {
super(mover, maxRange);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment