Esempio n. 1
0
    def test_intersect(self):
        anInt = Intervals()
        anInt.add_interval((5, 10))
        anInt.add_interval((12, 20))
        anInt.add_interval((50, 100))

        another = Intervals()
        another.add_interval((3, 105))

        test1 = another.intersection(anInt)
        test2 = anInt.intersection(another)
        self.assertEqual(test1, test2)
        self.assertEqual(test1, anInt)

        another = Intervals()
        another.add_interval((3, 18))

        test1 = another.intersection(anInt)

        self.assertEqual(test1.periods(), [(5, 10), (12, 18)])

        another = Intervals()
        another.add_interval((19, 55))
        test1 = anInt.intersection(another)

        self.assertEqual(test1.periods(), [(19, 20), (50, 55)])
Esempio n. 2
0
    def slice(self, start, end):
        """
        Keep only the selected period

        :param start: time of the beginning of the slice
        :param end: time of the end of the slice
        """

        to_return = tn.DynGraphIG()
        slice_time = Intervals((start, end))
        for n, presence in self.node_presence().items():
            to_return.add_node_presence(n, slice_time.intersection(presence))
        for e, presence in self.interactions().items():
            to_return.add_interaction(e[0], e[1],
                                      slice_time.intersection(presence))

        return to_return
Esempio n. 3
0
    def slice(self, start, end):
        """
        Keep only the selected period

        :param start: time of the beginning of the slice (inclusive)
        :param end: time of the end of the slice (exclusive)
        """

        to_return = tn.DynGraphLS()
        slice_time = Intervals((start, end))
        for n, presence in self.node_presence().items():
            duration = slice_time.intersection(presence)
            if duration.duration() > 0:
                to_return.add_node_presence(n, duration)

        for e, presence in self.interactions_intervals().items():
            to_return.add_interaction(e[0], e[1], presence.islice(start, end))
            to_return.add_interaction(e[0], e[1],
                                      slice_time.intersection(presence))

        return to_return
Esempio n. 4
0
    def slice(self,start,end):
        """
        Keep only the selected period

        :param start: time of the beginning of the slice
        :param end: time of the end of the slice
        """


        to_return = tn.DynGraphIG()
        slice_time = Intervals((start,end))
        for n,presence in self.node_presence().items():
            duration = slice_time.intersection(presence)
            if duration.duration()>0:
                to_return.add_node_presence(n,duration)

        for e,presence in self.interactions_intervals().items():
            el = list(e)
            duration = slice_time.intersection(presence)
            if duration.duration()>0:
                to_return.add_interaction(el[0],el[1],duration)

        return to_return