コード例 #1
0
def main():
    ClockProcess().start()  # 开启一个子进程,用于获取所有需解析的URL,并存储到数据库
    PutUrlToQueue(Wanfang, 20)  # 往队列queue放20条数据,进行数据待处理
    LoopTimer(0.5, PutUrlToQueue, args=(
        Wanfang,
        20,
    )).start()  # 开启一个线程,比如Thread-7,它会0.5秒执行一下PutUrlToList函数
コード例 #2
0
                    count=100,
                    retain_rate=0.25,
                    random_select_rate=0.5,
                    mutation_rate=0.05,
                    section_id=sec_id)
            fig = plt.figure(num="遗传算法")
            x, y = [], []
            for i in range(70):
                ga.evolve()
                solution, seq, average_volume = ga.sloution()
                mytest = "the %d iter: %s %s" % (i, average_volume, seq)
                log.write_textctrl_txt(mytest)
                print("the %d iter:" % i, average_volume, seq)
                x.append(i + 1)
                y.append(average_volume)
            solution, seq, average_volume = ga.sloution()
            # PutData(solution, sec_id).convert_package()
            plt.plot(x, y)
            plt.title("遗传算法——随机选纸箱迭代结果图", fontproperties=simsun)
            plt.xlabel("迭代次数", fontproperties=simsun)
            plt.ylabel("纸箱体积平均利用率", fontproperties=simsun)
            plt.show()
    else:
        print("{} No section is needed to pack.".format(current_time()))


if __name__ == '__main__':
    loop = LoopTimer(interval=2, target=CartonPackAlgorithmMain)
    loop.start()
    loop.join()
コード例 #3
0
            pc_low, pc_up = 0.6, 0.99
            pm_low, pm_up = 0.05, 0.6
            beta = 0.01
            if i != 0:
                if y[i - 1] == y[i]:
                    unevolveNum += 1
                else:
                    unevolveNum = 0
            else:
                unevolveNum = 0
            ga.crossRate = pc_low + (pc_up - pc_low) * (1 - math.exp(
                -beta * unevolveNum)) / (1 + math.exp(-beta * unevolveNum))
            ga.mutation_rate = pm_low + (pm_up - pm_low) * (1 - math.exp(
                -beta * unevolveNum)) / (1 + math.exp(-beta * unevolveNum))

        end_time = time.time()
        print('算法迭代所花费的时间为:%s' % (end_time - start_time))
        print(ga._boxes)
        # LayoutGraph(solution)
        # Graph().pltIterGraph(x, (y,), name)
        Graph().pltIterGraph(
            x, (y, crossRates, mutateRates, volumeRate, end_time - start_time),
            name,
            mod=1)


if __name__ == '__main__':
    loop = LoopTimer(interval=2, target=Instance1Main)
    loop.start()
    loop.join()
コード例 #4
0
                            self.plate_temp[current_level_next][2] = self.layout_component_info[r][0] - get_x
                            current_level_next = self.get_new_plate_info(current_level_next, get_x)
                            i = r - 1
                            break
                        elif r == len(self.layout_component_info) - 1 and self.layout_component_info[r][1] == self.lowest_level_line:
                            self.plate_temp[current_level_next][2] = self._box_long - get_x
                            current_level_next = self.get_new_plate_info(current_level_next, get_x)
                            i = r
                            break
            i += 1
        return current_level_next

    def get_new_plate_info(self, current_level_next, _x):
        self.plate_temp[current_level_next][0] = _x
        self.plate_temp[current_level_next][1] = self.lowest_level_line
        self.plate_temp[current_level_next][3] = self._box_short - self.lowest_level_line
        current_level_next += 1
        return current_level_next


def get_time():
    t = time.strftime('%Y{y}%m{m}%d{d} %H{h}%M{f}%S{s}').format(y=u'年', m=u'月', d=u'日', h=u'时', f=u'分', s=u'秒')
    return t


if __name__ == '__main__':
    pack = CardBoardPack()
    loop = LoopTimer(interval=2, target=pack.package_main)
    loop.start()
    loop.join()
コード例 #5
0
    ga = GA(sec_id, partList, box, len(partList))

    for i in range(500):
        ga.evolve()
        solution, seq, volumeRate = ga.getSolution()
        crossRates.append(ga.crossRate)
        mutateRates.append(ga.mutation_rate)
        iterTimes.append(i+1)
        volumeRates.append(volumeRate)
        print("the %d iter:" % (i + 1), volumeRate, crossRates[i], mutateRates[i])
        if volumeRate == bestTarget:
            break
    algo_time = time.time() - start_time
    print('算法迭代所花费的时间为:%s' % algo_time)

    resSol = PutData(solution, sec_id, volumeRates[-1]).decodeSol()
    saveIterData(iterTimes, volumeRates, crossRates, mutateRates, algo_time, resSol, setName)
    Graph().pltIterGraph(iterTimes,(volumeRates,crossRates,mutateRates,volumeRate,algo_time),setName,mod=0)
    LayoutGraph(resSol)


if __name__ == '__main__':
    if runMode == 0:
        loop = LoopTimer(interval=2, target=mainAGA)
        loop.start()
        loop.join()
    elif runMode == 1:
        mainAGA()
    else:
        raise AttributeError("The run mode must be 0 or 1.")