Struct ProjectSelectionProblem

Source
pub struct ProjectSelectionProblem { /* private fields */ }

Implementations§

Source§

impl ProjectSelectionProblem

Source

pub fn new(n_project: usize, n_value: usize) -> Self

Source

pub fn with_n_values(n_values: Vec<usize>) -> Self

Source

pub fn add_cost1(&mut self, p: usize, v: usize, c: i64)

Examples found in repository?
crates/competitive/src/graph/project_selection_problem.rs (line 68)
56    pub fn add_cost2<F>(&mut self, p1: usize, p2: usize, mut cost: F)
57    where
58        F: FnMut(usize, usize) -> i64,
59    {
60        debug_assert_ne!(p1, p2);
61        let nv1 = self.n_values[p1];
62        let nv2 = self.n_values[p2];
63        debug_assert_ne!(nv1, 0);
64        debug_assert_ne!(nv2, 0);
65        let c00 = cost(0, 0);
66        self.totalcost += c00;
67        for v1 in 1usize..nv1 {
68            self.add_cost1(p1, v1, cost(v1, 0) - c00);
69        }
70        for v2 in 1usize..nv2 {
71            self.add_cost1(p2, v2, cost(0, v2) - c00);
72        }
73        let mut acc = 0i64;
74        for v1 in 1usize..nv1 {
75            for v2 in 1usize..nv2 {
76                let c = cost(v1 - 1, v2) + cost(v1, v2 - 1) - cost(v1, v2) - cost(v1 - 1, v2 - 1);
77                debug_assert!(c >= 0, "cost is not monge");
78                let key = (self.start[p1] + v1 - 1, self.start[p2] + v2 - 1);
79                if c > 0 {
80                    *self.cost2.entry(key).or_default() += c as u64;
81                }
82                acc -= c;
83            }
84            self.add_cost1(p1, v1, acc);
85        }
86    }
Source

pub fn add_cost2_01( &mut self, p1: usize, p2: usize, v1: usize, v2: usize, c: u64, )

x1 >= v1 && x2 < v2 (0 < v1 < nv1, 0 < v2 < nv2)

Examples found in repository?
crates/competitive/src/graph/project_selection_problem.rs (line 53)
52    pub fn add_cost2_10(&mut self, p1: usize, p2: usize, v1: usize, v2: usize, c: u64) {
53        self.add_cost2_01(p2, p1, v2, v1, c);
54    }
Source

pub fn add_cost2_10( &mut self, p1: usize, p2: usize, v1: usize, v2: usize, c: u64, )

x1 < v1 && x2 >= v2 (0 < v1 < nv1, 0 < v2 < nv2)

Source

pub fn add_cost2<F>(&mut self, p1: usize, p2: usize, cost: F)
where F: FnMut(usize, usize) -> i64,

cost is monge: cost(v1-1, v2) + cost(v1, v2-1) >= cost(v1, v2) + cost(v1-1, v2-1)

Source

pub fn solve(&self) -> (i64, Vec<usize>)

Trait Implementations§

Source§

impl Clone for ProjectSelectionProblem

Source§

fn clone(&self) -> ProjectSelectionProblem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProjectSelectionProblem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProjectSelectionProblem

Source§

fn default() -> ProjectSelectionProblem

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.