示例#1
0
 def draw(self, I=None, ax=None, title=None):
     if I is None:
         I = range(self.nv)
     if ax is None:
         ax = plt.gca()
     cnames = CSS4_COLORS.values()[59:]
     for y in I:
         c = cnames[y]
         for x in range(self.ne):
             if self.__is_contained(y, self.__e[x]):
                 rect = plt.Rectangle((x - 0.5, y - 0.5),
                                      1,
                                      1,
                                      alpha=0.75,
                                      color=c)
                 ax.add_patch(rect)
     ax.set_xlim([-0.5, self.ne - 0.5])
     ax.set_ylim([-0.5, self.nv - 0.5])
     ax.set_xticks(range(self.ne))
     ax.set_yticks(range(self.nv))
     ax.set_xticklabels([str(e) for e in self.__e], rotation=90)
     ax.set_axisbelow(True)
     ax.grid(color='#cccccc')
     if title:
         ax.set_title(title)
示例#2
0
def draw(sc, I=None, ax=None):
    n, m = sc.universal_set_size, sc.covering_set_num
    if I is None:
        I = [1] * m
    if ax is None:
        ax = plt.gca()
    ax.set_axisbelow(True)
    ax.grid(color="#cccccc")
    cnames = CSS4_COLORS.values()[59:]
    for y, val in enumerate(I):
        if val == 0:
            continue
        c = cnames[y]
        for e in range(sc.sizes[y]):
            x = sc.sets[y][e]
            rect = plt.Rectangle((x - 0.5, y - 0.5), 1, 1, alpha=0.75, color=c)
            ax.add_patch(rect)
示例#3
0
                else:
                    j = heapq.heappop(self.__stack)
                    j.ct.append([self.__t, self.__t + j.pt])
                    self.__t += j.pt
                self.__stacking()
        self.__print()

    def draw(self, fname=None):
        for j in jobs:
            j.draw()
        plt.gca().set_ylim([0, 2])
        plt.gca().margins(0.1)
        if fname:
            plt.savefig(fname, bbox_inches='tight')
        else:
            plt.show()


if __name__ == '__main__':
    jobs = []
    c = mc.values()
    n = len(c) - 1
    random.seed(0)
    jobs.append(job(2, 0, c[random.randint(0, n)]))
    jobs.append(job(1, 4, c[random.randint(0, n)]))
    jobs.append(job(4, 1, c[random.randint(0, n)]))
    sched = srpt(jobs)
    for j in sched.jobs:
        print j.ct
    sched.draw('srpt_for_js1.png')