Commit f178d915 authored by Nicolas Seydoux's avatar Nicolas Seydoux
Browse files

Merge branch 'shapes-activation' of https://framagit.org/nseydoux/edr into shapes-activation

parents 7fa50e22 07d256c4
{
"name":"comfort-app",
"uri":"http://localhost/",
"port":8005,
"endpoint":"http://localhost:6001/rules/add",
"ruleset":[
"shapes/abstract/r1Shape.ttl",
"shapes/abstract/r2Shape.ttl",
"shapes/abstract/r3Shape.ttl",
"shapes/abstract/r4Shape.ttl",
"shapes/abstract/r5Shape.ttl",
"shapes/abstract/r6Shape.ttl",
"shapes/abstract/r7Shape.ttl",
"shapes/abstract/r8Shape.ttl",
"shapes/abstract/r9Shape.ttl"
]
}
......@@ -274,8 +274,7 @@ ex:IIoTR1CoreRule
ssn:observedBy ?state_sensor.
FILTER(?stateValue = '1.0'^^xsd:float)
?machine a iiot:Machine;
iiot:onConveyor/iiot:locatedIn? ?presenceFeature.
?machine iiot:onConveyor/iiot:locatedIn? ?presenceFeature.
?presenceFeature iiot:locatedIn? ?feature.
$this a lmu:HostNode.
......
......@@ -281,8 +281,7 @@ ex:IIoTR6CoreRule
FILTER(?machineSpeedValue < ?conveyorSpeedValue)
?machine a iiot:Machine;
iiot:onConveyor ?conveyor.
?machine iiot:onConveyor ?conveyor.
$this a lmu:HostNode.
......
......@@ -9,16 +9,17 @@ fig = plt.figure()
ax = fig.add_subplot(111)
results = [
# "/home/nseydoux/dev/edr/results_rpi23sb_1",
# "/home/nseydoux/dev/edr/results_rpi23sb_2",
# "/home/nseydoux/dev/edr/results_rpi23sb_3",
# "/home/nseydoux/dev/edr/results_rpi23sb_4",
# "/home/nseydoux/dev/edr/results_rpi23sb_5",
#"/home/nseydoux/dev/edr/results/results_rpi23sb_1",
#"/home/nseydoux/dev/edr/results/results_rpi23sb_2",
#"/home/nseydoux/dev/edr/results/results_rpi23sb_3",
#"/home/nseydoux/dev/edr/results/results_rpi23sb_4",
#"/home/nseydoux/dev/edr/results/results_rpi23sb_5",
# "/home/nseydoux/dev/edr/results_tmp"
# "/home/nseydoux/dev/edr/results_shapes_rpi23sb_1",
"/home/nseydoux/dev/edr/results_shapes_rpi23sb_2",
"/home/nseydoux/dev/edr/results_shapes_rpi23sb_3",
"/home/nseydoux/dev/edr/results_shapes_rpi23sb_4"
# "/home/nseydoux/dev/edr/results/results_shapes_rpi23sb_2",
# "/home/nseydoux/dev/edr/results/results_shapes_rpi23sb_3",
# "/home/nseydoux/dev/edr/results/results_shapes_rpi23sb_4"
"/home/nseydoux/dev/edr/results_minimal_cdp"
]
for path in results:
......@@ -32,15 +33,18 @@ for path in results:
lbl = "s"+"0"
labels.append(lbl)
decentralized = []
for data_file in glob.glob(path+"/journ_delays_1"):
# print(data_file)
with open(data_file, "rb") as f:
decentralized.append(pickle.load(f))
data.append([x for l in decentralized for x in l])
lbl = path.split("/")[5]
lbl = "s"+"1"
labels.append(lbl)
print("Centralized deductions : "+str(len(data[0])))
# decentralized = []
# for data_file in glob.glob(path+"/journ_delays_1"):
# # print(data_file)
# with open(data_file, "rb") as f:
# decentralized.append(pickle.load(f))
# data.append([x for l in decentralized for x in l])
# lbl = path.split("/")[5]
# lbl = "s"+"1"
# labels.append(lbl)
# print("Decentralized deductions : "+str(len(data[1])))
# plt.boxplot(data,0, '')
......
......@@ -59,20 +59,20 @@ python3 simulator/generator.py -t simulator/coopis/default_factory.json -o simul
python3 simulator/generator.py -t simulator/coopis/small_factory.json -o simulator/coopis/small_factory_adp -c adp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/scala_syndream/clone_f_0_cdr -c cdr
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/scala_syndream/clone_f_0_cir -c cir
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/scala_syndream/clone_f_0_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/scala_syndream/clone_f_0_cip -c cip
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/scala_syndream/clone_f_0_adp -c adp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/scala_syndream/clone_f_1_cdr -c cdr
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/scala_syndream/clone_f_1_cir -c cir
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/scala_syndream/clone_f_1_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/scala_syndream/clone_f_1_cip -c cip
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/scala_syndream/clone_f_1_adp -c adp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/scala_syndream/clone_f_2_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/scala_syndream/clone_f_2_cir -c cir
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/scala_syndream/clone_f_2_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/scala_syndream/clone_f_2_cip -c cip
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/scala_syndream/clone_f_2_adp -c adp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/clone_f_0_cdr -c cdr
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/clone_f_0_cir -c cir
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/clone_f_0_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/clone_f_0_cip -c cip
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_0.json -o simulator/coopis/clone_f_0_adp -c adp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/clone_f_1_cdr -c cdr
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/clone_f_1_cir -c cir
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/clone_f_1_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/clone_f_1_cip -c cip
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_1.json -o simulator/coopis/clone_f_1_adp -c adp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/clone_f_2_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/clone_f_2_cir -c cir
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/clone_f_2_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/clone_f_2_cip -c cip
python3 simulator/generator.py -t simulator/coopis/scala_syndream/clone_f_2.json -o simulator/coopis/clone_f_2_adp -c adp
......@@ -18,12 +18,14 @@
<Filter type="MarkerFilter" marker="EXCEPTION" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</Appender>
<Appender type="File" name="LogAppender" fileName="${sys:filename}">
<Appender type="File" name="LogAppender" fileName="test.log">
<Layout type="PatternLayout">
<Filters>
<Filter type="MarkerFilter" marker="MODEL_MARKER" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Pattern>%msg%n</Pattern>
</Layout>
</Appender>
</Appenders>
<Loggers>
<Logger name="org.apache.jena" level="info" additivity="true">
......
......@@ -78,7 +78,7 @@ public enum E_Property {
return E_Property.HYGROMETRY;
} else if(value.equals("athmospheric_pressure")){
return E_Property.ATHMOSPHERIC_PRESSURE;
} else if(value.equals("machineState")){
} else if(value.equals("machine_state")){
return E_Property.MACHINE_STATE;
} else if(value.equals("conveyor_state")){
return E_Property.CONVEYOR_STATE;
......
......@@ -90,18 +90,20 @@ public class InterestManager {
// targets = Node.getInstance().getProductionManager().getProducers(interestURI);
if(E_Centralization.rawDataPropagation(Node.getInstance().getConfiguration().getCentralization())){
targets = Node.getInstance().getProductionManager().getProducers(interestURI);
LOGGER.debug(targets.size()+" nodes under "+Node.getInstance().getName()+" are producers of "+interestURI);
} else {
targets = Node.getInstance().getProductionManager().getPartialProducers(interestURI);
LOGGER.debug(targets.size()+" nodes under "+Node.getInstance().getName()+" are partial producers of "+interestURI);
}
LOGGER.debug(targets.size()+" nodes under "+Node.getInstance().getName()+" are partial producers of "+interestURI);
//} else {
// targets.addAll(Node.getInstance().getProductionManager().getPartialProducers(interestURI));
//}
for(String downstream : targets){
String downstreamEndpoint = Node.getInstance().getTopologyManager().getEndpoint(downstream);
if(downstreamEndpoint != null && !(downstreamEndpoint.equals(""))){
LOGGER.debug("Propagating interests of "+interested+" to "+downstream+" at endpoint "+downstreamEndpoint);
LOGGER.debug("Propagating interests of "+interested+" for"+interestURI+" to "+downstream+" at endpoint "+downstreamEndpoint);
String interestedEndpoint = Node.getInstance().getTopologyManager().getEndpoint(interested);
AnnouncerClient.annouceToDownstream(
downstreamEndpoint,
......
......@@ -252,12 +252,18 @@ public class KBManager {
return r;
}
public Model executeRules(){
public Model executeRules(Boolean activateNodeElements, Boolean deactivateNodeElements){
Model inferences = null;
this.m.enterCriticalSection(Lock.WRITE);
try {
if(activateNodeElements){
Node.getInstance().getShapesManager().activateNodeSensitiveElements();
}
inferences = RuleUtil.executeRules(this.m, this.m, null, null);
this.m.add(inferences);
if(deactivateNodeElements){
Node.getInstance().getShapesManager().deactivateNodeSensitiveElements();
}
} finally {
this.m.leaveCriticalSection();
}
......
......@@ -236,14 +236,14 @@ public class RuleManager {
// LOGGER.debug("The KB violates some constraints");
// LOGGER.debug(ModelPrinter.get().print(report.getModel()));
// }
this.triggerReasoning();
this.triggerReasoning(false, true);
// LOGGER.trace("Deactivating node-sensitive elements");
Node.getInstance().getShapesManager().deactivateNodeSensitiveElements();
// Node.getInstance().getShapesManager().deactivateNodeSensitiveElements();
}
public Model triggerReasoning(){
public Model triggerReasoning(Boolean activateNodeElements, Boolean deactivateNodeElements){
LOGGER.trace("Starting a reasoning step");
Model inference = Node.getInstance().getKBManager().executeRules();
Model inference = Node.getInstance().getKBManager().executeRules(activateNodeElements, deactivateNodeElements);
if(inference.size() > 0){
// Node.getInstance().getKBManager().addToModel(inference);
LOGGER.debug("Inferenced : " + ModelPrinter.get().print(inference));
......@@ -290,9 +290,9 @@ public class RuleManager {
LOGGER.debug("Shifting a transfer into an activation of "+ruleURI);
this.shiftTransferIntoInterest(ruleURI);
this.markRuleActivable(ruleURI);
LOGMODEL.debug(MODEL_MARKER, Node.getInstance().getKBManager().serializeModel());
Model reinference = Node.getInstance().getKBManager().executeRules();
Node.getInstance().getKBManager().addToModel(reinference);
// LOGMODEL.debug(MODEL_MARKER, Node.getInstance().getKBManager().serializeModel());
Model reinference = Node.getInstance().getKBManager().executeRules(true, true);
// Node.getInstance().getKBManager().addToModel(reinference);
LOGGER.debug("Reinference : " + ModelPrinter.get().print(reinference));
}
}
......
......@@ -216,7 +216,8 @@ public class Node {
String remoteURI = this.tm.extractNodeFromAnnounce(remoteModel);
this.tm.addDownstreamRemote(remoteURI);
Node.getInstance().getShapesManager().activateNodeSensitiveElements();
Node.getInstance().getRuleManager().triggerReasoning();
// XXX Used to be true/false
Node.getInstance().getRuleManager().triggerReasoning(true, true);
if(E_Centralization.rulePropagationAllowed(Node.getInstance().getConfiguration().getCentralization())){
this.rm.updateDownStreamNode(remoteURI);
}
......@@ -256,9 +257,9 @@ public class Node {
propertyInstance,
feature);
LOGGER.trace("Registering to remote sensor at address "+sensor.get("endpoint"));
Node.getInstance().getShapesManager().activateNodeSensitiveElements();
Node.getInstance().getRuleManager().triggerReasoning();
Node.getInstance().getShapesManager().deactivateNodeSensitiveElements();
// Node.getInstance().getShapesManager().activateNodeSensitiveElements();
Node.getInstance().getRuleManager().triggerReasoning(true, true);
// Node.getInstance().getShapesManager().deactivateNodeSensitiveElements();
}
// The subscription is done in two times in order to minimize the delay between subscriptions
for(Map<String, String> sensor : this.config.getSensors()){
......@@ -383,7 +384,7 @@ public class Node {
public void reasonOverNewData(Model data){
LOGGER.debug("Reasoning over new data...");
Tracer.reasoningStarts(this.enricher.getObservation(data));
Model inference = Node.getInstance().getRuleManager().triggerReasoning();
Model inference = Node.getInstance().getRuleManager().triggerReasoning(false, false);
if(inference != null){
LOGGER.debug("Inferred new knowledge");
Tracer.reasoningEnds(this.enricher.getObservation(data), true);
......
......@@ -3,6 +3,6 @@
for i in {1..10}
do
echo "Computing results round $i"
mkdir results_minimal_local_$i
python3 results.py --adp logs_minimal_adp_$i --cir logs_minimal_cir_$i --cip logs_minimal_cip_$i --cdp logs_minimal_cdp_$i --cdr logs_minimal_cdr_$i -o results_minimal_local_$i
# mkdir results_minimal_local_$i
python3 results.py --adp logs/logs_minimal_reproduce/iter_2/logs_minimal_adp_$i --cir logs/logs_minimal_reproduce/iter_2/logs_minimal_cir_$i --cip logs/logs_minimal_reproduce/iter_2/logs_minimal_cip_$i --cdp logs/logs_minimal_reproduce/iter_2/logs_minimal_cdp_$i --cdr logs/logs_minimal_reproduce/iter_2/logs_minimal_cdr_$i -o results/results_minimal_reproduce/iter_2/results_minimal_local_$i
done
......@@ -254,11 +254,11 @@ def get_bin_centers(bin_edges):
centers.append((bin_edges[i]+bin_edges[i+1])/2.0)
return centers
def plot_histogram_kde(ax, data, bins):
def plot_histogram_kde(name, ax, data, bins):
#n, bins, patches = ax.hist(data, density=True, bins='doane')
n, bins, patches = ax.hist(data, density=True, bins=bins)
try:
print("{0} values, from {1} to {2}".format(str(len(data)), str(min(data)), str(max(data))))
print("{0} values, from {1} to {2} - {3}".format(str(len(data)), str(min(data)), str(max(data)), name))
if len(data) > 1:
kernel = stats.gaussian_kde(data)
# possible bandwidth method : silverman
......@@ -301,17 +301,19 @@ def histogram_journeys(journeys_list, folder):
fig_handle = plt.figure(1)
plt_id = int(str(len(journeys_list))+"11")
ax0 = plt.subplot(plt_id)
for journeys in journeys_list:
subplot_id = int(str(len(journeys_list))+"1"+str(index))
ax_n = plt.subplot(subplot_id, sharex=ax0, sharey=ax0)
ded_delay = []
for journey in journeys:
if "delay" in journey and journey["delay"] > 0 and journey["delay"]<7000:
ded_delay.append(journey["delay"])
plot_histogram_kde(ax_n, ded_delay, 75)
with open(folder+"/journ_delays_"+str(journeys_list.index(journeys)), "wb") as f:
pickle.dump(ded_delay, f)
index += 1
for method, journeys in journeys_list.items():
if len(journeys) > 0:
subplot_id = int(str(len(journeys_list))+"1"+str(index))
ax_n = plt.subplot(subplot_id, sharex=ax0, sharey=ax0)
ded_delay = []
plt.title(method)
for journey in journeys:
if "delay" in journey and journey["delay"] > 0 and journey["delay"]<7000:
ded_delay.append(journey["delay"])
plot_histogram_kde(method, ax_n, ded_delay, 75)
with open(folder+"/journ_delays_"+method, "wb") as f:
pickle.dump(ded_delay, f)
index += 1
plt.xlabel('Delays')
plt.savefig(folder+"/journ_delay",format='eps', dpi=300)
with open(folder+"/"+"journey_fig.pkl", "wb") as f:
......@@ -492,18 +494,20 @@ if args.delay and (args.centralized != None or args.distributed != None):
pickle.dump(delays[1], f)
del(graphs)
if args.adp != None and args.cir != None and args.cdp != None and args.cip != None and args.cdr != None:
journeys = []
if args.adp != None or args.cir != None or args.cdp != None or args.cip != None or args.cdr != None:
journeys = {}
for method, folder in {"adp":args.adp,
"cdp":args.cdp, "cip":args.cip,
"cdr":args.cdr, "cir":args.cir}.items():
"cdp":args.cdp,
"cip":args.cip,
"cdr":args.cdr,
"cir":args.cir}.items():
print("Collecting results for "+method)
trace = prepare_trace(folder)
graph = prepare_graph(folder)
journey = compute_journeys(graph, trace)
with open(args.output+"/journeys_{0}.pkl".format(method), "wb") as f:
pickle.dump(journey, f)
journeys.append(journey)
journeys[method]=journey
delay = extract_delays_details(journey)
with open(args.output+"/delays_{0}.pkl".format(method), "wb") as f:
pickle.dump(delay, f)
......
......@@ -64,6 +64,12 @@
rdfs:subClassOf :ManufacturingEntity ;
rdfs:label "Machine"@en .
:SparkGeneratingMachine rdf:type owl:Class ;
rdfs:subClassOf :Machine .
:ColdSensitiveMachine rdf:type owl:Class ;
rdfs:subClassOf :Machine .
### https://w3id.org/laas-iot/edr/iiot/factory#ManufacturingEntity
:ManufacturingEntity rdf:type owl:Class ;
......@@ -140,8 +146,7 @@
### https://w3id.org/laas-iot/edr/iiot/factory#Machine111
:Machine111 rdf:type owl:NamedIndividual ,
:Machine ;
:Machine111 rdf:type owl:NamedIndividual , :Machine, :SparkGeneratingMachine;
:onConveyor :Conveyor11 .
......@@ -153,7 +158,7 @@
### https://w3id.org/laas-iot/edr/iiot/factory#Machine113
:Machine113 rdf:type owl:NamedIndividual ,
:Machine ;
:Machine, :SparkGeneratingMachine ;
:onConveyor :Conveyor11 .
......@@ -177,13 +182,13 @@
### https://w3id.org/laas-iot/edr/iiot/factory#Machine211
:Machine211 rdf:type owl:NamedIndividual ,
:Machine ;
:Machine, :ColdSensitiveMachine ;
:onConveyor :Conveyor21 .
### https://w3id.org/laas-iot/edr/iiot/factory#Machine212
:Machine212 rdf:type owl:NamedIndividual ,
:Machine ;
:Machine, :ColdSensitiveMachine ;
:onConveyor :Conveyor21 .
......@@ -201,13 +206,13 @@
### https://w3id.org/laas-iot/edr/iiot/factory#Machine231
:Machine231 rdf:type owl:NamedIndividual ,
:Machine ;
:Machine, :ColdSensitiveMachine ;
:onConveyor :Conveyor23 .
### https://w3id.org/laas-iot/edr/iiot/factory#Machine232
:Machine232 rdf:type owl:NamedIndividual ,
:Machine ;
:Machine, :ColdSensitiveMachine ;
:onConveyor :Conveyor23 .
......
......@@ -16,6 +16,11 @@
"host": "http://localhost",
"count":1,
"measures":"presence"
}, {
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"supervisor_presence"
}, {
"type":"sensor",
"host": "http://localhost",
......@@ -30,7 +35,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"conveyorState"
"measures":"conveyor_state"
}, {
"type":"sensor",
"host": "http://localhost",
......@@ -45,7 +50,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"machineState"
"measures":"machine_state"
}]
}, {
"type": "room",
......@@ -56,7 +61,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"machineState"
"measures":"machine_state"
}]
}, {
"type": "room",
......@@ -67,7 +72,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"machineState"
"measures":"machine_state"
}]
}]
}, {
......@@ -79,7 +84,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"conveyorState"
"measures":"conveyor_state"
}, {
"type":"sensor",
"host": "http://localhost",
......@@ -94,7 +99,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"machineState"
"measures":"machine_state"
}]
}, {
"type": "room",
......@@ -105,7 +110,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"machineState"
"measures":"machine_state"
}]
}, {
"type": "room",
......@@ -116,7 +121,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"machineState"
"measures":"machine_state"
}]
}]
}]
......
......@@ -2,7 +2,7 @@
"type":"factory",
"floors":[{
"type":"floor",
"sensors":["presence", "luminosity", "particles", "temperature"],
"sensors":["presence", "luminosity", "particle_level", "temperature"],
"count":1,
"conveyors":[{
"type":"conveyor",
......
{
"name": "simple-building",
"centralized": "adp",
"common_knowledge":["https://w3id.org/laas-iot/edr/simu/minimal_local.ttl"],
"common_knowledge":[],
"layers": {
"type": "building",
"count": 1,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment