mirror of
https://github.com/samsapti/bachelor-project.git
synced 2024-11-25 06:17:55 +00:00
Avoid warnings
This commit is contained in:
parent
8b34b64f16
commit
ff6dec081d
|
@ -1,12 +1,13 @@
|
||||||
from MP_SPDZ.Compiler import types
|
# vim: ft=python
|
||||||
|
|
||||||
from MP_SPDZ.Compiler.util import *
|
from Compiler import types
|
||||||
|
|
||||||
from MP_SPDZ.Compiler.oram import OptimalORAM
|
from Compiler.util import *
|
||||||
|
|
||||||
from MP_SPDZ.Compiler.library import for_range, do_while, time, \
|
from Compiler.oram import OptimalORAM
|
||||||
if_, print_ln, crash, print_str
|
|
||||||
from MP_SPDZ.Compiler.gs import OMatrix, OStack
|
from Compiler.library import for_range, do_while, time, if_, print_ln, crash, print_str
|
||||||
|
from Compiler.gs import OMatrix, OStack
|
||||||
|
|
||||||
|
|
||||||
class Matchmaker:
|
class Matchmaker:
|
||||||
|
@ -16,22 +17,26 @@ class Matchmaker:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def init_easy(self):
|
def init_easy(self):
|
||||||
self.m_prefs = OMatrix(self.N, self.M, oram_type=self.oram_type, \
|
self.m_prefs = OMatrix(self.N, self.M, oram_type=self.oram_type,
|
||||||
int_type=self.int_type)
|
int_type=self.int_type)
|
||||||
|
|
||||||
@for_range(self.N)
|
@for_range(self.N)
|
||||||
def f(i):
|
def f(i):
|
||||||
time()
|
time()
|
||||||
types.cint(i).print_reg('mpre')
|
types.cint(i).print_reg('mpre')
|
||||||
|
|
||||||
@for_range(self.M)
|
@for_range(self.M)
|
||||||
def f(j):
|
def f(j):
|
||||||
self.m_prefs[i][j] = (i + j) % self.N
|
self.m_prefs[i][j] = (i + j) % self.N
|
||||||
|
|
||||||
self.f_ranks = OMatrix(self.N, oram_type=self.oram_type, \
|
self.f_ranks = OMatrix(self.N, oram_type=self.oram_type,
|
||||||
int_type=self.int_type)
|
int_type=self.int_type)
|
||||||
|
|
||||||
@for_range(self.N)
|
@for_range(self.N)
|
||||||
def f(i):
|
def f(i):
|
||||||
time()
|
time()
|
||||||
types.cint(i).print_reg('fran')
|
types.cint(i).print_reg('fran')
|
||||||
|
|
||||||
@for_range(self.M)
|
@for_range(self.M)
|
||||||
def f(j):
|
def f(j):
|
||||||
self.f_ranks[i][(j - i + self.N) % self.N] = j
|
self.f_ranks[i][(j - i + self.N) % self.N] = j
|
||||||
|
@ -71,10 +76,10 @@ class Matchmaker:
|
||||||
leaving = self.int_type(rank_man) < self.int_type(rank_fiance)
|
leaving = self.int_type(rank_man) < self.int_type(rank_fiance)
|
||||||
if self.M < self.N:
|
if self.M < self.N:
|
||||||
leaving = 1 - (1 - leaving) * (1 - worst_fiance)
|
leaving = 1 - (1 - leaving) * (1 - worst_fiance)
|
||||||
print_str('woman: %s, man: %s, fiance: %s, worst fiance: %s, ', \
|
print_str('woman: %s, man: %s, fiance: %s, worst fiance: %s, ',
|
||||||
*(x.reveal() for x in (woman, man, fiance, worst_fiance)))
|
*(x.reveal() for x in (woman, man, fiance, worst_fiance)))
|
||||||
print_ln('rank man: %s, rank fiance: %s, engaged: %s, leaving: %s', \
|
print_ln('rank man: %s, rank fiance: %s, engaged: %s, leaving: %s',
|
||||||
*(x.reveal() for x in \
|
*(x.reveal() for x in
|
||||||
(rank_man, rank_fiance, engaged, leaving)))
|
(rank_man, rank_fiance, engaged, leaving)))
|
||||||
self.dump(fiance, woman, engaged * leaving * for_real)
|
self.dump(fiance, woman, engaged * leaving * for_real)
|
||||||
self.engage(man, woman, (1 - (engaged * (1 - leaving))) * for_real)
|
self.engage(man, woman, (1 - (engaged * (1 - leaving))) * for_real)
|
||||||
|
@ -89,20 +94,22 @@ class Matchmaker:
|
||||||
loop = for_range(n_loops)
|
loop = for_range(n_loops)
|
||||||
init_rounds = n_loops / self.M
|
init_rounds = n_loops / self.M
|
||||||
self.wives = \
|
self.wives = \
|
||||||
self.oram_type(self.N, entry_size=log2(self.N), \
|
self.oram_type(self.N, entry_size=log2(self.N),
|
||||||
init_rounds=0, value_type=self.basic_type)
|
init_rounds=0, value_type=self.basic_type)
|
||||||
self.husbands = \
|
self.husbands = \
|
||||||
self.oram_type(self.N, entry_size=log2(self.N), \
|
self.oram_type(self.N, entry_size=log2(self.N),
|
||||||
init_rounds=0, value_type=self.basic_type)
|
init_rounds=0, value_type=self.basic_type)
|
||||||
propose = \
|
propose = \
|
||||||
self.oram_type(self.N, entry_size=log2(self.N), \
|
self.oram_type(self.N, entry_size=log2(self.N),
|
||||||
init_rounds=0, value_type=self.basic_type)
|
init_rounds=0, value_type=self.basic_type)
|
||||||
self.unengaged = OStack(self.N, oram_type=self.oram_type, \
|
self.unengaged = OStack(self.N, oram_type=self.oram_type,
|
||||||
int_type=self.int_type)
|
int_type=self.int_type)
|
||||||
|
|
||||||
@for_range(init_rounds)
|
@for_range(init_rounds)
|
||||||
def f(i):
|
def f(i):
|
||||||
self.unengaged.append(i)
|
self.unengaged.append(i)
|
||||||
rounds = types.MemValue(types.regint(0))
|
rounds = types.MemValue(types.regint(0))
|
||||||
|
|
||||||
@loop
|
@loop
|
||||||
def f(i=None):
|
def f(i=None):
|
||||||
rounds.iadd(1)
|
rounds.iadd(1)
|
||||||
|
@ -119,17 +126,18 @@ class Matchmaker:
|
||||||
propose[man] = pref + 1
|
propose[man] = pref + 1
|
||||||
# self.husbands.ram[0].x[0].reveal().print_reg('l')
|
# self.husbands.ram[0].x[0].reveal().print_reg('l')
|
||||||
self.propose(man, self.m_prefs[man][pref], True)
|
self.propose(man, self.m_prefs[man][pref], True)
|
||||||
print_ln('man: %s, pref: %s, left: %s', \
|
print_ln('man: %s, pref: %s, left: %s',
|
||||||
*(x.reveal() for x in (man, pref, self.unengaged.size)))
|
*(x.reveal() for x in (man, pref, self.unengaged.size)))
|
||||||
# self.wives[man].reveal().print_reg('wife')
|
# self.wives[man].reveal().print_reg('wife')
|
||||||
return types.regint((self.unengaged.size > 0).reveal())
|
return types.regint((self.unengaged.size > 0).reveal())
|
||||||
print_ln('%s rounds', rounds)
|
print_ln('%s rounds', rounds)
|
||||||
|
|
||||||
@for_range(init_rounds)
|
@for_range(init_rounds)
|
||||||
def f(i):
|
def f(i):
|
||||||
types.cint(i).print_reg('wife')
|
types.cint(i).print_reg('wife')
|
||||||
self.husbands[i].reveal().print_reg('husb')
|
self.husbands[i].reveal().print_reg('husb')
|
||||||
|
|
||||||
def __init__(self, N, M=None, reverse=False, oram_type=OptimalORAM, \
|
def __init__(self, N, M=None, reverse=False, oram_type=OptimalORAM,
|
||||||
int_type=types.sint):
|
int_type=types.sint):
|
||||||
self.N = N
|
self.N = N
|
||||||
self.M = N if M is None else M
|
self.M = N if M is None else M
|
Loading…
Reference in a new issue