def get_png_data_poset(library, name, x, data_format):
    if isinstance(x, FinitePoset):
        import mcdp_report.my_gvgen as gvgen
        direction = 'TB'
        assert direction in ['LR', 'TB']
        gg = gvgen.GvGen(options="rankdir=%s" % direction)
        
        e2n = {}
        for e in x.elements:
            n = gg.newItem(e)
            e2n[e] = n
            gg.propertyAppend(n, "shape", "none")
        
        
        for e1, e2 in x.relations:
            # check if e2 is minimal
            all_up = set(_ for _ in x.elements if x.leq(e1, _) and not x.leq(_, e1))
            
            minimals = poset_minima(all_up, x.leq)
            
            if not e2 in minimals:
                continue
            
            low = e2n[e1]
            high = e2n[e2]
            l = gg.newLink(high, low )
            gg.propertyAppend(l, "arrowhead", "none")
            gg.propertyAppend(l, "arrowtail", "none")
            
        data, = gg_get_formats(gg, (data_format,))
        return data
    else:
        s = str(x)
        return create_image_with_string(s, size=(512, 512), color=(128, 128, 128))
示例#2
0
    def plot(self, pylab, axis, space, value, params={}):
        params0 = dict(color_shadow=[1.0, 0.8, 0.8],
                       markers='k.',
                       markers_params={})
        params0.update(params)

        color_shadow = params0.pop('color_shadow')
        markers = params0.pop('markers')
        markers_params = params0.pop('markers_params')
        if params0:
            msg = 'Extra parameters given.'
            raise_desc(ValueError, msg, params0=params0)

        self.axis = axis
        self.check_plot_space(space)

        #         tu = get_types_universe()
        #         P_TO_S, _ = tu.get_embedding(space.P, self.R2)

        minimals = [
            self._get_screen_coords(self.P_to_S(_), axis)
            for _ in value.minimals
        ]

        minimals = poset_minima(minimals, self.R2.leq)
        v = self.R2.Us(minimals)

        from mcdp_report.generic_report_utils import extra_space_finite
        plot_upset_R2(pylab,
                      v,
                      axis,
                      extra_space_shadow=extra_space_finite,
                      color_shadow=color_shadow,
                      markers=markers,
                      marker_params=markers_params)
示例#3
0
def get_hasse(fp):
    """ yiels (a, b) in hasse diagram) """
    check_isinstance(fp, FinitePoset)
    for e1, e2 in fp.relations:
        # check if e2 is minimal
        all_up = set(_ for _ in fp.elements
                     if fp.leq(e1, _) and not fp.leq(_, e1))

        minimals = poset_minima(all_up, fp.leq)

        if e2 in minimals:
            yield e1, e2
示例#4
0
 def join(self, a, b):
     from mcdp_posets.find_poset_minima.baseline_n2 import poset_minima
     # find all descendants
     da = self._get_upper_closure(a)
     db = self._get_upper_closure(b)
     # take intersection
     inter = set(da) & set(db)
     if not inter:
         msg = 'There exists no join because upper closures separate.'
         raise_desc(NotJoinable, msg, a=self.format(a), b=self.format(b),
                    da=da, db=db)
     minima = poset_minima(inter, self.leq)
     if len(minima) > 1:
         msg = 'There exists no least element of intersection of upper closure.'
         raise_desc(NotJoinable, msg)
     return list(minima)[0]
示例#5
0
    def join(self, a, b):
        from mcdp_posets.find_poset_minima.baseline_n2 import poset_minima

        # find all descendants
        da = self._get_upper_closure(a)
        db = self._get_upper_closure(b)
        # take intersection
        inter = set(da) & set(db)
        if not inter:
            msg = 'There exists no join because upper closures separate.'
            raise_desc(NotJoinable, msg, a=self.format(a), b=self.format(b),
                       da=da, db=db)
        minima = poset_minima(inter, self.leq)
        if len(minima) > 1:
            msg = 'There exists no least element of intersection of upper closure.'
            raise_desc(NotJoinable, msg)
        return list(minima)[0]
示例#6
0
文件: finite_poset.py 项目: rusi/mcdp
 def get_maximal_elements(self):
     geq = lambda a, b: self.leq(b, a)
     from mcdp_posets.find_poset_minima.baseline_n2 import poset_minima
     maxima = poset_minima(self.elements, geq)
     return maxima
示例#7
0
文件: finite_poset.py 项目: rusi/mcdp
 def get_minimal_elements(self):
     from mcdp_posets.find_poset_minima.baseline_n2 import poset_minima
     minima = poset_minima(self.elements, self.leq)
     return minima
示例#8
0
 def get_maximal_elements(self):
     geq = lambda a, b: self.leq(b, a)
     from mcdp_posets.find_poset_minima.baseline_n2 import poset_minima
     maxima = poset_minima(self.elements, geq)
     return maxima
示例#9
0
 def get_minimal_elements(self):
     from mcdp_posets.find_poset_minima.baseline_n2 import poset_minima
     minima = poset_minima(self.elements, self.leq)
     return minima