Esempio n. 1
0
def writeConf(robNum, taskNum, combConf):
    robPosLst = generatePos(robNum, combConf[0])
    robAbiLst = generateRate(robNum, combConf[2], robPosLst)
    robPosLst = [(robPos.x, robPos.y) for robPos in robPosLst]
    robVelLst = [1 for x in range(robNum)]
    sum_robAbi = sum(robAbiLst)
    taskPosLst = generatePos(taskNum, combConf[1])
    taskRateLst = generateRate(taskNum, combConf[3], taskPosLst)
    # deal with the unable instance
    for i in range(len(taskRateLst)):
        taskRate = taskRateLst[i]
        while taskRate * robNum / 2 > sum_robAbi:
            taskRate *= random.uniform(0.5, 1)
        taskRateLst[i] = taskRate
    taskPosLst = [(taskPos.x, taskPos.y) for taskPos in taskPosLst]
    taskStateLst = [1 for i in range(taskNum)]
    comp_threhold = 0.1

    rob2tskDisMat = np.zeros((robNum, taskNum))
    rob2tskDisLst = []
    for i in range(robNum):
        for j in range(taskNum):
            d2 = float(EuclideanDis(robPosLst[i], taskPosLst[j]))
            rob2tskDisMat[i][j] = d2
            rob2tskDisLst.append(d2)

    tskDisLst = []
    tskDisMat = np.zeros((taskNum, taskNum))
    for i in range(taskNum):
        for j in range(taskNum):
            d2 = EuclideanDis(taskPosLst[i], taskPosLst[j])
            tskDisMat[i][j] = d2
            tskDisLst.append(d2)
    nameLst = []
    nameLst.append(robNum)
    nameLst.append(taskNum)
    for disType in combConf:
        nameLst.append(disType.name)
    nameLst.append('thre' + str(comp_threhold))
    nameLst = [str(x) for x in nameLst]
    sep = '_'
    sep = sep.join(nameLst)
    insFileDir = '.\\benchmark\\'
    insFileName = insFileDir + sep + 'MPDAins.dat'
    f_ins = open(insFileName, 'w')
    f_ins.write('time ' +
                datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + '\n')
    f_ins.write(sep + '\n')
    rd.writeConf(f_ins, 'robNum', [robNum])
    rd.writeConf(f_ins, 'taskNum', [taskNum])
    #    writeConf(f_ins,'max_cordx',[max_cordx])
    #    writeConf(f_ins,'max_cordy',[max_cordy])
    #    writeConf(f_ins,'max_vel',[max_vel])
    #    writeConf(f_ins,'max_abi',[max_abi])
    #    writeConf(f_ins,'max_rat',[max_rat])
    #    writeConf(f_ins,'max_state',[max_state])
    rd.writeConf(f_ins, 'comp_threhold', [comp_threhold])
    rd.writeConf(f_ins, 'rob2tskDis', rob2tskDisLst)
    rd.writeConf(f_ins, 'tskDis', tskDisLst)

    f_ins.write('\n')
    rob_xLst = [x[0] for x in robPosLst]
    rob_yLst = [y[1] for y in robPosLst]
    rd.writeConf(f_ins, 'rob_x', rob_xLst)
    rd.writeConf(f_ins, 'rob_y', rob_yLst)
    rd.writeConf(f_ins, 'rob_vel', robVelLst)
    rd.writeConf(f_ins, 'rob_abi', robAbiLst)

    f_ins.write('\n')
    tsk_xLst = [x[0] for x in taskPosLst]
    tsk_yLst = [y[1] for y in taskPosLst]
    rd.writeConf(f_ins, 'tsk_x', tsk_xLst)
    rd.writeConf(f_ins, 'tsk_y', tsk_yLst)
    rd.writeConf(f_ins, 'tsk_rat', taskRateLst)
    rd.writeConf(f_ins, 'tsk_state', taskStateLst)
    f_ins.close()
Esempio n. 2
0
 def saveEncode(self):
     for i in range(self.robNum):
         lst = list(self.encode[i][:])
         rd.writeConf(self.deg2, str(i), lst)
     self.deg2.flush()