mirror of
https://github.com/samsapti/bachelor-project.git
synced 2024-11-22 04:47:53 +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.oram import OptimalORAM
|
||||||
|
|
||||||
from Compiler.library import for_range, do_while, time, if_, print_ln, crash, print_str
|
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:
|
class Matchmaker:
|
||||||
|
@ -103,44 +103,39 @@ class Matchmaker:
|
||||||
print('match', N, M)
|
print('match', N, M)
|
||||||
|
|
||||||
|
|
||||||
""" CONSTANTS """
|
# Constants
|
||||||
|
|
||||||
PLAYERS = 3
|
PLAYERS = 3
|
||||||
MATCHING_SIZE = 2
|
MATCHING_SIZE = 5
|
||||||
|
|
||||||
|
|
||||||
""" Assembling lists """
|
|
||||||
|
|
||||||
p_shares = Matrix(rows=PLAYERS, columns=MATCHING_SIZE, value_type=types.sint)
|
p_shares = Matrix(rows=PLAYERS, columns=MATCHING_SIZE, value_type=types.sint)
|
||||||
t_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]
|
# The matrix is ordered as m[row:player][col:share]
|
||||||
@for_range(PLAYERS)
|
@for_range(PLAYERS)
|
||||||
def _(i):
|
def _(i):
|
||||||
@for_range(MATCHING_SIZE)
|
p_index = MemValue(cint(0))
|
||||||
def _(j):
|
t_index = MemValue(cint(0))
|
||||||
p_shares[i][j] = sint.get_input_from(i)
|
|
||||||
|
|
||||||
# Fill data from players into the therapist matrix
|
@do_while
|
||||||
# The matrix is ordered as m[row:player][col:share]
|
def _():
|
||||||
@for_range(PLAYERS)
|
try:
|
||||||
def _(i):
|
typ = sint.get_input_from(i)
|
||||||
@for_range(MATCHING_SIZE)
|
|
||||||
def _(j):
|
|
||||||
t_shares[i][j] = sint.get_input_from(i)
|
|
||||||
|
|
||||||
@for_range(PLAYERS)
|
@if_e(typ == -100)
|
||||||
def _(i):
|
def _():
|
||||||
@for_range(MATCHING_SIZE)
|
p_shares[i][p_index.read()] = sint.get_input_from(i)
|
||||||
def _(j):
|
p_index.iadd(1)
|
||||||
print_ln('input from player %s: %s', i, p_shares[i][j].reveal())
|
@else_
|
||||||
|
def _():
|
||||||
|
@if_(typ == -200)
|
||||||
|
def _():
|
||||||
|
t_shares[i][t_index.read()] = sint.get_input_from(i)
|
||||||
|
t_index.iadd(1)
|
||||||
|
|
||||||
@for_range(PLAYERS)
|
return 1
|
||||||
def _(i):
|
except Exception:
|
||||||
@for_range(MATCHING_SIZE)
|
return 0
|
||||||
def _(j):
|
|
||||||
print_ln('input from player %s: %s', i, t_shares[i][j].reveal())
|
|
||||||
|
|
||||||
# Add entire column together to reveal secret-shared input
|
# Add entire column together to reveal secret-shared input
|
||||||
p_cases = OMatrix(N=MATCHING_SIZE, M=1, oram_type=OptimalORAM, int_type=types.sint)
|
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)
|
@for_range(MATCHING_SIZE)
|
||||||
def _(i):
|
def _(i):
|
||||||
p_val = sum(p_shares.get_column(i))
|
p_cases[i][0] = sum(p_shares.get_column(i))
|
||||||
p_cases[i][0] = p_val
|
t_exps[i][0] = sum(t_shares.get_column(i))
|
||||||
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())
|
|
||||||
|
|
||||||
mm = Matchmaker(MATCHING_SIZE, p_cases, t_exps)
|
mm = Matchmaker(MATCHING_SIZE, p_cases, t_exps)
|
||||||
mm.match()
|
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"
|
MACHINE="$1"
|
||||||
shift
|
shift
|
||||||
|
|
Loading…
Reference in a new issue