コード例 #1
0
class scheduler_deterministic:

    _PID = BSet(PID.process1, PID.process2, PID.process3)

    def __init__(self):
        self.active = BSet()
        self._ready = BSet()
        self.waiting = BSet()

    def new(self, pp):
        if ((BBoolean(
                BBoolean(
                    self._PID.elementOf(pp).booleanValue() and self.active.
                    notElementOf(pp).booleanValue()).booleanValue()
                and self._ready.union(
                    self.waiting).notElementOf(pp).booleanValue())
             ).booleanValue()):
            self.waiting = self.waiting.union(BSet(pp))

    def _del(self, pp):
        if ((self.waiting.elementOf(pp)).booleanValue()):
            self.waiting = self.waiting.difference(BSet(pp))

    def ready(self, rr):
        if ((self.waiting.elementOf(rr)).booleanValue()):
            self.waiting = self.waiting.difference(BSet(rr))
            if self.active.equal(BSet()):
                self.active = BSet(rr)
            else:
                self._ready = self._ready.union(BSet(rr))

    def swap(self, pp):
        if self.active.unequal(BSet()):
            self.waiting = self.waiting.union(self.active)
            if self._ready.equal(BSet()):
                self.active = BSet()
            else:
                self.active = BSet(pp)
                self._ready = self._ready.difference(BSet(pp))

    def _get_active(self):
        return self.active

    def _get__ready(self):
        return self._ready

    def _get_waiting(self):
        return self.waiting
コード例 #2
0
ファイル: Sieve.py プロジェクト: favu100/b2program
    def ComputeNumberOfPrimes(self):
        while (BBoolean(
                self.cur.greater(BInteger(1)).booleanValue()
                and self.cur.multiply(self.cur).lessEqual(
                    self.limit).booleanValue())).booleanValue():
            if (self.numbers.elementOf(self.cur)).booleanValue():
                n = self.cur
                set = BSet()
                while (n.lessEqual(self.limit.divide(
                        self.cur))).booleanValue():
                    set = set.union(BSet(self.cur.multiply(n)))
                    n = n.plus(BInteger(1))

                self.numbers = self.numbers.difference(set)

            self.cur = self.cur.plus(BInteger(1))

        res = self.numbers.card()
        return res
コード例 #3
0
class Train_1_beebook_deterministic:



    _BLOCKS = BSet(BLOCKS.A, BLOCKS.B, BLOCKS.C, BLOCKS.D, BLOCKS.E, BLOCKS.F, BLOCKS.G, BLOCKS.H, BLOCKS.I, BLOCKS.J, BLOCKS.K, BLOCKS.L, BLOCKS.M, BLOCKS.N)
    _ROUTES = BSet(ROUTES.R1, ROUTES.R2, ROUTES.R3, ROUTES.R4, ROUTES.R5, ROUTES.R6, ROUTES.R7, ROUTES.R8, ROUTES.R9, ROUTES.R10)

    def __init__(self):
        self.fst = BRelation(BTuple(ROUTES.R1, BLOCKS.L), BTuple(ROUTES.R2, BLOCKS.L), BTuple(ROUTES.R3, BLOCKS.L), BTuple(ROUTES.R4, BLOCKS.M), BTuple(ROUTES.R5, BLOCKS.M), BTuple(ROUTES.R6, BLOCKS.C), BTuple(ROUTES.R7, BLOCKS.G), BTuple(ROUTES.R8, BLOCKS.N), BTuple(ROUTES.R9, BLOCKS.G), BTuple(ROUTES.R10, BLOCKS.N))
        self.lst = BRelation(BTuple(ROUTES.R1, BLOCKS.C), BTuple(ROUTES.R2, BLOCKS.G), BTuple(ROUTES.R3, BLOCKS.N), BTuple(ROUTES.R4, BLOCKS.G), BTuple(ROUTES.R5, BLOCKS.N), BTuple(ROUTES.R6, BLOCKS.L), BTuple(ROUTES.R7, BLOCKS.L), BTuple(ROUTES.R8, BLOCKS.L), BTuple(ROUTES.R9, BLOCKS.M), BTuple(ROUTES.R10, BLOCKS.M))
        self.nxt = BRelation(BTuple(ROUTES.R1, BRelation(BTuple(BLOCKS.L, BLOCKS.A), BTuple(BLOCKS.A, BLOCKS.B), BTuple(BLOCKS.B, BLOCKS.C))), BTuple(ROUTES.R2, BRelation(BTuple(BLOCKS.L, BLOCKS.A), BTuple(BLOCKS.A, BLOCKS.B), BTuple(BLOCKS.B, BLOCKS.D), BTuple(BLOCKS.D, BLOCKS.E), BTuple(BLOCKS.E, BLOCKS.F), BTuple(BLOCKS.F, BLOCKS.G))), BTuple(ROUTES.R3, BRelation(BTuple(BLOCKS.L, BLOCKS.A), BTuple(BLOCKS.A, BLOCKS.B), BTuple(BLOCKS.B, BLOCKS.D), BTuple(BLOCKS.D, BLOCKS.K), BTuple(BLOCKS.K, BLOCKS.J), BTuple(BLOCKS.J, BLOCKS.N))), BTuple(ROUTES.R4, BRelation(BTuple(BLOCKS.M, BLOCKS.H), BTuple(BLOCKS.H, BLOCKS.I), BTuple(BLOCKS.I, BLOCKS.K), BTuple(BLOCKS.K, BLOCKS.F), BTuple(BLOCKS.F, BLOCKS.G))), BTuple(ROUTES.R5, BRelation(BTuple(BLOCKS.M, BLOCKS.H), BTuple(BLOCKS.H, BLOCKS.I), BTuple(BLOCKS.I, BLOCKS.J), BTuple(BLOCKS.J, BLOCKS.N))), BTuple(ROUTES.R6, BRelation(BTuple(BLOCKS.C, BLOCKS.B), BTuple(BLOCKS.B, BLOCKS.A), BTuple(BLOCKS.A, BLOCKS.L))), BTuple(ROUTES.R7, BRelation(BTuple(BLOCKS.G, BLOCKS.F), BTuple(BLOCKS.F, BLOCKS.E), BTuple(BLOCKS.E, BLOCKS.D), BTuple(BLOCKS.D, BLOCKS.B), BTuple(BLOCKS.B, BLOCKS.A), BTuple(BLOCKS.A, BLOCKS.L))), BTuple(ROUTES.R8, BRelation(BTuple(BLOCKS.N, BLOCKS.J), BTuple(BLOCKS.J, BLOCKS.K), BTuple(BLOCKS.K, BLOCKS.D), BTuple(BLOCKS.D, BLOCKS.B), BTuple(BLOCKS.B, BLOCKS.A), BTuple(BLOCKS.A, BLOCKS.L))), BTuple(ROUTES.R9, BRelation(BTuple(BLOCKS.G, BLOCKS.F), BTuple(BLOCKS.F, BLOCKS.K), BTuple(BLOCKS.K, BLOCKS.I), BTuple(BLOCKS.I, BLOCKS.H), BTuple(BLOCKS.H, BLOCKS.M))), BTuple(ROUTES.R10, BRelation(BTuple(BLOCKS.N, BLOCKS.J), BTuple(BLOCKS.J, BLOCKS.I), BTuple(BLOCKS.I, BLOCKS.H), BTuple(BLOCKS.H, BLOCKS.M))))
        self._ic_set_0 = BRelation()
        for _ic_b_1 in self._BLOCKS:
            for _ic_r_1 in Train_1_beebook_deterministic._ROUTES:
                if(BBoolean(self.nxt.domain().elementOf(_ic_r_1).booleanValue() and BBoolean(self.nxt.functionCall(_ic_r_1).domain().elementOf(_ic_b_1).booleanValue() or self.nxt.functionCall(_ic_r_1)._range().elementOf(_ic_b_1).booleanValue()).booleanValue())).booleanValue():
                    _ic_set_0 = self._ic_set_0.union(BRelation(BTuple(_ic_b_1, _ic_r_1)))

        self.rtbl = self._ic_set_0
        self.resrt = BSet()
        self.resbl = BSet()
        self.rsrtbl = BRelation()
        self.OCC = BSet()
        self.TRK = BRelation()
        self.frm = BSet()
        self.LBT = BSet()

    def route_reservation(self, r):
        _ld_resrt = self.resrt

        _ld_rsrtbl = self.rsrtbl
        _ld_resbl = self.resbl
        self.resrt = _ld_resrt.union(BSet(r))
        self.rsrtbl = _ld_rsrtbl.union(self.rtbl.rangeRestriction(BSet(r)))
        self.resbl = _ld_resbl.union(self.rtbl.inverse().relationImage(BSet(r)))

    def route_freeing(self, r):
        _ld_resrt = self.resrt

        _ld_frm = self.frm
        self.resrt = _ld_resrt.difference(BSet(r))
        self.frm = _ld_frm.difference(BSet(r))

    def FRONT_MOVE_1(self, r):
        _ld_OCC = self.OCC
        _ld_LBT = self.LBT
        self.OCC = _ld_OCC.union(BSet(self.fst.functionCall(r)))
        self.LBT = _ld_LBT.union(BSet(self.fst.functionCall(r)))

    def FRONT_MOVE_2(self, b):
        self.OCC = self.OCC.union(BSet(self.TRK.functionCall(b)))

    def BACK_MOVE_1(self, b):
        _ld_OCC = self.OCC
        _ld_LBT = self.LBT
        _ld_rsrtbl = self.rsrtbl
        _ld_resbl = self.resbl
        self.OCC = _ld_OCC.difference(BSet(b))
        self.rsrtbl = _ld_rsrtbl.domainSubstraction(BSet(b))
        self.resbl = _ld_resbl.difference(BSet(b))
        self.LBT = _ld_LBT.difference(BSet(b))

    def BACK_MOVE_2(self, b):
        _ld_OCC = self.OCC
        _ld_LBT = self.LBT
        _ld_rsrtbl = self.rsrtbl
        _ld_resbl = self.resbl
        self.OCC = _ld_OCC.difference(BSet(b))
        self.rsrtbl = _ld_rsrtbl.domainSubstraction(BSet(b))
        self.resbl = _ld_resbl.difference(BSet(b))
        self.LBT = _ld_LBT.difference(BSet(b)).union(BSet(self.TRK.functionCall(b)))

    def point_positionning(self, r):
        self.TRK = self.TRK.domainSubstraction(self.nxt.functionCall(r).domain()).rangeSubstraction(self.nxt.functionCall(r)._range()).union(self.nxt.functionCall(r))

    def route_formation(self, r):
        self.frm = self.frm.union(BSet(r))


    def _get_LBT(self):
        return self.LBT

    def _get_TRK(self):
        return self.TRK

    def _get_frm(self):
        return self.frm

    def _get_OCC(self):
        return self.OCC

    def _get_resbl(self):
        return self.resbl

    def _get_resrt(self):
        return self.resrt

    def _get_rsrtbl(self):
        return self.rsrtbl