def decide(self, reports, hashes, leader): if self.decision_type == constants.MAJORITY_VOTE_DECISION: return self.incremental_vote(reports) elif self.decision_type == constants.SOCIAL_WELFARE_MAXIMIZING: return self.vcg_selection(reports) elif self.decision_type == constants.MEDIAN_REPORT: return self.median_vote(reports) elif self.decision_type == constants.LOWER_MEDIAN_REPORT: return self.lower_median_vote(reports) elif self.decision_type == constants.UPPER_MEDIAN_REPORT: return self.upper_median_vote(reports) elif self.decision_type == constants.WEIGHTED_MEDIAN_REPORT: return self.weighted_median_vote(reports, hashes) elif self.decision_type == constants.SUPPRESSED_MEDIAN_REPORT: return self.suppressed_median_vote(reports) elif self.decision_type == constants.SUPPRESSED_WEIGHTED_MEDIAN_REPORT: return self.suppressed_weighted_median_vote(reports, hashes) elif self.decision_type == constants.HASHPOWER_CAPACITY_MAXIMIZING: return self.hash_cap_selection(reports, hashes) elif self.decision_type == constants.HASHPOWER_CAPSQUARED_MAXIMIZING: return self.hash_cap_squared_selection(reports, hashes) elif self.decision_type == constants.HASHPOWER_CAPSQRT_MAXIMIZING: return self.hash_cap_sqrt_selection(reports, hashes) elif self.decision_type == constants.LEADER_REPORT: return self.leader_report(leader) elif self.decision_type == constants.BOUNDED_LEADER_REPORT: return self.bounded_leader_report(leader) else: value_error("Unsupported decision type: {}", self.decision_type)
def feasible_reports(self): if self.report_type in [ constants.DIRECTIONAL_REPORT, constants.RANDOM_DIRECTIONAL_REPORT ]: return [0, 1, 2] else: value_error("Unsupported report type {}", self.report_type)
def honest_report(self, parameter): if self.report_type in [ constants.DIRECTIONAL_REPORT, constants.RANDOM_DIRECTIONAL_REPORT ]: return (0 if self.capacity < parameter else 1 if self.capacity == parameter else 2) elif self.report_type == constants.DIRECT_CAPACITY_REPORT: return self.capacity else: value_error("Unsupported report type {}", self.report_type)
def setup_agents(options): if len(options["capacities"]) > 0 and len(options["hashes"]) > 0: return explicit_honest_agents(options["capacities"], options["hashes"], options["report_type"]) if options["agent_mode"] == constants.HONEST_INCREASING_AGENTS: return increasing_node_capacities(options["num_agents"], options["low_capacity"], options["report_type"]) if options["agent_mode"] == constants.HONEST_RANDOM_AGENTS: return random_node_capacities(options["num_agents"], options["low_capacity"], options["high_capacity"], options["report_type"]) value_error("Unsupported agent type: {}", options["agent_mode"])
def selfish_report(self, parameter): if self.report_type == constants.DIRECT_CAPACITY_REPORT: return self.capacity else: value_error("Unsupported report type {}", self.report_type)