Esempio n. 1
0
def obtainClasses(dL, runL, agt):
  agtCl = []
  r0 = s0.newState()  
  for d in dL:
    r0.deal = d
    r1 = r0.execRun(runL)
    bDeals = ut.sortDeals(r1.getAgtDeals(agt))
    agtCl.append(bDeals)
  return agtCl
Esempio n. 2
0
def computeLeakage(run, agt):
  result = {}
  tmLst = []
  leakedLst  = []
  r0 = s0.newState()
  # Evaluate only for those deals that 
  # can truthfully announce run
  deals = s0.run2Deals(run) 
  deals = ut.sortDeals(deals)
  pDeals = {}
  for d in deals:
    r0.deal = d
    s = time.time() 
    rF = r0.execRun(run)
    cL = rF.getCards(agt)
    e = time.time()
    tmLst.append(e-s)
    leakedLst.append(cL)
  # For computing possible deals according to agt
  #    The component according to agt.
  r0 = s0.newState()
  r0.deal = deals[0] 
  # Sufficient to compute for first deal
  #   as all deals will a) have the same hand for agt
  #                     b) for each of those deals, agt considers the same set to be possible.
  rFinal = r0.execRun(run)
  dKey = ut.deal2Key(d)
  pDList = rFinal.getAgtDeals(agt)
  pDeals = []
  for pd in pDList:
    pdKey = ut.deal2Key(pd)
    pDeals.append(pdKey)
  dealsUniverse = [dList]
  runPre = []
  for ann in run:
    runPre.append(ann)
    dealsUniverse.append(s0.run2Deals(runPre))
  result['dList'] = deals
  result['timings'] = tmLst
  result['leakage'] = leakedLst
  nLeaked = []
  for l in leakedLst:
    nLeaked.append(len(l))
  result['nLeaked']   = nLeaked
  result['publicLst'] = dealsUniverse # How the set of deals changes publicly.
  # Possible Deals that agt thinks to be possible.
  result['possibleDeals'] = pDeals
  return result
Esempio n. 3
0
def BCView(deal, ann):
  '''The BC connected part of model after 
  ann is announced starting from deal.'''
  cview = CView(deal, ann) # First get C's set.
  resView = []
  for d in cview:
    r0 = s0.newState()
    r0.deal = d
    r1 = r0.updateAnn(ann)
    bL = r1.getAgtDeals('b')
    i, found = 0, False
    for d1 in bL:
      while i < len(resView) and not found:
        currD = resView[i]
        if not isDistinct(currD, d1):
          found = True
        i = i + 1
      if not found:
        resView.append(d1)
  resView = ut.sortDeals(resView)
  return resView
Esempio n. 4
0
import cpUtil as ut; 

deal = {'a' : [0, 1, 2, 3], 'b':[4, 5, 6, 7], 'c':[8,9] };
infAgts, eaves = ['a', 'b'],'c';
rus442 = cps.cpState([4, 4, 2], ['a','b', 'c'], deal, infAgts, eaves);

aCards = [[0], [1], [2], [3]]; 
A0 = ut.allHands(4, range(4,10)); 
A1 = ut.allHands(3, range(4,10)); 
aL = ut.crossProduct(aCards, A1, ''); 
aL = [[0,1,2,3]] + aL + A0; 
annA = ('a', aL); run = [annA]; 

s0 = rus442.updateAnn(annA); 
altC = s0.getAgtDeals('c'); 
altC = ut.sortDeals(altC);

aH = ut.allHands(4, range(10))

def nonHand(hand):
  '''
  All cards not in hand
  '''
  cLst = range(10)
  nH = []
  for c in cLst:
    if not c in hand:
      nH.append(c)
  return nH

def maxInfFor(hand):
Esempio n. 5
0
import cpState as cps
import cpUtil as ut

deal = {
    'a': [0, 1, 2, 3],
    'b': [4, 5, 6, 7],
    'c': [8, 9]
}
infAgts, eaves = ['a', 'b'], 'c'
rus442 = cps.cpState([4, 4, 2], ['a', 'b', 'c'], deal, infAgts, eaves)

s0 = rus442.newState()
dList = s0.fml2Deals(cps.z3.And(True))
dList = ut.sortDeals(dList)

ann1L = [[0,1,2,3], [0,1,4,5], [0,2,6,7], [0,3,8,9], [0,4,6,8],\
         [0,5,7,9], [1,2,8,9], [1,3,6,7], [1,4,7,9], [1,5,6,8],\
         [2,3,4,5], [2,4,7,8], [2,5,6,9], [3,4,6,9], [3,5,7,8]]

f1 = ut.ann2DealFml('a', ann1L)
f = cps.z3.Not(f1)
dList1 = s0.fml2Deals(f)
dList1 = ut.sortDeals(dList1)

import pickle as pk
f = open('rcp442-Deals.txt', 'w')
pk.dump(dList, f)
f.close()

f = open('rcp442-Rest1.txt', 'w')
pk.dump(dList1, f)