1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#[macro_export]
macro_rules! make_run {
( $ProblemDefinition:ty, $StartingPoints:ty, $Parameter:ty, $CostValue:ty ) => {
fn run(
&mut self,
operator: &'a $ProblemDefinition,
init_param: &$StartingPoints,
) -> Result<ArgminResult<$Parameter, $CostValue>> {
self.init(operator, init_param)?;
let mut res;
loop {
res = self.next_iter()?;
if res.terminated {
break;
}
}
Ok(res)
}
}
}
#[macro_export]
macro_rules! make_terminate {
($condition:expr, $reason:path;) => {
if $condition {
return $reason;
}
};
($condition:expr, $reason:path ; $($x: expr, $y:path;)*) => {
make_terminate!( $condition, $reason; );
make_terminate!( $($x, $y;)* );
};
($self:ident, $($x: expr, $y:path;)*) => {
fn terminate(&$self) -> TerminationReason {
make_terminate!( $($x, $y;)* );
TerminationReason::NotTerminated
}
};
}