mirror of
https://github.com/samsapti/bachelor-project.git
synced 2024-11-21 20:37:55 +00:00
Read data as input for Matchmaker
This commit is contained in:
parent
58c7c2857b
commit
70c25542b1
|
@ -7,7 +7,7 @@ from Compiler.util import *
|
|||
from Compiler.oram import OptimalORAM
|
||||
|
||||
from Compiler.library import for_range, do_while, time, if_, print_ln, crash, print_str
|
||||
from Compiler.gs import OMatrix, OMatrixRow, OStack
|
||||
from Compiler.gs import OMatrix, OStack
|
||||
|
||||
|
||||
class Matchmaker:
|
||||
|
@ -103,44 +103,39 @@ class Matchmaker:
|
|||
print('match', N, M)
|
||||
|
||||
|
||||
""" CONSTANTS """
|
||||
|
||||
# Constants
|
||||
PLAYERS = 3
|
||||
MATCHING_SIZE = 2
|
||||
|
||||
|
||||
""" Assembling lists """
|
||||
MATCHING_SIZE = 5
|
||||
|
||||
p_shares = Matrix(rows=PLAYERS, columns=MATCHING_SIZE, value_type=types.sint)
|
||||
t_shares = Matrix(rows=PLAYERS, columns=MATCHING_SIZE, value_type=types.sint)
|
||||
|
||||
# Fill data from players into the patient matrix
|
||||
# Fill data from players into the matrices
|
||||
# The matrix is ordered as m[row:player][col:share]
|
||||
@for_range(PLAYERS)
|
||||
def _(i):
|
||||
@for_range(MATCHING_SIZE)
|
||||
def _(j):
|
||||
p_shares[i][j] = sint.get_input_from(i)
|
||||
p_index = MemValue(cint(0))
|
||||
t_index = MemValue(cint(0))
|
||||
|
||||
# Fill data from players into the therapist matrix
|
||||
# The matrix is ordered as m[row:player][col:share]
|
||||
@for_range(PLAYERS)
|
||||
def _(i):
|
||||
@for_range(MATCHING_SIZE)
|
||||
def _(j):
|
||||
t_shares[i][j] = sint.get_input_from(i)
|
||||
@do_while
|
||||
def _():
|
||||
try:
|
||||
typ = sint.get_input_from(i)
|
||||
|
||||
@for_range(PLAYERS)
|
||||
def _(i):
|
||||
@for_range(MATCHING_SIZE)
|
||||
def _(j):
|
||||
print_ln('input from player %s: %s', i, p_shares[i][j].reveal())
|
||||
@if_e(typ == -100)
|
||||
def _():
|
||||
p_shares[i][p_index.read()] = sint.get_input_from(i)
|
||||
p_index.iadd(1)
|
||||
@else_
|
||||
def _():
|
||||
@if_(typ == -200)
|
||||
def _():
|
||||
t_shares[i][t_index.read()] = sint.get_input_from(i)
|
||||
t_index.iadd(1)
|
||||
|
||||
@for_range(PLAYERS)
|
||||
def _(i):
|
||||
@for_range(MATCHING_SIZE)
|
||||
def _(j):
|
||||
print_ln('input from player %s: %s', i, t_shares[i][j].reveal())
|
||||
return 1
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
# Add entire column together to reveal secret-shared input
|
||||
p_cases = OMatrix(N=MATCHING_SIZE, M=1, oram_type=OptimalORAM, int_type=types.sint)
|
||||
|
@ -148,12 +143,8 @@ t_exps = OMatrix(N=MATCHING_SIZE, M=1, oram_type=OptimalORAM, int_type=types.sin
|
|||
|
||||
@for_range(MATCHING_SIZE)
|
||||
def _(i):
|
||||
p_val = sum(p_shares.get_column(i))
|
||||
p_cases[i][0] = p_val
|
||||
t_val = sum(t_shares.get_column(i))
|
||||
t_exps[i][0] = t_val
|
||||
print_ln('p_res: %s', p_val.reveal())
|
||||
print_ln('t_res: %s', t_val.reveal())
|
||||
p_cases[i][0] = sum(p_shares.get_column(i))
|
||||
t_exps[i][0] = sum(t_shares.get_column(i))
|
||||
|
||||
mm = Matchmaker(MATCHING_SIZE, p_cases, t_exps)
|
||||
mm.match()
|
||||
|
|
47
src/gen_data.sh
Executable file
47
src/gen_data.sh
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
patient_pref() {
|
||||
printf '%d %d' "-100" "$1"
|
||||
}
|
||||
|
||||
therapist_pref() {
|
||||
printf '%d %d' "-200" "$1"
|
||||
}
|
||||
|
||||
secret_share() {
|
||||
local secret="$1"
|
||||
share_0="$(( RANDOM % (secret / 2 + 1) ))"
|
||||
share_1="$(( RANDOM % (secret / 2 + 1) ))"
|
||||
share_2="$(( secret - (share_0 + share_1) ))"
|
||||
}
|
||||
|
||||
declare -a p_data_0
|
||||
declare -a p_data_1
|
||||
declare -a p_data_2
|
||||
declare -a t_data_0
|
||||
declare -a t_data_1
|
||||
declare -a t_data_2
|
||||
|
||||
max_index=5
|
||||
|
||||
for _ in $(seq "$1"); do
|
||||
rand="$(( (RANDOM % max_index) + 1 ))"
|
||||
secret_share "$rand"
|
||||
|
||||
p_data_0+=("$(patient_pref $share_0)")
|
||||
p_data_1+=("$(patient_pref $share_1)")
|
||||
p_data_2+=("$(patient_pref $share_2)")
|
||||
done
|
||||
|
||||
for _ in $(seq "$1"); do
|
||||
rand="$(( (RANDOM % max_index) + 1 ))"
|
||||
secret_share "$rand"
|
||||
|
||||
t_data_0+=("$(therapist_pref $share_0)")
|
||||
t_data_1+=("$(therapist_pref $share_1)")
|
||||
t_data_2+=("$(therapist_pref $share_2)")
|
||||
done
|
||||
|
||||
for i in $(seq 0 2); do
|
||||
eval 'echo "${p_data_'$i'[*]} ${t_data_'$i'[*]}" > MP-SPDZ/Player-Data/Input-P'$i'-0'
|
||||
done
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/usr/bin/env sh
|
||||
|
||||
MACHINE="$1"
|
||||
shift
|
||||
|
|
Loading…
Reference in a new issue