Ejemplo n.º 1
0
def run_view():
    evac_time = 0  #疏散时间
    Data.FX_R = 6
    Data.FX_P = math.pow(6, 2) / 2

    result_speed = []
    allPeople = InitPeolple.creatPeople()
    DrawFirst.drawPeople(allPeople)
    while Data.flag:  #循环开始
        move_on = 0
        move_all = 0

        for p in allPeople:  #遍历行人
            Income.outDirection(p, allPeople)  #计算收益
            direction = max(p.allInComeBySort.items(),
                            key=lambda x: x[1])[0]  #获取方向
            if direction != 5:
                move_on = move_on + 1
            move_all = move_all + 1
            Rule.PeopleMove(p, direction)  # 行人移动
            Rule.chickOverAround(p, allPeople)  #检测是否到达出口

        DrawFirst.drawPeople(allPeople)
        speed = move_on / move_all
        result_speed.append(speed)
        evac_time = evac_time + 1  #疏散时间+1
        if evac_time == 15:
            Data.flag = False
        print('当前时间步:', evac_time)
    print(result_speed)
Ejemplo n.º 2
0
def run_view():
    '''此方法为单步运行测试方法,带图像显示'''
    time_logo = 0
    # allPeople = InitPeolple.creatPeople()  # 产生随机行人
    # allPeople=InitPeolple.creatPeople_force_normal()
    # allPeople=InitPeolple.creatPeople_force_fix()
    allPeople = InitPeolple.creatPeople_force_random()
    # allPeople=InitPeolple.creatAppointPeo()#产生指定行人
    # allPeople=InitPeolple.creatAreaPeople()
    # print(len(allPeople))
    # allWall = InitPeolple.creatWall()  # 创建墙壁
    # allExit = InitPeolple.creatExit()  # 创建出口
    DrawFirst.drawPeople(allPeople)
    while Data.flag:  #循环开始
        if Data.FX_S_R < 21:
            count_R_O_V(time_logo)
        for p in allPeople:  #遍历行人
            Income.outDirection(p, allPeople)  #计算收益
            direction = max(p.allInComeBySort.items(),
                            key=lambda x: x[1])[0]  #获取方向
            Rule.chickOverAround(p, allPeople)  #检测是否到达出口
            Rule.PeopleMove(p, direction)  #行人移动
        DrawFirst.drawPeople(allPeople)
        time_logo = time_logo + 1
        print(
            time_logo,
            "\033[4;32;40mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\033[0m"
        )
Ejemplo n.º 3
0
def run_force_test(double_r,steps):
    time_logo=0
    Data.PEOPLE_FORCE=50
    Data.FX_S_SIGMA_2=double_r
    Data.FX_S_R = 2 * np.sqrt(Data.FX_S_SIGMA_2)
    Data.FX_S_P = 2 * Data.FX_S_SIGMA_2
    allPeople = InitPeolple.creatPeople()  # 产生随机行人
    # allPeople=InitPeolple.creatAppointPeo()#产生指定行人
    # allPeople=InitPeolple.creatAreaPeople()
    # print(len(allPeople))
    # allWall = InitPeolple.creatWall()  # 创建墙壁
    # allExit = InitPeolple.creatExit()  # 创建出口
    # DrawFirst.drawPeople(allPeople)
    while Data.flag:#循环开始
        for p in allPeople:#遍历行人
            Income.outDirection(p, allPeople)#计算收益
            direction = max(p.allInComeBySort.items(), key=lambda x: x[1])[0]#获取方向
            Rule.chickOverAround(p, allPeople)#检测是否到达出口
            Rule.PeopleMove(p, direction)#行人移动
        # DrawFirst.drawPeople(allPeople)
        time_logo = time_logo + 1
        # print(time_logo,"\033[4;32;40mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\033[0m")
        if len(allPeople)==0:
            Data.flag=False
    allData=[]
    allData.append(double_r)
    allData.append(steps)
    allData.append(time_logo)
    return allData
Ejemplo n.º 4
0
def run_view():
    '''此方法为单步运行测试方法,带图像显示'''
    time_logo=0

    Data.FX_R = 8
    Data.FX_P = math.pow(Data.FX_R, 2) / 2

    Data.FX_S_V = 0
    Data.FX_S_R = 15


    # allPeople = InitPeolple.creatPeople()  # 产生随机行人
    # allPeople=InitPeolple.creatPeople_force_normal()
    allPeople=InitPeolple.creatPeople_force_fix()
    # allPeople=InitPeolple.creatPeople_force_random()
    # allPeople=InitPeolple.creatAppointPeo()#产生指定行人
    # allPeople=InitPeolple.creatAreaPeople()
    # print(len(allPeople))
    # allWall = InitPeolple.creatWall()  # 创建墙壁
    # allExit = InitPeolple.creatExit()  # 创建出口
    DrawFirst.drawPeople(allPeople)
    # time.sleep(100)
    result_time=[]
    result_rote=[]
    result_all=[]
    while Data.flag:#循环开始
        if Data.FX_S_R<21:
            count_R_O_V()
        for p in allPeople:#遍历行人
            Income.outDirection(p, allPeople)#计算收益
            direction = max(p.allInComeBySort.items(), key=lambda x: x[1])[0]#获取方向
            Rule.chickOverAround(p, allPeople)#检测是否到达出口
            Rule.PeopleMove(p, direction)#行人移动


        a_p=0
        b_p = 0
        for p in allPeople:
            if Data.FX_R**2<((p.x-Data.FX_M)**2 +(p.x-Data.FX_M)**2)<Data.FX_S_R**2:
                a_p=a_p+1
                if p.isInGrend==2:
                    b_p=b_p+1
        result_time.append(time_logo)
        if a_p==0:
            result_rote.append(0)
        else:
            result_rote.append(b_p/a_p)
        DrawFirst.drawPeople(allPeople)
        time_logo = time_logo + 1
        # print(time_logo,"\033[4;32;40mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\033[0m")
        # if time_logo==15:
        #     Data.flag=False
        print(time_logo)
    result_all.append(result_time)
    result_all.append(result_rote)
    print(result_all)
Ejemplo n.º 5
0
def run_insert(case_s, density, radius, radius_ob, radius_v, force, force_type,
               peo_view, steps):
    '''此方法为运行方法,带参数接受和返回,不带图像显示'''
    Data.flag = True
    time_logo = 0

    if case_s == 0:  #危险源位置设置
        Data.FX_N = 19
    elif case_s == 1:
        Data.FX_N = 15
    elif case_s == 2:
        Data.FX_N = 10
    elif case_s == 3:
        Data.FX_N = 5
    elif case_s == 4:
        Data.FX_N = 2

    Data.PEOPLE_DENSYTY = density
    Data.PEOPLE_NUMBER = Data.count_PEOPLE_NUMBER(density)

    Data.FX_SIGMA_2 = radius  # 危险源大小
    Data.FX_R = Data.count_FX_R(radius)  # 影响范围半径
    Data.FX_P = Data.count_FX_P(radius)  # 系数 p越大 高斯函数的圆形越大

    Data.FX_S_SIGMA_2 = radius_ob
    Data.FX_S_R = Data.count_FX_S_R(radius_ob)
    Data.FX_S_P = Data.count_FX_S_P(radius_ob)

    Data.FX_S_V = radius_v

    Data.PEOPLE_FORCE = force

    if force_type == 0:  # fix
        allPeople = InitPeolple.creatPeople_force_fix()
    else:  #random
        allPeople = InitPeolple.creatPeople_force_random()

    Data.PEOPLE_FAN_R = peo_view
    while Data.flag:  #循环开始
        if Data.FX_S_R < 21:
            count_R_O_V(time_logo)
        for p in allPeople:  #遍历行人
            Income.outDirection(p, allPeople)  #计算收益
            direction = max(p.allInComeBySort.items(),
                            key=lambda x: x[1])[0]  #获取方向
            Rule.chickOverAround(p, allPeople)  #检测是否到达出口
            Rule.PeopleMove(p, direction)  #行人移动
        if len(allPeople) == 0:
            Data.flag = False
        time_logo = time_logo + 1
    # print(time_logo)
    # print("\033[4;32;40mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\033[0m")

    return time_logo
Ejemplo n.º 6
0
def run_insert(par_density,par_case,par_r_c,par_r_o,par_v,par_force):
    '''此方法为运行方法,带参数接受和返回,不带图像显示'''
    Data.flag=True
    time_logo=0
    if par_case==1:#危险源位置设置
        Data.FX_N=19
    elif par_case==2:
        Data.FX_N = 15
    elif par_case==3:
        Data.FX_N = 10
    Data.PEOPLE_DENSYTY=par_density
    Data.PEOPLE_NUMBER=int(Data.ROOM_N * Data.ROOM_M * par_density)
    Data.FX_R =par_r_c   # 影响范围半径
    Data.FX_P = math.pow(par_r_c, 2) / 2 # 系数 p越大 高斯函数的圆形越大
    Data.FX_S_R=par_r_o
    Data.FX_S_P=math.pow(par_r_o, 2) / 2
    Data.FX_S_V=par_v
    Data.PEOPLE_FORCE=par_force
    allPeople = InitPeolple.creatPeople_force_fix()

    result_time = []
    result_rote = []
    result_all = []

    while Data.flag:#循环开始
        if Data.FX_S_R<21:
            count_R_O_V()
        for p in allPeople:#遍历行人
            Income.outDirection(p, allPeople)#计算收益
            direction = max(p.allInComeBySort.items(), key=lambda x: x[1])[0]#获取方向
            Rule.chickOverAround(p, allPeople)#检测是否到达出口
            Rule.PeopleMove(p, direction)#行人移动
        if len(allPeople)==0:
            Data.flag=False
        a_p = 0
        b_p = 0
        for p in allPeople:
            if Data.FX_R ** 2 < ((p.x - Data.FX_M) ** 2 + (p.x - Data.FX_M) ** 2) < Data.FX_S_R ** 2:
                a_p = a_p + 1
                if p.isInGrend == 2:
                    b_p = b_p + 1
        result_time.append(time_logo)
        if a_p == 0:
            result_rote.append(0)
        else:
            result_rote.append(b_p / a_p)
        time_logo = time_logo + 1
    result_all.append(result_time)
    result_all.append(result_rote)
    return result_all
Ejemplo n.º 7
0
    def test_plot(self):
        '''This function will test if plots from year 2007 to 2012 are generated successfully'''
        try:
            for i in range(2007,2013):
                os.remove('./Income_Box_'+str(i)+'.jpg')
                os.remove('./Income_Hist_'+str(i)+'.jpg')

        except OSError:
            pass
        i = Income()
        i.plot_2007_2012()
        for i in range(2007,2013):
            self.assertTrue(os.path.isfile('./Income_Box_'+str(i)+'.jpg'), "Fail to generate plot.")
            self.assertTrue(os.path.isfile('./Income_Hist_'+str(i)+'.jpg'), "Fail to generate plot.")
Ejemplo n.º 8
0
def main():
    income_data = Income()
    # Ask user for a year and exit until 'finish' entered.
    user_input = get_user_input()
    while user_input != "finish":
        year = 0
        while year == 0:
            try:
                year = read_year(user_input)
                income_data.income_dist(year)
                break
            except ValueError:
                print "Invalid input. Please enter again."
            except RangeError:
                print "The year you entered is not in [1800, 2012]. Please enter again."
            user_input = get_user_input()
        user_input = get_user_input()
    # plot income data from 2007 to 2015
    income_data.plot_2007_2012()
Ejemplo n.º 9
0
def run_insert(par_case, par_density, par_radius):
    Data.flag = True
    evac_time = 0  #疏散时间
    if par_case == 1:
        Data.FX_N = 19
    elif par_case == 2:
        Data.FX_N = 15
    else:
        Data.FX_N = 10

    Data.PEOPLE_DENSYTY = par_density
    Data.PEOPLE_NUMBER = int(Data.ROOM_N * Data.ROOM_M * par_density)

    Data.FX_R = par_radius
    Data.FX_P = math.pow(par_radius, 2) / 2

    result_all = []
    result_speed = []
    result_time = []
    allPeople = InitPeolple.creatPeople()
    while Data.flag:  #循环开始
        move_on = 0
        move_all = 0
        for p in allPeople:  #遍历行人
            Income.outDirection(p, allPeople)  #计算收益
            direction = max(p.allInComeBySort.items(),
                            key=lambda x: x[1])[0]  #获取方向
            if direction != 5:
                move_on = move_on + 1
            move_all = move_all + 1
            Rule.PeopleMove(p, direction)  # 行人移动
            Rule.chickOverAround(p, allPeople)  #检测是否到达出口
        if len(allPeople) == 0:
            Data.flag = False
        speed = move_on / move_all
        result_speed.append(speed)
        result_time.append(evac_time, )
        evac_time = evac_time + 1  #疏散时间+1
    result_all.append(result_time)
    result_all.append(result_speed)
    return result_all
    def income(self, event):
        db = pymysql.connect("localhost", "root", "root", "adv")
        cursor = db.cursor()
        sql = "SELECT INCOME FROM cia WHERE UIDAI = {}".format(self.uidai)
        try:
            cursor.execute(sql)
            result = cursor.fetchone()
            if result[0] == 0:
                i = Income(self.master, self.uidai)
            else:
                os.startfile(str(self.uidai) + "i.docx")
                os.startfile(str(self.uidai) + "i.docx", "print")
                exit(0)

        except pymysql.Error as e:
            print(e)
Ejemplo n.º 11
0
def run_insert_old(case_s,P,R,steps):
    resultData=[]#返回总列表
    if case_s==0:#危险源位置设置
        Data.FX_N=19
    elif case_s==1:
        Data.FX_N = 15
    elif case_s==2:
        Data.FX_N = 10
    elif case_s==3:
        Data.FX_N = 5
    elif case_s==4:
        Data.FX_N = 2
    Data.PEOPLE_DENSYTY=P#行人密度
    Data.PEOPLE_NUMBER=int(Data.ROOM_N*Data.ROOM_M*Data.PEOPLE_DENSYTY)#行人数量
    Data.FX_SIGMA_2=R#危险源大小
    Data.FX_R = 2 * np.sqrt(Data.FX_SIGMA_2)  # 影响范围半径
    Data.FX_P = 2 * Data.FX_SIGMA_2  # 系数 p越大 高斯函数的圆形越大

    # init = InitPeolple.InitPeople()#实例化 产生行人类
    # draw = DrawFirst.draw()#实例化 画图类
    # income = Income.outDirection()
    allPeople = InitPeolple.creatPeople()#产生随机行人
    # allPeople=init.creatAppointPeo()#产生指定行人
    allWall = InitPeolple.creatWall()#创建墙壁
    allExit = InitPeolple.creatExit()#创建出口

    T=[]#疏散时间
    S=[]#剩余行人
    V=[]#行人速度
    Q=[]#出口流量
    Q.append(0)#将出口流量[0]设为0 Q列表少一个数

    evac_time = 0#疏散时间

    while Data.flag:#循环开始
        move_on_num = 0#本次时间步移动的行人
        move_off_num = 0#本次时间步静止的行人
        vector = 0#本次时间步行人速度
        for p in allPeople:#遍历行人
            Income.outDirection(p, allPeople)#计算收益
            direction = max(p.allInComeBySort.items(), key=lambda x: x[1])[0]#获取方向
            if direction==5:#如果行人静止
                move_off_num=move_off_num+1#计数器+1
            else:
                move_on_num=move_on_num+1#计数器+1
            Rule.chickOverAround(p, allPeople)#检测是否到达出口
            Rule.PeopleMove(p, direction)#行人移动

        # draw.drawPeople(allPeople)#绘制行人
        # print(evac_time,"---",len(allPeople),"---",move_on_num/len(allPeople))

        if len(allPeople)==0:#如果行人全部疏散完毕
            vector=1#速度设为1
            Data.flag=False#循环标志--停止
        else:
            vector=move_on_num/len(allPeople)#行人速度=移动的行人/总行人
        if vector>1:#如果行人速度>1
            vector=1.0#设置为1

        T.append(evac_time)#将疏散时间添加到T
        S.append(len(allPeople))#将剩余行人添加到S
        V.append(vector)#将行人速度添加到V

        evac_time=evac_time+1#疏散时间+1

    for i in range(len(S) - 1):#遍历行人
        quar = S[i] - S[i + 1]#出口流量=上一步的行人总数-下一步的行人总数
        Q.append(quar)#将出口流量添加到Q

    '''将各种参数添加到返回列表'''
    resultData.append(case_s)
    resultData.append(P)
    resultData.append(R)
    resultData.append(steps)
    resultData.append(T)
    resultData.append(S)
    resultData.append(V)
    resultData.append(Q)


    return resultData
Ejemplo n.º 12
0
import numpy as np
import Data, InitPeople, Draw, Rule, Income
import matplotlib.pyplot as plt
import matplotlib.animation
import time

init = InitPeople.InitPeoples()
draw = Draw.Draw()
# move=Rule.PeopleMove()
income = Income.outDirection()
# allPeople=init.creatPeople()
allPeople = init.creatForemostPeo()
allWall = init.creatWall()
allExit = init.creatExit()
# while Data.flag:

# for p in allPeople:
#     income.outDirection(p,allPeople)
#     direction=max(p.allInComeBySort.items(),key=lambda  x:x[1])[0]
#     print('direction ==',direction)
while Data.flag:
    for p in allPeople:
        income.outDirection(p, allPeople)

        direction = max(p.allInComeBySort.items(), key=lambda x: x[1])[0]

        Rule.chickOverAround(p, allPeople)
        Rule.PeopleMove(p, direction)
        # print(p.grendIncome)
        # print(p.isInGrend)
        print(p.allInComeBySort)