All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.io.github.moonlightsuite.moonlight.online.signal.MultiOnlineSpaceTimeSignal Maven / Gradle / Ivy

Go to download

MoonLight is a light-weight Java-tool for monitoring temporal, spatial and spatio-temporal properties of distributed complex systems, such as Cyber-Physical Systems and Collective Adaptive Systems.

The newest version!
package io.github.moonlightsuite.moonlight.online.signal;

import io.github.moonlightsuite.moonlight.core.base.Box;
import io.github.moonlightsuite.moonlight.core.signal.TimeSignal;
import io.github.moonlightsuite.moonlight.online.algorithms.Signals;
import io.github.moonlightsuite.moonlight.core.signal.SignalDomain;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class MultiOnlineSpaceTimeSignal
        implements TimeSignal>>>
{
    private final TimeChain>>> segments;
    private final int size;


    public MultiOnlineSpaceTimeSignal(int locations,
                              SignalDomain>> domain)
    {
        List>> any =
                IntStream.range(0, locations).boxed()
                         .map(i -> domain.any())
                         .collect(Collectors.toList());

        segments = new TimeChain<>(new TimeSegment<>(0.0, any), Double.POSITIVE_INFINITY);

        size = locations;
    }

    /**
     * Performs an update of the internal representation of the signal,
     * given the data available in the update.
     *
     * @param u the new data available from new knowledge
     * @return true if the refinement actually updates the signal.
     * false otherwise
     */
    @Override
    public boolean refine(Update>>> u) {
        return Signals.refine(segments, u,
                (v, vNew) -> IntStream.range(0, size)
                                      .filter(i -> containment(v.get(i),
                                                               vNew.get(i)))
                                      .count() != 0
                );
    }

    @Override
    public boolean refine(
            TimeChain>>> updates)
    {
        return Signals.refineChain(segments, updates,
                (v, vNew) -> IntStream.range(0, size)   //.parallel()
                                      .filter(i -> containment(v.get(i),
                                                               vNew.get(i)))
                                      .count() != 0
                );
    }

    private static boolean containment(List> v,
                                       List> vNew)
    {
        return  IntStream.range(0, v.size())
                         .filter(i -> !v.get(i).contains(vNew.get(i)))
                         .count() != 0;
    }

    /**
     * Temporal projection operation that selects a sub-part of the signal
     * delimited by the time instants provided by the input parameters.
     *
     * @param start beginning of the time frame of interest
     * @param end   ending of the time frame of interest
     * @return the chain of segments of the signal delimited by the input
     */
    @Override
    public TimeChain>>> select(
            Double start, Double end)
    {
        throw new UnsupportedOperationException("Not allowed for SpaceTime" +
                                                " Signals");
    }

    /**
     * Returns the internal chain of segments.
     *
     * @return the total chain of segments of the signal
     * @throws UnsupportedOperationException when not allowed by implementors
     */
    @Override
    public TimeChain>>> getSegments() {
        return segments;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy