-
Notifications
You must be signed in to change notification settings - Fork 0
/
CondorcetDriver.py
49 lines (36 loc) · 2.53 KB
/
CondorcetDriver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Condorcet
import time
import inspect
def printLine():
print('----------------')
def generateFileName(numPlayers, numPlayersPerGame, discrepancyRange, trial, directory):
fileName = str(directory) + "_discrepancyRange" + str(discrepancyRange) + "_numPlayers" + str(numPlayers) + "_numPlayersPerGame" + str(numPlayersPerGame) + "_trial" + str(trial) + ".txt"
return(fileName)
def trialGenerator(numberOfMachines, machineNumber, firstTrial, numberOfTrials, baseNumPlayersPerGame, discrepancyRangeList, baseNumPlayers, numGames, timeLimitMinutes, directory, targetVar, function):
i = machineNumber # should range between 1 and number of machines
start = time.time()
baseNumGames = numGames
timeLimit = timeLimitMinutes*60
for discrepancyIdx in range(0, len(discrepancyRangeList)):
thisDiscrepancyRange = discrepancyRangeList[discrepancyIdx]
for numPlayersPerGameIdx in range(0, len(baseNumPlayersPerGame)):
thisNumPlayersPerGame = baseNumPlayersPerGame[numPlayersPerGameIdx]
for numPlayerIdx in range (0, len(baseNumPlayers)):
thisNumPlayers = baseNumPlayers[numPlayerIdx]
thisDiscrepancy = thisDiscrepancyRange//thisNumPlayers ##
for trial in range(firstTrial,firstTrial+numberOfTrials):
thisNumGames = baseNumGames
if (i%numberOfMachines == 0):
fileName = generateFileName(thisNumPlayers, thisNumPlayersPerGame, thisDiscrepancyRange, trial, directory)
argspecs = inspect.getargspec(function)
argCount = (len(argspecs.args))
if (argCount == 6):
function(thisNumPlayers, thisNumGames, thisNumPlayersPerGame, thisDiscrepancy, fileName, timeLimit)
elif (argCount == 7):
function(thisNumPlayers, thisNumGames, thisNumPlayersPerGame, thisDiscrepancyRange, fileName, timeLimit, targetVar)
i+=1
end = time.time()
print(end-start)
def DriveSimulator(numberOfMachines, machineNumber, firstTrial, numberOfTrials, baseNumPlayersPerGame, discrepancyRangeList, baseNumPlayers, numGames, timeLimitMinutes, directory, targetVar):
trialGenerator(numberOfMachines, machineNumber, firstTrial, numberOfTrials, baseNumPlayersPerGame, discrepancyRangeList, baseNumPlayers, numGames, timeLimitMinutes, directory, targetVar, Condorcet.simulate)
##DriveSimulator(4, 4, 6, 1)