pub struct ProjectSelectionProblem { /* private fields */ }
Implementations§
Source§impl ProjectSelectionProblem
impl ProjectSelectionProblem
pub fn new(n_project: usize, n_value: usize) -> Self
pub fn with_n_values(n_values: Vec<usize>) -> Self
Sourcepub fn add_cost1(&mut self, p: usize, v: usize, c: i64)
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 }
Sourcepub fn add_cost2_01(
&mut self,
p1: usize,
p2: usize,
v1: usize,
v2: usize,
c: u64,
)
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)
Sourcepub fn add_cost2_10(
&mut self,
p1: usize,
p2: usize,
v1: usize,
v2: usize,
c: u64,
)
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)
Sourcepub fn add_cost2<F>(&mut self, p1: usize, p2: usize, cost: F)
pub fn add_cost2<F>(&mut self, p1: usize, p2: usize, cost: F)
cost is monge: cost(v1-1, v2) + cost(v1, v2-1) >= cost(v1, v2) + cost(v1-1, v2-1)
pub fn solve(&self) -> (i64, Vec<usize>)
Trait Implementations§
Source§impl Clone for ProjectSelectionProblem
impl Clone for ProjectSelectionProblem
Source§fn clone(&self) -> ProjectSelectionProblem
fn clone(&self) -> ProjectSelectionProblem
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ProjectSelectionProblem
impl Debug for ProjectSelectionProblem
Source§impl Default for ProjectSelectionProblem
impl Default for ProjectSelectionProblem
Source§fn default() -> ProjectSelectionProblem
fn default() -> ProjectSelectionProblem
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ProjectSelectionProblem
impl RefUnwindSafe for ProjectSelectionProblem
impl Send for ProjectSelectionProblem
impl Sync for ProjectSelectionProblem
impl Unpin for ProjectSelectionProblem
impl UnwindSafe for ProjectSelectionProblem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more