[TASK] Add a ton of event classes, fix up abox with simulation.

This commit is contained in:
Jan Philipp Timme 2016-10-09 14:10:23 +02:00
parent 038a6a85bc
commit bdf7191c18
6 changed files with 225 additions and 10 deletions

View File

@ -30,6 +30,35 @@
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#0"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#4">
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#2"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#5">
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#2"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#6">
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#0"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#7">
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#1"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#8">
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#1"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#9">
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<simontology:isCarModel rdf:resource="http://example.org/carSim/objects/CarModel#0"/>
</owl:NamedIndividual>
<!-- Car Model data -->

View File

@ -2,6 +2,7 @@
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<!-- Classes -->
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#Car">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
</rdf:Description>
@ -23,7 +24,7 @@
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#Event"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarAirbagEvent">
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarAirbagTriggeredEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
@ -33,6 +34,12 @@
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarCheckEngineEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarUserEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
@ -49,6 +56,76 @@
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarHandbrakeEngageEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarHandbrakeReleaseEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarLockEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarUnlockEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarStrongAcceleratingEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarStrongBrakingEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarStandingEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarMovingEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarWearEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarEngineWearEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarWearEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarBrakeWearEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarWearEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarHandbrakeWearEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarWearEvent"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#CarTireWearEvent">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="http://example.org/carSim/carSimulationOntology#CarWearEvent"/>
</rdf:Description>
<!-- Attributes -->
<rdf:Description rdf:about="http://example.org/carSim/carSimulationOntology#isOfCarModel">
<rdfs:domain rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
<rdfs:range rdf:resource="http://example.org/carSim/carSimulationOntology#CarModel"/>
@ -85,5 +162,4 @@
<rdfs:range rdf:resource="http://example.org/carSim/carSimulationOntology#Event"/>
</rdf:Description>
</rdf:RDF>

View File

@ -53,6 +53,8 @@ public class Car {
private double tirePressure2;
private double tirePressure3;
private double tirePressure4;
private boolean checkEngineLightOn;
// Sitzplätze? Reservierungen für X Personen?
@ -61,7 +63,42 @@ public class Car {
this.id = id;
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/Car";
this.quads = new ArrayList<RdfQuadruple>();
this.CAR_TYPE = RandomHelper.nextInt(2);
// Technical details according to data in ABox
switch(id) {
case 0:
this.CAR_TYPE = 0;
break;
case 1:
this.CAR_TYPE = 2;
break;
case 2:
this.CAR_TYPE = 1;
break;
case 3:
this.CAR_TYPE = 0;
break;
case 4:
this.CAR_TYPE = 2;
break;
case 5:
this.CAR_TYPE = 2;
break;
case 6:
this.CAR_TYPE = 0;
break;
case 7:
this.CAR_TYPE = 1;
break;
case 8:
this.CAR_TYPE = 1;
break;
case 9:
this.CAR_TYPE = 0;
break;
default:
this.CAR_TYPE = RandomHelper.nextInt(2);
break;
}
this.initializeCarType(this.CAR_TYPE);
}
@ -80,6 +117,8 @@ public class Car {
this.currentAction = CarAction.NONE;
this.isCurrentActionHard = false;
this.currentActionTicksLeft = 0;
// Other data
this.checkEngineLightOn = false;
}
public void keyClose() {
@ -111,10 +150,12 @@ public class Car {
public void engageHandbrake() {
this.handbrakeEngaged = true;
this.fireHandbrakeEngageEvent();
}
public void releaseHandbrake() {
this.handbrakeEngaged = false;
this.fireHandbrakeReleaseEvent();
}
public boolean isHandbrakeEngaged() {
@ -142,6 +183,11 @@ public class Car {
* Update internal stuff according to state
*/
public void tick() {
// See whether the check engine light comes on
if(RandomHelper.isLuckyByChance(0.002)) {
this.checkEngineLightOn = true;
}
// Do the simulation stuff
int rpmBonus = 0;
Car.logger.debug("Old state: " + this.currentState + ", Action: " + this.currentAction);
switch(this.currentAction) {
@ -158,10 +204,12 @@ public class Car {
case LOCKING:
this.isLocked = true;
this.currentState = CarState.LOCKED;
this.fireLockEvent();
break;
case UNLOCKING:
this.isLocked = false;
this.currentState = CarState.OFF;
this.fireUnlockEvent();
break;
case ACCELERATING:
if(this.currentState == CarState.IDLE) this.currentState = CarState.DRIVE;
@ -197,12 +245,17 @@ public class Car {
this.motorOn = false;
this.motorRpm = 0;
this.speed = 0;
this.fireAirbagEvent();
break;
case NONE:
break;
default:
break;
}
// See if the check Engine light is on and fire an event accordingly
if(this.checkEngineLightOn) {
this.fireCheckEngineEvent();
}
// Decrement action tick counter and move to none if action is done
this.currentActionTicksLeft--;
if(this.currentActionTicksLeft == 0) {
@ -217,7 +270,7 @@ public class Car {
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarAirbagEvent", time));
this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarAirbagTriggeredEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time));
}
@ -230,6 +283,42 @@ public class Car {
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time));
}
private void fireLockEvent() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarLockEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time));
}
private void fireUnlockEvent() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarUnlockEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time));
}
private void fireHandbrakeEngageEvent() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarHandbrakeEngageEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time));
}
private void fireHandbrakeReleaseEvent() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarHandbrakeReleaseEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time));
}
private void generateContinousReportQuads() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;

View File

@ -57,5 +57,9 @@ public class CarPool {
public List<Car> getCars() {
return new ArrayList<Car>(this.cars);
}
public boolean hasFreeCars() {
return !this.availableCars.isEmpty();
}
}

View File

@ -47,8 +47,25 @@ public class Driver {
this.carPool = carPool;
this.car = null;
this.quads = new ArrayList<RdfQuadruple>();
// Pick a random behaviour and stick to it.
this.trait = (Trait) RandomHelper.getRandomElementFromArray(Trait.values());
// Personality according to names in ABox
switch(id) {
case 0:
case 1:
this.trait = Trait.REGULAR;
break;
case 2:
this.trait = Trait.INSANE;
break;
case 3:
this.trait = Trait.CAREFUL;
break;
case 4:
this.trait = Trait.FAST;
break;
default:
this.trait = (Trait) RandomHelper.getRandomElementFromArray(Trait.values());
break;
}
}
public int getID() {
@ -64,12 +81,12 @@ public class Driver {
* given a car is available.
*/
public void tick() {
if(car == null) {
if(car == null && this.carPool.hasFreeCars()) {
// Nothing to do, maybe randomly take a free car
if(RandomHelper.isLuckyByChance(0.75)) {
this.takeRandomCarFor(RandomHelper.getRandomNumberWithin(20,50));
}
} else {
} else if(car != null) {
// Do random things with the car
if(this.car.needsInput()) {
this.useCar(this.car);

View File

@ -45,8 +45,8 @@ public class RentACarSimulation implements Runnable {
public RentACarSimulation() {
this.registerOwnPrefixes();
int numberOfCars = 2;
int numberOfCustomers = 1;
int numberOfCars = 2; // Maximum of 10 cars are in the ABox (0-9)
int numberOfCustomers = 5; // Maximum of 5 drivers are in the ABox (0-4)
// Create a car pool and drivers
this.carPool = new CarPool(numberOfCars);
this.drivers = new ArrayList<Driver>();