有人可以帮助我解决这个传奇问题吗?

发布于 2025-02-13 12:11:23 字数 1830 浏览 2 评论 0原文

任何专家可以帮助我合并以下传奇吗? 我希望将所有两个传说合并在一起,

可以帮助我合并以下传奇吗? 我希望所有两个传说合并

def dominates(bestRouteTime, num_buses):
    dominating = False
    for i in range(len(bestRouteTime)):
        if bestRouteTime[i] > num_buses[i]:
    return False
        if bestRouteTime[i] < num_buses[i]:
        dominating = True
    return dominating


def is_dominated(bestRouteTime,front):
    for num_buses in front:
        if dominates(num_buses,bestRouteTime):
            return True
    return False

def pareto_front(cand):
    front = set([])
    for i in cand:
       add_i = True
        for j in list(front):
            if dominates(i,j):
                front.remove(j)
            if dominates(j,i):
            add_i = False
        if add_i:
            front.add(i)
    front = list(front)
    front.sort()
    return front

if __name__ == "__main__":
    import random
    #random.seed(1)
    cand = [(random.random()**.25,random.random()**.25) for i in range(1000)]
    fig, ax = plt.subplots(figsize=(10, 8))
    ax.xlabel = "Travel Time (seconds)"
    ax.ylabel = "Number of Walking Buses"
    for (bestRouteTime, num_buses) in cand:
        x,y = (bestRouteTime*360, num_buses*10) 
        ax.plot(x,y,"bo")
    
    front = pareto_front(cand)
    ax.plot([x for (x,y) in front], [y for (x,y) in front], "ro", label="Pareto Font")
    fig.canvas.draw()
    ax.set_ylabel('Number of Walking Buses')
    ax.set_xlabel('Travel Time (seconds)')
    plt.title = ("Pareto Optimal Fronts (TSPTW))")
    legend = ax.legend(loc='best', shadow=True, fontsize='large')
    plt.show()

这就是从我的代码中获得的

输入图像描述在这里

Can any expert help me merge the following legend?
I would like all the two legends to be merged

Can any expert help me merge the following legend?
I would like all the two legends to be merged

def dominates(bestRouteTime, num_buses):
    dominating = False
    for i in range(len(bestRouteTime)):
        if bestRouteTime[i] > num_buses[i]:
    return False
        if bestRouteTime[i] < num_buses[i]:
        dominating = True
    return dominating


def is_dominated(bestRouteTime,front):
    for num_buses in front:
        if dominates(num_buses,bestRouteTime):
            return True
    return False

def pareto_front(cand):
    front = set([])
    for i in cand:
       add_i = True
        for j in list(front):
            if dominates(i,j):
                front.remove(j)
            if dominates(j,i):
            add_i = False
        if add_i:
            front.add(i)
    front = list(front)
    front.sort()
    return front

if __name__ == "__main__":
    import random
    #random.seed(1)
    cand = [(random.random()**.25,random.random()**.25) for i in range(1000)]
    fig, ax = plt.subplots(figsize=(10, 8))
    ax.xlabel = "Travel Time (seconds)"
    ax.ylabel = "Number of Walking Buses"
    for (bestRouteTime, num_buses) in cand:
        x,y = (bestRouteTime*360, num_buses*10) 
        ax.plot(x,y,"bo")
    
    front = pareto_front(cand)
    ax.plot([x for (x,y) in front], [y for (x,y) in front], "ro", label="Pareto Font")
    fig.canvas.draw()
    ax.set_ylabel('Number of Walking Buses')
    ax.set_xlabel('Travel Time (seconds)')
    plt.title = ("Pareto Optimal Fronts (TSPTW))")
    legend = ax.legend(loc='best', shadow=True, fontsize='large')
    plt.show()

This is what got from my code

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白云不回头 2025-02-20 12:11:23

在不使我的生活变得过多复杂的情况下,我会捕获line艺术家(line1,line2在下面的代码中),并将其在传说中使用。特别是使用蓝点的最后一位艺术家:

#random.seed(1)
cand = [(random.random()**.25,random.random()**.25) for i in range(1000)]
fig, ax = plt.subplots(figsize=(10, 8))
ax.xlabel = "Travel Time (seconds)"
ax.ylabel = "Number of Walking Buses"
for (bestRouteTime, num_buses) in cand:
    x,y = (bestRouteTime*360, num_buses*10) 
    line1, = ax.plot(x,y,"bo", label="Number of walking buses")

front = pareto_front(cand)
line2, = ax.plot([x for (x,y) in front], [y for (x,y) in front], "ro", label="Pareto Font")
fig.canvas.draw()
ax.set_ylabel('Number of Walking Buses')
ax.set_xlabel('Travel Time (seconds)')
plt.title = ("Pareto Optimal Fronts (TSPTW))")
legend = ax.legend(handles=(line1, line2), loc='best', shadow=True, fontsize='large')
plt.show()

Without complicating my life too much, I would capture the line artists (line1, line2 in the code below) and use them on the legend. In particular, use the last artist of the blue dots:

#random.seed(1)
cand = [(random.random()**.25,random.random()**.25) for i in range(1000)]
fig, ax = plt.subplots(figsize=(10, 8))
ax.xlabel = "Travel Time (seconds)"
ax.ylabel = "Number of Walking Buses"
for (bestRouteTime, num_buses) in cand:
    x,y = (bestRouteTime*360, num_buses*10) 
    line1, = ax.plot(x,y,"bo", label="Number of walking buses")

front = pareto_front(cand)
line2, = ax.plot([x for (x,y) in front], [y for (x,y) in front], "ro", label="Pareto Font")
fig.canvas.draw()
ax.set_ylabel('Number of Walking Buses')
ax.set_xlabel('Travel Time (seconds)')
plt.title = ("Pareto Optimal Fronts (TSPTW))")
legend = ax.legend(handles=(line1, line2), loc='best', shadow=True, fontsize='large')
plt.show()
柳絮泡泡 2025-02-20 12:11:23
if __name__ == "__main__":
       # random.seed(1)
      cand = [(random.random()**.25,random.random()**.25) for i in range(1000)]
       #  cand  = np.random.randn(1000)
          fig, ax = plt.subplots(figsize=(10, 8))

      for (bestRouteTime, num_buses) in cand:
           x,y = (bestRouteTime*360, num_buses*10) 
          TSPTW, = ax.plot(x,y,"bo")

       front = pareto_front(cand)
       Font, = ax.plot([x for (x,y) in front], [y for (x,y) in front], "ro")
       fig.canvas.draw()
       ax.set_ylabel('Number of Walking Buses')
       ax.set_xlabel('Travel Time (seconds)')
       plt.title = ("Pareto Optimal Fronts (Modified TSPTW))")
       legend1 = plt.legend((TSPTW,Font), ["Generated Solutions","Pareto Set"],
       loc="upper left", shadow=True, fontsize='large')
       plt.gca().add_artist(legend1)
       plt.show()

新输出

if __name__ == "__main__":
       # random.seed(1)
      cand = [(random.random()**.25,random.random()**.25) for i in range(1000)]
       #  cand  = np.random.randn(1000)
          fig, ax = plt.subplots(figsize=(10, 8))

      for (bestRouteTime, num_buses) in cand:
           x,y = (bestRouteTime*360, num_buses*10) 
          TSPTW, = ax.plot(x,y,"bo")

       front = pareto_front(cand)
       Font, = ax.plot([x for (x,y) in front], [y for (x,y) in front], "ro")
       fig.canvas.draw()
       ax.set_ylabel('Number of Walking Buses')
       ax.set_xlabel('Travel Time (seconds)')
       plt.title = ("Pareto Optimal Fronts (Modified TSPTW))")
       legend1 = plt.legend((TSPTW,Font), ["Generated Solutions","Pareto Set"],
       loc="upper left", shadow=True, fontsize='large')
       plt.gca().add_artist(legend1)
       plt.show()

New output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文