예제 #1
0
def modifyfile(filename):
    f = open(filename, 'rU')
    lines = f.readlines()
    f.close()
    data = []
    processes=[]
    for line in lines:
		if line.startswith("imax"):
			data.append(line.strip().split())
			imax = int(line.strip().split()[1])
		elif line.startswith("rate"):
			rateList = ['rate','']
			nprocess = len(line.strip().split()[1:])/imax
			#ColumnsToModify = linspace(2,(imax-1)*nprocess+2,imax)
                        ColumnsToModify=[]
                        for i in range(len(processes)):
                                       if process in processes[i]: ColumnsToModify.append(i+1)
			i=1
			for item in line.strip().split()[1:]:
				if i in ColumnsToModify:
					itemtemp = float(mu)*float(item)
					rateList.append(str(itemtemp))
				else:
					rateList.append(item)
				i+=1
			data.append(rateList)
		elif line.startswith("----"): data.append(['break'])
		elif (line.startswith("Observation") or line.startswith("shapes")): data.append([line.strip().split()[0],'','','']+line.strip().split()[1:])
		elif (line.startswith("bin") or line.startswith("process")):
                    data.append([line.strip().split()[0],'']+line.strip().split()[1:])
                    if line.startswith("process") and not processes:
                        processes=line.strip().split()[1:]
		else: data.append(line.strip().split())
    out=open(output,'w')
    printTable(data,out)
예제 #2
0
def modifyfile(filename):
    f = open(filename, 'rU')
    lines = f.readlines()
    f.close()
    data = []
    for line in lines:
        if line.startswith("imax"):
            data.append(line.strip().split())
            imax = int(line.strip().split()[1])
        elif line.startswith("rate"):
            rateList = ['rate', '']
            nprocess = len(line.strip().split()[1:]) / imax
            ColumnsToModify = linspace(2, (imax - 1) * nprocess + 2, imax)
            i = 1
            for item in line.strip().split()[1:]:
                if i in ColumnsToModify:
                    itemtemp = float(mu) * float(item)
                    rateList.append(str(itemtemp))
                else:
                    rateList.append(item)
                i += 1
            data.append(rateList)
        elif line.startswith("----"):
            data.append(['break'])
        elif (line.startswith("Observation") or line.startswith("shapes")):
            data.append([line.strip().split()[0], '', '', ''] +
                        line.strip().split()[1:])
        elif (line.startswith("bin") or line.startswith("process")):
            data.append([line.strip().split()[0], ''] +
                        line.strip().split()[1:])
        else:
            data.append(line.strip().split())
    out = open('dataCard.txt', 'w')
    printTable(data, out)
예제 #3
0
def show():
    print u"\n\n\n +++++++++++++你已经进入流水相关服务 :  +++++++++++++"
    cardNo = sql.readLoginCardNo()
    if not  cardNo:
        print u"请先登录..."
        login.loginStart()
        cardNo = sql.readLoginCardNo()

    while True:
        utils.printTable(flowService)
        num =  raw_input(u"请选择对应服务 或者 输入q退出 :")
        if num == 'q': break
        regex = re.compile(r"\d+")
        if (not regex.match(num))  or (  int(num) >= len(flowService)):
            print u"请输入正确服务号码"
            continue
        num = int(num)
        break
    result = flowService[num].values().pop()()
    if not result :
        print u"无任何记录"
        return True

    for t in result:
        tmpDict = {'type':t.get('type'),'money':t.get('money')}
        tmpDict['time'] = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(t.get('time')))
        print tmpDict
    return  True
예제 #4
0
def main(inputRfilename, outputRfilename, inputDCfilename, outputDCfilename, threshold, thresholdBG):
    input = ROOT.TFile(inputRfilename, 'READ')
    output = ROOT.TFile(outputRfilename, 'RECREATE')
    data = []
    olddata, binList, processList = readOldDataCard(inputDCfilename)
    data += olddata
    newdata = walk_and_copy(input, output, threshold, thresholdBG, binList, processList)
    data += newdata
    out=open(outputDCfilename,'w')
    printTable(data,out)
예제 #5
0
def main(inputRfilename, outputRfilename, inputDCfilename, outputDCfilename):
    input = ROOT.TFile(inputRfilename, 'READ')
    output = ROOT.TFile(outputRfilename, 'RECREATE')
    if not os.path.exists(inputDCfilename[:-4] + '_original.txt'):
        os.system('mv ' + inputDCfilename + ' ' + inputDCfilename[:-4] +
                  '_original.txt')
    data = readDataCard(inputDCfilename[:-4] + '_original.txt')
    out = open(inputDCfilename, 'w')
    printTable(data, out)
    walk_and_copy(input, output)
예제 #6
0
def main(inputDCfile, inputDCfile0P, outputDCfile0P, inputDCfile0M, outputDCfile0M):
	data0P = []
	dataOld0P, dictOld0P = readDataCard(inputDCfile0P)
	data0P += dataOld0P
	dataNew0P = addStatShapes(inputDCfile, dictOld0P, dataOld0P[-1])
	data0P += dataNew0P
	out0P=open(outputDCfile0P,'w')
	printTable(data0P,out0P)

	data0M = []
	dataOld0M, dictOld0M = readDataCard(inputDCfile0M)
	data0M += dataOld0M
	dataNew0M = addStatShapes(inputDCfile, dictOld0M, dataOld0M[-1])
	data0M += dataNew0M
	out0M=open(outputDCfile0M,'w')
	printTable(data0M,out0M)
예제 #7
0
def main(inputRfilename, input2dRfilename, outputRfilename, inputDCfilename,
         outputDCfilename, threshold, thresholdBG, thresholdSignal, p0m, p1m,
         p0h, p1h):
    input = ROOT.TFile(inputRfilename, 'READ')
    input2d = ROOT.TFile(input2dRfilename, 'READ')
    output = ROOT.TFile(outputRfilename, 'RECREATE')
    data = []
    olddata, binList, processLists = readOldDataCard(inputDCfilename)
    data += olddata
    newdataS, newdataT = walk_and_copy(input, input2d, output, threshold,
                                       thresholdBG, thresholdSignal, binList,
                                       processLists, p0m, p1m, p0h, p1h)
    data += newdataT
    data += newdataS
    out = open(outputDCfilename, 'w')
    printTable(data, out)
예제 #8
0
from utils import readFilePairs, printTable
from calculateMakespan import calculateMakespan
from plotResult import plotResult

sequence = [
    11, 10, 9, 2, 1, 13, 8, 0, 2, 4, 13, 0, 4, 4, 5, 0, 7, 4, 5, 11, 12, 12, 4,
    10, 5, 2, 11, 6, 6, 3, 12, 6, 0, 9, 9, 14, 1, 12, 7, 9, 13, 2, 6, 14, 2, 8,
    5, 3, 6, 5, 12, 9, 8, 1, 4, 6, 7, 1, 10, 14, 3, 7, 6, 11, 14, 14, 8, 0, 1,
    7, 9, 5, 9, 10, 2, 4, 3, 13, 5, 4, 3, 12, 6, 0, 7, 12, 6, 11, 2, 0, 8, 12,
    13, 2, 2, 6, 12, 0, 8, 6, 13, 13, 11, 10, 10, 3, 10, 1, 13, 12, 9, 1, 1, 1,
    14, 2, 7, 10, 14, 0, 11, 14, 11, 9, 4, 11, 3, 9, 6, 12, 11, 10, 13, 10, 4,
    9, 7, 7, 5, 10, 8, 13, 3, 0, 12, 6, 2, 7, 14, 2, 1, 2, 8, 11, 14, 9, 8, 0,
    8, 4, 2, 1, 7, 1, 10, 3, 7, 5, 7, 1, 8, 14, 11, 8, 3, 11, 3, 0, 13, 13, 10,
    3, 5, 1, 6, 9, 4, 12, 4, 7, 3, 0, 14, 14, 5, 4, 14, 7, 0, 13, 12, 11, 14,
    3, 13, 6, 1, 8, 9, 4, 3, 10, 9, 2, 12, 10, 5, 5, 11, 13, 5, 8, 5, 0, 8
]
times, machines, n = readFilePairs("cases/15_15_1")

result, table = calculateMakespan(times, machines, sequence, n)

print("RESULT: %s" % result)
print("Sequence: ")
print(sequence)
printTable(table)
plotResult(table, result)
예제 #9
0
def genetic(times, machines, n, population_number, iterations, rate, target):
    machine_number = len(machines[0])
    start_time = time.time()

    def sortAndGetBestIndividual(population):
        best_individual = None
        best_result = None
        for individual in population:
            result = None
            if not individual[1]: 
                result, table = calculateMakespan(times, machines, individual[0], n)
                individual[1] = result
            else: 
                result = individual[1]

            if not best_result or result < best_result:
                best_result = result
                best_individual = individual

        population.sort(key=lambda x: x[1])
        return best_individual, best_result

    population = generate_population(population_number, n, machine_number)
    global_best_ind, global_best = sortAndGetBestIndividual(population)
    
    ##if we don't define a target we set the number of iterations we want 
    if not target:
        for i in range(iterations):
            population = evolve(population, rate)
            best_ind, best_result = sortAndGetBestIndividual(population)
            total_fitness, diffPercentage = getFitness(population)

            if(not global_best or best_result < global_best):
                global_best = best_result
                global_best_ind = copy.deepcopy(best_ind)

            printProgress(best_result, i, time.time() - start_time)
            checkDiversity(population, diffPercentage, n, machine_number)
    else:
        #If we define a target we iterate until the best result reach that target
        i = 0
        while(target < global_best):
            i += 1
            #in every iteration: 
            #We evolve the population
            population = evolve(population, rate)
            #We find the best individual 
            best_ind, best_result = sortAndGetBestIndividual(population)
            #We calculate the diversity % between the population and the total_fitness(sum of all the results)
            total_fitness, diffPercentage = getFitness(population)

            #if the result found is better than the global found we update the global
            if(not global_best or best_result < global_best):
                global_best = best_result
                global_best_ind = copy.deepcopy(best_ind)
            #We print the progress so far and the time elapsed
            printProgress(best_result, i, time.time() - start_time)
            #We check the diversity, in case the diversity percentage is very low we delete a number of the population and we add randome members
            checkDiversity(population, diffPercentage, n, machine_number)

    
    best_result, best_table = calculateMakespan(times, machines, global_best_ind[0], n)           
    print("\nOVERALL RESULT")
    print("RESULT: %s" %best_result)                 
    print('the elapsed time:%ss'% (int(time.time() - start_time)))
    print("Permutation: ")
    print(fromPermutation(global_best_ind[0], n))
    printTable(best_table)
    plotResult(best_table, best_result)
예제 #10
0
파일: DataCard.py 프로젝트: jstupak/VHbb-1
 def toTxt(self, fileName):
     out = open(fileName, 'w')
     printTable(self.data, out)
예제 #11
0
파일: DataCard.py 프로젝트: qunwang/VHbb-1
 def toTxt(self, fileName):
     out=open(fileName,'w')
     printTable(self.data,out)
예제 #12
0
def main():
    """ Main function to run Paper Trail program. """

    # Load database. If none exists, create one.
    papersDir = os.path.dirname(DB_PATH)
    if not os.path.isdir(papersDir):
        os.makedirs(papersDir)
    if os.path.isfile(DB_PATH):
        with open(DB_PATH, 'rb') as f:
            database = pickle.load(f)
    else:
        database = Database()

    # Action loop
    while True:

        print_action_prompt()
        action = input()
        print("")

        if action == '1':

            # Get table name to print.
            print("Enter table name. Should be either 'papers', 'authors', or"\
            " 'topics': ", end="")
            tableName = input()
            while tableName not in ['papers', 'authors', 'topics']:
                print("Invalid table name! Try again: ", end="")
                tableName = input()

            # Call utils to print table
            printTable(database, tableName)

        elif action == '2':

            # Collect paper information from link.
            print("Enter link to paper: ", end="")
            link = input()
            paperArgs = getBibInfo(link)

            # Check for error opening paper.
            if 'err' in paperArgs:
                print("%s\n" % paperArgs['err'])
                continue

            # Get labels from user
            print("Enter topic names separated by commas: ", end="")
            paperArgs['topicNames'] = [
                label.strip() for label in input().split(",")
            ]

            # Get parents from user
            print("Enter name of parent papers. "\
                  "If no parents, just press enter: ", end="")
            parents = input().split()
            while not all([parent in database.papers for parent in parents]):
                print("Unrecognized parent name! Try again:")
                parents = input().split()
            paperArgs['parents'] = parents

            # Get children from user
            print("Enter name of child papers. "\
                  "If no children, just press enter: ", end="")
            children = input().split()
            while not all([child in database.papers for child in children]):
                print("Unrecognized child name! Try again:")
                children = input().split()
            paperArgs['children'] = children

            # Add misc info
            paperArgs['dateAdded'] = datetime.datetime.now().strftime(
                "%m/%d/%Y")
            paperArgs['dateRead'] = ""
            paperArgs['link'] = link
            paperArgs['read'] = False
            paperArgs['notes'] = ""

            # Create paper object and add it to database
            database.addPaper(Paper(**paperArgs))
            print("Paper added!\n")

        elif action == '3':

            # Get name of paper to delete
            print("Name of paper: ", end="")
            paperName = input()

            # Create and execute SQL command
            if paperName in database.papers:
                del database.papers[paperName]
                print("Paper '%s' removed!\n" % paperName)
            else:
                print("Paper '%s' not in database!\n" % paperName)

        else:
            print("Goodbye!\n")
            break

        # Save database
        with open(DB_PATH, 'wb') as f:
            pickle.dump(database, f)