def results(self, ballots, **kwargs): """IRV results. >>> Irv().resultsFor(DeterministicModel(3)(5,3),Irv().honBallot)["results"] [0, 1, 2] >>> Irv().results([[0,1,2]])[2] 2 >>> Irv().results([[0,1,2],[2,1,0]])[1] 0 >>> Irv().results([[0,1,2]] * 4 + [[2,1,0]] * 3 + [[1,2,0]] * 2) [2, 0, 1] """ if type(ballots) is not list: ballots = list(ballots) ncand = len(ballots[0]) results = [-1] * ncand piles = [[] for i in range(ncand)] loserpile = ballots loser = -1 for i in range(ncand): self.resort(loserpile, loser, ncand, piles) negscores = ["x" if isnum(pile) else -len(pile) for pile in piles] loser = self.winner(negscores) results[loser] = i loserpile, piles[loser] = piles[loser], -1 return results
def __init__(self,Tag,ListTag=[],ListMeas=[],ListSigma=[],ListFlag=[],ListUnit=[]): if (not (isnum(Tag)) and(len(ListTag)!=0) and (len(ListMeas)!=0) and (len(ListSigma)) and (len(ListFlag)!=0)): if (Tag in ListTag): self.Tag=ListTag[ListTag.index(Tag)] self.Meas=float(ListMeas[ListTag.index(Tag)]) self.Sigma=float(ListSigma[ListTag.index(Tag)]) self.Flag=int(ListFlag[ListTag.index(Tag)]) self.Est=self.Meas self.Sol=self.Meas self.Unit=ListUnit[ListTag.index(Tag)] else: print "Error : in ", Tag," Sensor Tag not found in the Measurement file" elif ((isnum(Tag)) and(len(ListTag)==0) and (len(ListMeas)==0) and (len(ListSigma)==0) and (len(ListFlag)==0) and (len(ListUnit)==0)): ''' You are expected to give the concentration in mole fraction ''' self.Tag=[] self.Meas=Tag self.Est=Tag self.Sigma=1#0.01*Tag self.Flag=1.0 self.Sol=Tag
def winner(results): """Simply find the winner once scores are already calculated. Override for ranked methods. >>> Method().winner([1,2,3,2,-100]) 2 >>> 2 < Method().winner([1,2,1,3,3,3,2,1,2]) < 6 True """ winScore = max([result for result in results if isnum(result)]) winners = [cand for (cand, score) in enumerate(results) if score==winScore] return random.choice(winners)
def setPortNumber(self, portNumber): """ Sets the port number to use with the connection. """ if isnum(portNumber): self._port = portNumber
def isnum_foreach(s): for i in s: if not isnum(i): return 0 else: return 1
print('-107:', end=' ') asal.asalmı_gelismis(-107) print('0:', end=' ') asal.asalmı_gelismis(0) print('1:', end=' ') asal.asalmı_gelismis(1) print('2:', end=' ') asal.asalmı_gelismis(2) print('-1:', end=' ') asal.asalmı_gelismis(-1) print('-2:', end=' ') asal.asalmı_gelismis(-2) print('-11:', end=' ') asal.asalmı_gelismis(-11) print(isnum(1)) print(isnum(-1)) print(isnum('1')) print(isnum('a')) L = [1, 2, 3] print(isnum(L[:])) def isnum_foreach(s): for i in s: if not isnum(i): return 0 else: return 1