use std::marker::PhantomData;
use crate::game::{ExplicitGame, PlayerSet, SetFunction};
use crate::properties;
use crate::solution::{Guarantee, Property, Unverified};
pub trait ProofKind {
type Output<T>;
fn guarantee(property: Property) -> Guarantee;
fn wrap<T>(value: T, property: Property) -> Self::Output<T>;
}
pub enum Proven {}
pub enum Assumed {}
impl ProofKind for Proven {
type Output<T> = T;
fn guarantee(property: Property) -> Guarantee {
Guarantee::Proven(property)
}
fn wrap<T>(value: T, _property: Property) -> T {
value
}
}
impl ProofKind for Assumed {
type Output<T> = Unverified<T>;
fn guarantee(property: Property) -> Guarantee {
Guarantee::Assumed(property)
}
fn wrap<T>(value: T, property: Property) -> Unverified<T> {
Unverified::new(value, property)
}
}
pub trait ConvexGame: SetFunction {
type Proof: ProofKind;
}
#[derive(Clone, Debug, PartialEq)]
pub struct ConvexChecked {
game: ExplicitGame,
}
impl ConvexChecked {
pub fn new(game: ExplicitGame) -> std::result::Result<ConvexChecked, ExplicitGame> {
if properties::is_convex(&game) {
Ok(ConvexChecked { game })
} else {
Err(game)
}
}
pub fn game(&self) -> &ExplicitGame {
&self.game
}
}
impl SetFunction for ConvexChecked {
fn players(&self) -> usize {
self.game.players()
}
fn value(&self, coalition: &PlayerSet) -> f64 {
SetFunction::value(&self.game, coalition)
}
}
impl ConvexGame for ConvexChecked {
type Proof = Proven;
}
pub enum Convexity {}
pub struct Assume<P, G> {
game: G,
marker: PhantomData<fn() -> P>,
}
impl<G> Assume<Convexity, G> {
pub fn convex(game: G) -> Assume<Convexity, G> {
Assume {
game,
marker: PhantomData,
}
}
}
impl<P, G> Assume<P, G> {
pub fn inner(&self) -> &G {
&self.game
}
pub fn into_inner(self) -> G {
self.game
}
}
impl<P, G: SetFunction> SetFunction for Assume<P, G> {
fn players(&self) -> usize {
self.game.players()
}
fn value(&self, coalition: &PlayerSet) -> f64 {
self.game.value(coalition)
}
}
impl<G: SetFunction> ConvexGame for Assume<Convexity, G> {
type Proof = Assumed;
}