def pickStartCountry(): ## Move refs from all countries: if graph.vs[0]['NumRefs']<10000: coIDs = range( 38 ) numRefsCos = [] for coid in coIDs: # graph.vs[coid]['NumRefs'] numRefsCos.append( graph.vs[coid]['NumRefs'] ) originCoWeight = [ i/float(sum(numRefsCos)) for i in numRefsCos ] # print originCoWeight return np.random.choice(coIDs, p=originCoWeight) ## Move Refs only from Origin and Transition countries else: coList = COS.originCoList() + COS.transitionCoList() coIDs = []#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 18, 19, 30, 31, 32, 33, 34, 35, 36, 37, 38] numRefsCos = [] for vertex in graph.vs: if vertex['label'] in coList: numRefsCos.append( vertex['NumRefs'] ) coIDs.append( vertex.index ) # for coid in coIDs: # graph.vs[coid]['NumRefs'] # numRefsCos.append( graph.vs[coid]['NumRefs'] ) originCoWeight = [ i/float(sum(numRefsCos)) for i in numRefsCos ] # print originCoWeight return np.random.choice(coIDs, p=originCoWeight)
def selfCostMSIMcalculate(vertex, update=True): # if vertex['NumRefs'] <.0001: # vertex['NumRefs'] = 1 if vertex['label'] in COS.originCoList(): cost = .3 else: n1 = 2 * vertex['SafetyCo'] * \ vertex['Resources'] * \ vertex['NumRefs']**2 adjacents = graph.adjacent( target ) #returns edge labels adjTargets = graph.vs[ graph.es[adjacents]['Target'] ] ## Do the weird pi cumulitive product thing: distSum = 1#1.15 # for distance in graph.es[adjacents]['Distance']: # distSum = distSum + distance # print 'dist is: ', distance, distSum #lnPi = math.log(distProd) numeratorMoneySigma = sum( graph.es[adjacents]['MoneyCost'] ) denomSafetySigma = sum( graph.es[adjacents]['Safety'] ) + \ sum( adjTargets['SafetyCo'] ) denomResourceSigma = sum( adjTargets['Resources'] ) cost = n1 * distSum * numeratorMoneySigma / \ vertex['RefCap'] / denomSafetySigma / denomResourceSigma # vertex['Jessie'] = (n1, vertex['SafetyCo'], vertex['Resources'],vertex['NumRefs']**2) if update==True: vertex['CostSelf'] = cost return cost