def part2convex(ppp): """This function takes a proposition preserving partition and generates another proposition preserving partition such that each part in the new partition is a convex polytope @type ppp: L{PropPreservingPartition} @return: refinement into convex polytopes and map from new to old Regions @rtype: (L{PropPreservingPartition}, list) """ cvxpart = PropPreservingPartition(domain=copy.deepcopy(ppp.domain), prop_regions=copy.deepcopy( ppp.prop_regions)) new2old = [] for i in xrange(len(ppp.regions)): simplified_reg = pc.union(ppp.regions[i], ppp.regions[i], check_convex=True) for j in xrange(len(simplified_reg)): region_now = pc.Region([simplified_reg[j]], ppp.regions[i].props) cvxpart.regions.append(region_now) new2old += [i] cvxpart.adj = pc.find_adjacent_regions(cvxpart).copy() return (cvxpart, new2old)
def part2convex(ppp): """This function takes a proposition preserving partition and generates another proposition preserving partition such that each part in the new partition is a convex polytope @type ppp: L{PropPreservingPartition} @return: refinement into convex polytopes and map from new to old Regions @rtype: (L{PropPreservingPartition}, list) """ cvxpart = PropPreservingPartition( domain=copy.deepcopy(ppp.domain), prop_regions=copy.deepcopy(ppp.prop_regions) ) new2old = [] for i in xrange(len(ppp.regions)): simplified_reg = pc.union(ppp.regions[i], ppp.regions[i], check_convex=True) for j in xrange(len(simplified_reg)): region_now = pc.Region( [simplified_reg[j]], ppp.regions[i].props ) cvxpart.regions.append(region_now) new2old += [i] cvxpart.adj = pc.find_adjacent_regions(cvxpart).copy() return (cvxpart, new2old)
def prop2part(state_space, cont_props_dict): """Main function that takes a domain (state_space) and a list of propositions (cont_props), and returns a proposition preserving partition of the state space. See Also ======== L{PropPreservingPartition}, C{polytope.Polytope} @param state_space: problem domain @type state_space: C{polytope.Polytope} @param cont_props_dict: propositions @type cont_props_dict: dict of C{polytope.Polytope} @return: state space quotient partition induced by propositions @rtype: L{PropPreservingPartition} """ first_poly = [] #Initial Region's polytopes first_poly.append(state_space) regions = [pc.Region(first_poly)] for cur_prop in cont_props_dict: cur_prop_poly = cont_props_dict[cur_prop] num_reg = len(regions) prop_holds_reg = [] for i in xrange(num_reg): #i region counter region_now = regions[i].copy() #loop for prop holds prop_holds_reg.append(0) prop_now = regions[i].props.copy() dummy = region_now.intersect(cur_prop_poly) # does cur_prop hold in dummy ? if pc.is_fulldim(dummy): dum_prop = prop_now.copy() dum_prop.add(cur_prop) # is dummy a Polytope ? if len(dummy) == 0: regions[i] = pc.Region([dummy], dum_prop) else: # dummy is a Region dummy.props = dum_prop.copy() regions[i] = dummy.copy() prop_holds_reg[-1] = 1 else: #does not hold in the whole region # (-> no need for the 2nd loop) regions.append(region_now) continue #loop for prop does not hold regions.append(pc.Region([], props=prop_now)) dummy = region_now.diff(cur_prop_poly) if pc.is_fulldim(dummy): dum_prop = prop_now.copy() # is dummy a Polytope ? if len(dummy) == 0: regions[-1] = pc.Region([pc.reduce(dummy)], dum_prop) else: # dummy is a Region dummy.props = dum_prop.copy() regions[-1] = dummy.copy() else: regions.pop() count = 0 for hold_count in xrange(len(prop_holds_reg)): if prop_holds_reg[hold_count] == 0: regions.pop(hold_count - count) count += 1 mypartition = PropPreservingPartition( domain=copy.deepcopy(state_space), regions=regions, prop_regions=copy.deepcopy(cont_props_dict)) mypartition.adj = pc.find_adjacent_regions(mypartition).copy() return mypartition
def prop2part(state_space, cont_props_dict): """Main function that takes a domain (state_space) and a list of propositions (cont_props), and returns a proposition preserving partition of the state space. See Also ======== L{PropPreservingPartition}, C{polytope.Polytope} @param state_space: problem domain @type state_space: C{polytope.Polytope} @param cont_props_dict: propositions @type cont_props_dict: dict of C{polytope.Polytope} @return: state space quotient partition induced by propositions @rtype: L{PropPreservingPartition} """ first_poly = [] #Initial Region's polytopes first_poly.append(state_space) regions = [pc.Region(first_poly)] for cur_prop in cont_props_dict: cur_prop_poly = cont_props_dict[cur_prop] num_reg = len(regions) prop_holds_reg = [] for i in xrange(num_reg): #i region counter region_now = regions[i].copy() #loop for prop holds prop_holds_reg.append(0) prop_now = regions[i].props.copy() dummy = region_now.intersect(cur_prop_poly) # does cur_prop hold in dummy ? if pc.is_fulldim(dummy): dum_prop = prop_now.copy() dum_prop.add(cur_prop) # is dummy a Polytope ? if len(dummy) == 0: regions[i] = pc.Region([dummy], dum_prop) else: # dummy is a Region dummy.props = dum_prop.copy() regions[i] = dummy.copy() prop_holds_reg[-1] = 1 else: #does not hold in the whole region # (-> no need for the 2nd loop) regions.append(region_now) continue #loop for prop does not hold regions.append(pc.Region([], props=prop_now) ) dummy = region_now.diff(cur_prop_poly) if pc.is_fulldim(dummy): dum_prop = prop_now.copy() # is dummy a Polytope ? if len(dummy) == 0: regions[-1] = pc.Region([pc.reduce(dummy)], dum_prop) else: # dummy is a Region dummy.props = dum_prop.copy() regions[-1] = dummy.copy() else: regions.pop() count = 0 for hold_count in xrange(len(prop_holds_reg)): if prop_holds_reg[hold_count]==0: regions.pop(hold_count-count) count+=1 mypartition = PropPreservingPartition( domain = copy.deepcopy(state_space), regions = regions, prop_regions = copy.deepcopy(cont_props_dict) ) mypartition.adj = pc.find_adjacent_regions(mypartition).copy() return mypartition