Commit 96cb29ed authored by Tobias Meuser's avatar Tobias Meuser
Browse files

SiS adjustments to provide timestamp, included prediction

parent dadc1313
......@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sis;
import java.util.Map;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
......@@ -112,6 +113,11 @@ public interface SiSInformationConsumer {
public <T> T localObservationOf(INodeID observedNode, SiSType<T> type,
SiSRequest request) throws InformationNotAvailableException;
public <T> SiSInfoProperties localObservationOfInfo(INodeID pObservedNode, SiSType<T> pType, SiSRequest pRequest)
throws InformationNotAvailableException;
public <T> Set<INodeID> getObservedNodes(SiSType<T> pType, SiSRequest pRequest);
/**
* Returns an observation made by the observer node of the state of the
* observed node, iff the information is available locally (as part of the
......@@ -213,4 +219,5 @@ public interface SiSInformationConsumer {
// marker
}
}
......@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sis;
import java.util.Map;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationConsumer.AggregationFunction;
......@@ -53,6 +54,30 @@ public interface SiSInformationResolver {
public <T> T resolveLocally(INodeID observedNode, SiSType<T> type,
SiSRequest request) throws InformationNotAvailableException;
/**
* Returns the update info properties of the local state, if the given
* request can be resolved locally (either by accessing the local storage
* for past values, or by querying one of the registered information
* providers).
*
* @param observedNode
* can be null, meaning we want to know sth. about our own local
* node.
* @param request
* the requests object contains QoS parameters related to the
* request (e.g., desired granularity, max timeout)
* @return info properties
*/
public <T> SiSInfoProperties resolveLocallyInfo(INodeID pObservedNode, SiSType<T> pType, SiSRequest pRequest)
throws InformationNotAvailableException;
/**
* @param pType
* @param pRequest
* @return
*/
<T> Set<INodeID> getObservedNodes(SiSType<T> pType, SiSRequest pRequest);
/**
* Returns a map of all currently available local observations of the given
* type.
......
......@@ -60,4 +60,14 @@ public interface SiSLocalData {
public <T> Set<INodeID> getObservedNodes(SiSType<T> type,
SiSRequest request);
/**
* @param pNodeId
* @param pType
* @param pRequest
* @return
* @throws InformationNotAvailableException
*/
<T> SiSInfoProperties getValueInfo(INodeID pNodeId, SiSType<T> pType, SiSRequest pRequest)
throws InformationNotAvailableException;
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.impl.NoRoadSegmentPrediction;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionSiSType;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 03.01.2018
*
*/
public class DefaultSiSPredictionManager implements SiSPredictionManager {
private Map<SiSType<? extends Object>, Prediction<? extends Object>> availablePredictions = new HashMap<>();
private Host host;
private SiSComponent _siSComponent;
public DefaultSiSPredictionManager(Host host) {
this.host = host;
Prediction<? extends Object> prediction = new NoRoadSegmentPrediction();
availablePredictions.put(prediction.getBasicSiSType(), prediction);
}
@Override
public void initialize() {
try {
_siSComponent = getHost().getComponent(SiSComponent.class);
for (Entry<SiSType<? extends Object>, Prediction<? extends Object>> entry : availablePredictions
.entrySet()) {
PredictionSiSType<? extends Object> predictionSysType = entry.getKey().getPredictionSysType();
if (predictionSysType != null) {
_siSComponent.provide().nodeState(predictionSysType,
new PredictionSiSDataCallback<>(predictionSysType));
}
}
} catch (ComponentNotAvailableException e) {
}
}
@Override
public void shutdown() {
}
@Override
public Host getHost() {
return host;
}
@Override
public <T> PredictionContainer<T> predict(INodeID pNodeID, PredictionSiSType<T> pType, T pValue, long pTime)
throws InformationNotAvailableException {
if (availablePredictions.containsKey(pType.getOriginalSiSType())) {
Prediction prediction = availablePredictions.get(pType.getOriginalSiSType());
return prediction.predict(pNodeID, pValue, pTime);
}
throw new InformationNotAvailableException();
}
@SuppressWarnings("rawtypes")
private class PredictionSiSDataCallback<T extends Object> implements SiSDataCallback<PredictionContainer> {
private PredictionSiSType<T> _sisType;
public PredictionSiSDataCallback(PredictionSiSType<T> sisType) {
_sisType = sisType;
}
@Override
public PredictionContainer<T> getValue(INodeID pNodeID, SiSProviderHandle pProviderHandle)
throws InformationNotAvailableException {
T observation = _siSComponent.get().localObservationOf(pNodeID, _sisType.getOriginalSiSType(),
SiSRequest.NONE);
long timestamp = _siSComponent.get()
.localObservationOfInfo(pNodeID, _sisType.getOriginalSiSType(), SiSRequest.NONE)
.getLastUpdateTimestamp();
return predict(pNodeID, _sisType, observation, timestamp);
}
@Override
public Set<INodeID> getObservedNodes() {
return _siSComponent.get().getObservedNodes(_sisType.getOriginalSiSType(), SiSRequest.NONE);
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 05.01.2018
*
*/
public interface Prediction<T extends Object> {
/**
* @param pNodeID
* @param pObservation
* @param pTimestamp
* @return
*/
PredictionContainer<T> predict(INodeID pNodeID, T pObservation, long pTimestamp);
SiSType<T> getBasicSiSType();
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionSiSType;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 03.01.2018
*
*/
public interface SiSPredictionManager extends HostComponent {
static String getPredictionName(String originalName) {
return originalName + "_PREDICTED";
}
/**
* @param pNodeID
* @param pType
* @param pValue
* @param pTime
* @return
* @throws InformationNotAvailableException
*/
<T extends Object> PredictionContainer<T> predict(INodeID pNodeID, PredictionSiSType<T> pType, T pValue, long pTime)
throws InformationNotAvailableException;
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.impl;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.Prediction;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.ListBasedPredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 08.01.2018
*
*/
public class NoRoadSegmentPrediction implements Prediction<RoadNetworkEdge> {
@Override
public PredictionContainer<RoadNetworkEdge> predict(INodeID pNodeID, RoadNetworkEdge pObservation,
long pTimestamp) {
return new ListBasedPredictionContainer<>(pObservation);
}
@Override
public SiSType<RoadNetworkEdge> getBasicSiSType() {
return SiSTypes.ROAD_EDGE;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.type;
import java.util.ArrayList;
import java.util.List;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 03.01.2018
*
*/
public class ListBasedPredictionContainer<T extends Object> implements PredictionContainer<T> {
private List<T> values = new ArrayList<>();
public ListBasedPredictionContainer(T[] values) {
for (T t : values) {
this.values.add(t);
}
}
public ListBasedPredictionContainer(T value) {
this.values.add(value);
}
public ListBasedPredictionContainer(List<T> values) {
this.values = values;
}
public List<T> getValues() {
return values;
}
@Override
public double getProbabilityForValue(T pValue) {
if (values.contains(pValue)) {
return 1 / (double) values.size();
}
return 0;
}
@Override
public double isInsidePrediction(T pValue) {
if (values.contains(pValue)) {
return 1;
}
return 0;
}
@Override
public T getMostProbableValue() {
return values.get(0);
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.type;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 03.01.2018
*
*/
public interface PredictionContainer<T extends Object> {
double getProbabilityForValue(T value);
double isInsidePrediction(T value);
T getMostProbableValue();
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis.type;
import de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.SiSPredictionManager;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 03.01.2018
*
*/
@SuppressWarnings("rawtypes")
public class PredictionSiSType<S extends Object> extends SiSType<PredictionContainer> {
private SiSType<S> originalSiSType;
protected PredictionSiSType(SiSType<S> originalSysType) {
super(SiSPredictionManager.getPredictionName(originalSysType.getName()), PredictionContainer.class, null, true);
this.originalSiSType = originalSysType;
}
/**
* @return the originalSiSType
*/
public SiSType<S> getOriginalSiSType() {
return originalSiSType;
}
}
......@@ -45,6 +45,8 @@ public class SiSType<T extends Object> {
private final String name;
private final PredictionSiSType<T> predictionSysType;
/**
* Singletons!
*
......@@ -52,11 +54,21 @@ public class SiSType<T extends Object> {
* @param derivation
*/
protected SiSType(String name, Class<T> dataType,
SiSTypeAggregation<T> aggregationFunction) {
SiSTypeAggregation<T> aggregationFunction, boolean predicted) {
this.name = name;
this.dataType = dataType;
this.derivations = new LinkedHashSet<>();
this.aggregationFunction = aggregationFunction;
if (!predicted) {
this.predictionSysType = new PredictionSiSType<>(this);
} else {
this.predictionSysType = null;
}
}
protected SiSType(String name, Class<T> dataType, SiSTypeAggregation<T> aggregationFunction) {
this(name, dataType, aggregationFunction, false);
}
/**
......@@ -70,6 +82,13 @@ public class SiSType<T extends Object> {
derivations.add(derivation);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* Data type. If this is a collection, this method returns the inner type of
* the collection.
......@@ -80,6 +99,20 @@ public class SiSType<T extends Object> {
return dataType;
}
/**
* @return the aggregationFunction
*/
public SiSTypeAggregation<T> getAggregationFunction() {
return aggregationFunction;
}
/**
* @return the predictionSysType
*/
public PredictionSiSType<T> getPredictionSysType() {
return predictionSysType;
}
/**
* Determines the "best" derivation for the given available types and
* returns it (or null, if no matching derivation is found...)
......
Markdown is supported
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