Skip to content
Snippets Groups Projects
Commit dabef55e authored by ethanjwilliams's avatar ethanjwilliams
Browse files

Williams - Homework 3

parent 64248d7f
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
*/ */
package MV3500Cohort2024JulySeptember.homework3.Williams; package MV3500Cohort2024JulySeptember.homework3.Williams;
import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon;
import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton; import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton;
import edu.nps.moves.dis7.enumerations.*; import edu.nps.moves.dis7.enumerations.*;
...@@ -25,9 +24,9 @@ import java.util.logging.Logger; ...@@ -25,9 +24,9 @@ import java.util.logging.Logger;
* tasks of interest, and then reporting activity via PDUs to the network. * tasks of interest, and then reporting activity via PDUs to the network.
* Default program initialization includes PDU recording turned on by default. * Default program initialization includes PDU recording turned on by default.
* *
* Homework 3 Networking choices: * Homework 3 networking choices:
* This simulation uses UDP multicast for efficient distribution of PDUs to * This simulation uses UDP multicast for efficient distribution of PDUs to
* multiple participants, which is suitable for large-scale simulations where * multiple participants, which is great for large-scale simulations where
* state updates need to reach all networked participants. UDP is chosen over * state updates need to reach all networked participants. UDP is chosen over
* TCP due to its lower latency, which is essential for real-time simulations. * TCP due to its lower latency, which is essential for real-time simulations.
* *
...@@ -39,65 +38,38 @@ import java.util.logging.Logger; ...@@ -39,65 +38,38 @@ import java.util.logging.Logger;
*/ */
public class ExampleSimulationProgram public class ExampleSimulationProgram
{ {
/* **************************** infrastructure code, modification is seldom needed ************************* */
private String descriptor = this.getClass().getSimpleName(); private String descriptor = this.getClass().getSimpleName();
/** DIS channel defined by network address/port combination includes multiple utility capabilities */
protected DisChannel disChannel; protected DisChannel disChannel;
/** Factory object used to create new PDU instances */
protected PduFactory pduFactory; protected PduFactory pduFactory;
/** seconds per loop for real-time or simulation execution */ private double simulationTimeStepDuration = 1.0;
private double simulationTimeStepDuration = 1.0; // seconds TODO encapsulate
/** initial simulation time in seconds */
double simulationTimeInitial = 0.0; double simulationTimeInitial = 0.0;
/** current simulation time in seconds */
double simulationTimeSeconds = simulationTimeInitial; double simulationTimeSeconds = simulationTimeInitial;
/** Maximum number of simulation loops */
int MAX_LOOP_COUNT = 4; int MAX_LOOP_COUNT = 4;
String narrativeMessage1 = new String(); String narrativeMessage1 = new String();
String narrativeMessage2 = new String(); String narrativeMessage2 = new String();
String narrativeMessage3 = new String(); String narrativeMessage3 = new String();
/** EntityID settings for entity 1 */
protected EntityID entityID_1 = new EntityID(); protected EntityID entityID_1 = new EntityID();
/** EntityID settings for entity 2 */
protected EntityID entityID_2 = new EntityID(); protected EntityID entityID_2 = new EntityID();
/** ESPDU for entity 1 */
protected EntityStatePdu entityStatePdu_1; protected EntityStatePdu entityStatePdu_1;
/** ESPDU for entity 2 */
protected EntityStatePdu entityStatePdu_2; protected EntityStatePdu entityStatePdu_2;
/** FirePdu for entity 1 first weapon (if any) */
protected FirePdu firePdu_1a; protected FirePdu firePdu_1a;
/** FirePdu for entity 1 second weapon (if any) */
protected FirePdu firePdu_1b; protected FirePdu firePdu_1b;
/** MunitionDescriptor for these weapons */
protected MunitionDescriptor munitionDescriptor1; protected MunitionDescriptor munitionDescriptor1;
/**
* Constructor to create an instance of this class.
* Design goal: additional built-in initialization conveniences can go here
* to keep your efforts focused on the runSimulation() method.
*/
public ExampleSimulationProgram() public ExampleSimulationProgram()
{ {
initialize(); initialize();
} }
/**
* Constructor to create an instance of this class.
* @param newDescriptor describes this program, useful for logging and debugging
*/
public ExampleSimulationProgram(String newDescriptor) public ExampleSimulationProgram(String newDescriptor)
{ {
descriptor = newDescriptor; descriptor = newDescriptor;
initialize(); initialize();
} }
/**
* Utility Constructor that allows your example simulation program to override default network address and port
* @param address network address to use
* @param port corresponding network port to use
*/
public ExampleSimulationProgram(String address, int port) public ExampleSimulationProgram(String address, int port)
{ {
disChannel.setNetworkAddress(address); disChannel.setNetworkAddress(address);
...@@ -108,9 +80,6 @@ public class ExampleSimulationProgram ...@@ -108,9 +80,6 @@ public class ExampleSimulationProgram
initialize(); initialize();
} }
/** Initialize channel setup for OpenDis7 and report a test PDU
* @see initializeDisChannel
* @see initializeSimulationEntities */
private void initialize() private void initialize()
{ {
initializeDisChannel(); initializeDisChannel();
...@@ -122,7 +91,6 @@ public class ExampleSimulationProgram ...@@ -122,7 +91,6 @@ public class ExampleSimulationProgram
disChannel.sendCommentPdu(simulationTimeSeconds, DisChannel.COMMENTPDU_SIMULATION_TIMESTEP, timeStepMessage); disChannel.sendCommentPdu(simulationTimeSeconds, DisChannel.COMMENTPDU_SIMULATION_TIMESTEP, timeStepMessage);
} }
/** Initialize channel setup for OpenDis7 and report a test PDU */
private void initializeDisChannel() private void initializeDisChannel()
{ {
if (disChannel == null) if (disChannel == null)
...@@ -143,8 +111,6 @@ public class ExampleSimulationProgram ...@@ -143,8 +111,6 @@ public class ExampleSimulationProgram
disChannel.getPduRecorder().setVerbose(true); disChannel.getPduRecorder().setVerbose(true);
} }
/** Initialize simulation entities.
*/
public void initializeSimulationEntities() public void initializeSimulationEntities()
{ {
if (pduFactory == null) if (pduFactory == null)
...@@ -155,30 +121,31 @@ public class ExampleSimulationProgram ...@@ -155,30 +121,31 @@ public class ExampleSimulationProgram
firePdu_1b = pduFactory.makeFirePdu(); firePdu_1b = pduFactory.makeFirePdu();
munitionDescriptor1 = new MunitionDescriptor(); munitionDescriptor1 = new MunitionDescriptor();
// Define participants entityID_1.setSiteID((int)(Math.random() * 100))
entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); .setApplicationID((int)(Math.random() * 100))
.setEntityID((int)(Math.random() * 100));
disChannel.addEntity(entityID_1); disChannel.addEntity(entityID_1);
entityID_2.setSiteID(1).setApplicationID(2).setEntityID(4); entityID_2.setSiteID((int)(Math.random() * 100))
.setApplicationID((int)(Math.random() * 100))
.setEntityID((int)(Math.random() * 100));
disChannel.addEntity(entityID_2); disChannel.addEntity(entityID_2);
entityStatePdu_1.setEntityID(entityID_1); entityStatePdu_1.setEntityID(entityID_1);
entityStatePdu_1.setForceId(ForceID.FRIENDLY); entityStatePdu_1.setForceId(ForceID.FRIENDLY);
entityStatePdu_1.setEntityType(new _001Poseidon()); entityStatePdu_1.setEntityType(new _001Poseidon());
entityStatePdu_1.setMarking("Entity #53"); entityStatePdu_1.setMarking("Ethan's Poseidon #1");
entityStatePdu_2.setEntityID(entityID_2); entityStatePdu_2.setEntityID(entityID_2);
entityStatePdu_2.setForceId(ForceID.OPPOSING); entityStatePdu_2.setForceId(ForceID.OPPOSING);
entityStatePdu_2.setEntityType(new _002Triton()); entityStatePdu_2.setEntityType(new _002Triton());
entityStatePdu_2.setMarking("Entity #2"); entityStatePdu_2.setMarking("Ethan's Triton #2");
munitionDescriptor1.setQuantity(1); munitionDescriptor1.setQuantity(1);
firePdu_1a.setDescriptor(munitionDescriptor1).setRange(1000.0f); firePdu_1a.setDescriptor(munitionDescriptor1).setRange(1000.0f);
} }
/**
* This runSimulationLoops() method is customizable for running new simulations.
*/
@SuppressWarnings("SleepWhileInLoop") @SuppressWarnings("SleepWhileInLoop")
public void runSimulationLoops () public void runSimulationLoops ()
{ {
...@@ -195,13 +162,14 @@ public class ExampleSimulationProgram ...@@ -195,13 +162,14 @@ public class ExampleSimulationProgram
{ {
simulationLoopCount++; simulationLoopCount++;
entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + 1.0); entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + (Math.random() * 2));
System.out.println ("... My simulation just did something..."); System.out.println ("... My simulation just did something...");
System.out.flush(); System.out.flush();
narrativeMessage1 = "MV3500 ExampleSimulationProgram"; narrativeMessage1 = "Ethan's Custom Simulation Program";
narrativeMessage2 = "runSimulation() loop " + simulationLoopCount; narrativeMessage2 = "Loop " + simulationLoopCount + " - MV3500 Custom Version";
narrativeMessage3 = "Simulation developed by Ethan Williams";
if (simulationLoopCount > MAX_LOOP_COUNT) if (simulationLoopCount > MAX_LOOP_COUNT)
{ {
...@@ -242,14 +210,6 @@ public class ExampleSimulationProgram ...@@ -242,14 +210,6 @@ public class ExampleSimulationProgram
} }
} }
/**
* Send EntityState, Fire, Comment PDUs for this loop.
* @param simTimeSeconds simulation time in seconds
* @param entityStatePdu the ESPDU to send
* @param firePdu the FirePDU to send
* @param commentType enumeration value describing purpose of the narrative comment PDU
* @param comments String array of narrative comments
*/
public void sendAllPdusForLoopTimestep(double simTimeSeconds, public void sendAllPdusForLoopTimestep(double simTimeSeconds,
EntityStatePdu entityStatePdu, EntityStatePdu entityStatePdu,
FirePdu firePdu, FirePdu firePdu,
...@@ -265,10 +225,6 @@ public class ExampleSimulationProgram ...@@ -265,10 +225,6 @@ public class ExampleSimulationProgram
disChannel.sendCommentPdu(simTimeSeconds, commentType, comments); disChannel.sendCommentPdu(simTimeSeconds, commentType, comments);
} }
/**
* Initial execution via main() method: handle args array of command-line initialization (CLI) arguments here
* @param args command-line parameters: network address and port
*/
protected void handleArguments (String[] args) protected void handleArguments (String[] args)
{ {
if (args.length == 2) if (args.length == 2)
...@@ -285,47 +241,26 @@ public class ExampleSimulationProgram ...@@ -285,47 +241,26 @@ public class ExampleSimulationProgram
} }
} }
/**
* Get simple descriptor for this network interface, used in trace statements
* @return simple descriptor name
*/
public String getDescriptor() { public String getDescriptor() {
return descriptor; return descriptor;
} }
/**
* Set new simple descriptor for this network interface, used in trace statements
* @param newDescriptor simple descriptor name for this interface
*/
public void setDescriptor(String newDescriptor) { public void setDescriptor(String newDescriptor) {
if (newDescriptor == null) if (newDescriptor == null)
newDescriptor = ""; newDescriptor = "";
this.descriptor = newDescriptor; this.descriptor = newDescriptor;
} }
/**
* parameter accessor method
* @return the simulationTimeStepDuration in seconds
*/
public double getSimulationTimeStepDuration() { public double getSimulationTimeStepDuration() {
return simulationTimeStepDuration; return simulationTimeStepDuration;
} }
/**
* parameter accessor method
* @param timeStepDurationSeconds the simulationTimeStepDuration in seconds to set
*/
public void setSimulationTimeStepDuration(double timeStepDurationSeconds) { public void setSimulationTimeStepDuration(double timeStepDurationSeconds) {
this.simulationTimeStepDuration = timeStepDurationSeconds; this.simulationTimeStepDuration = timeStepDurationSeconds;
} }
/** Locally instantiable copy of program, can be subclassed. */
protected static ExampleSimulationProgram thisProgram; protected static ExampleSimulationProgram thisProgram;
/**
* Main method is first executed when a program instance is loaded.
* @param args command-line parameters: network address and port.
*/
public static void main(String[] args) public static void main(String[] args)
{ {
thisProgram = new ExampleSimulationProgram("test constructor"); thisProgram = new ExampleSimulationProgram("test constructor");
...@@ -342,4 +277,4 @@ public class ExampleSimulationProgram ...@@ -342,4 +277,4 @@ public class ExampleSimulationProgram
System.exit(0); System.exit(0);
} }
} }
\ No newline at end of file
For Homework 3, I modified the OpenDIS ExampleSimulationProgram to enhance its functionality For Homework 3, I customized the Example Simulation Program by randomizing the entity IDs
by experimenting with entity enumeration values and adjusting the network communication setup. and I also introduced randomized movement patterns for the entities during the simulation loop.
On the networking side, I configured the program to use UDP multicast for distribution of the PDUs across These changes make the simulation more realistic and ensuring variability in each run.
multiple participants in the simulation. I did this to attempt to create the \ No newline at end of file
low-latency communication needed in large-scale simulations, where UDP's minimal overhead is
advantageous, and multicast ensures that updates reach all clients at the same time. I also
enabled verbose logging to facilitate debugging. Additionally, I adjusted
the simulation loop to increment Entity 1’s position in each iteration, simulating movement, and set
the loop to run for a maximum of 10 iterations.
\ No newline at end of file
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