Coverage(Solver) - Puts solver at 76% coverage

This commit is contained in:
Dandaedre 2023-03-07 07:58:12 +01:00
parent fc5cce934a
commit 539a14a4fc
9 changed files with 302 additions and 27 deletions

View File

@ -21,7 +21,7 @@ script = [
[tasks.fmt]
script_runner = "@shell"
script = [
"cargo +nightly fmt -- --config format_code_in_doc_comments=true"
"cargo +nightly fmt -- --config format_code_in_doc_comments=true --config imports_granularity=Module"
]
[tasks.testcov]

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%">
<title>coverage: 56%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%">
<title>coverage: 69%</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
@ -16,8 +16,8 @@
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">56%</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">56%</text>
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">69%</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">69%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,13 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%">
<title>coverage: 56%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%">
<title>coverage: 69%</title>
<g shape-rendering="crispEdges">
<rect width="61" height="20" fill="#555"/>
<rect x="61" width="35" height="20" fill="#e05d44"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">56%</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">69%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 712 B

View File

@ -1,13 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 56%">
<title>COVERAGE: 56%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 69%">
<title>COVERAGE: 69%</title>
<g shape-rendering="crispEdges">
<rect width="91" height="28" fill="#555"/>
<rect x="91" width="51.5" height="28" fill="#e05d44"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="100">
<text fill="#fff" x="455" y="175" transform="scale(.1)" textLength="670">COVERAGE</text>
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">56%</text>
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">69%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 739 B

After

Width:  |  Height:  |  Size: 739 B

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 56%">
<title>coverage: 56%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 69%">
<title>coverage: 69%</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
@ -18,8 +18,8 @@
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="315" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
<text x="315" y="130" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">56%</text>
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">56%</text>
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">69%</text>
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">69%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 56%">
<title>Coverage: 56%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 69%">
<title>Coverage: 69%</title>
<style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style>
<linearGradient id="a" x2="0" y2="100%">
<stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/>
@ -20,8 +20,8 @@
<rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="61" height="19" rx="2"/>
<text aria-hidden="true" x="305" y="150" fill="#fff" transform="scale(.1)" textLength="510">Coverage</text>
<text x="305" y="140" transform="scale(.1)" textLength="510">Coverage</text>
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">56%</text>
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">56%</text>
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">69%</text>
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">69%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -210,6 +210,33 @@ impl<'a> Craft<'a> {
},
)
}
/// Create a "Three start" craft, testing only
pub fn three_star() -> Craft<'a> {
Self::new(
crate::specs::Recipe {
durability: 70,
progress: 3900,
quality: 10920,
progress_divider: 130,
quality_divider: 115,
progress_modifier: 80,
quality_modifier: 70,
},
crate::specs::Stats {
craftsmanship: 4041,
control: 3971,
max_cp: 595,
},
crate::io::Parameters {
threads: 8,
verbose: 2,
depth: 8,
desperate: false,
byregot_step: 10,
},
)
}
}
#[cfg(test)]

View File

@ -96,12 +96,9 @@
#![warn(missing_docs)]
use crate::io::SolverResult;
use crate::{
craft::Craft,
io::Parameters,
specs::{Recipe, Stats},
};
use crate::craft::Craft;
use crate::io::{Parameters, SolverResult};
use crate::specs::{Recipe, Stats};
use std::sync::{Arc, Mutex};
use threadpool::ThreadPool;

View File

@ -16,7 +16,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
let mut available_actions = Vec::<Option<&'a Action>>::new();
let mut forbidden_actions = Vec::<Option<&'a Action>>::new();
// Optimize the first three steps for massive time save
// Optimize the first four steps for massive time save
if craft.step_count == 0 {
return action_vec![ACTIONS.muscle_memory];
}
@ -65,7 +65,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec<Option<&'a Action>> {
}
// For long first run
if craft.step_count > 8 {
if craft.step_count > 8 && craft.buffs.waste_not == 0 {
available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not])
};
@ -246,3 +246,254 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
top_routes.push(top_route);
Some(top_routes)
}
#[cfg(test)]
mod test {
use crate::solver::{generate_routes_phase1, next_action_picker_1, ACTIONS};
#[test]
pub fn test_first_step() {
let mut craft = crate::craft::Craft::three_star();
// Try a failed craft
craft.success = crate::specs::Success::Failure;
let vact = next_action_picker_1(&craft);
assert_eq!(vact, vec![None]);
craft.success = crate::specs::Success::Pending;
// Try the first 4 steps
let vact = next_action_picker_1(&craft);
assert_eq!(vact, action_vec![ACTIONS.muscle_memory]);
craft.run_action(&ACTIONS.muscle_memory);
let vact = next_action_picker_1(&craft);
assert_eq!(vact, action_vec![ACTIONS.manipulation]);
craft.run_action(&ACTIONS.manipulation);
let vact = next_action_picker_1(&craft);
assert_eq!(vact, action_vec![ACTIONS.veneration]);
craft.run_action(&ACTIONS.veneration);
let vact = next_action_picker_1(&craft);
assert_eq!(vact, action_vec![ACTIONS.waste_not_ii, ACTIONS.groundwork]);
craft.run_action(&ACTIONS.waste_not_ii);
// Try the steps 5-8, deterministically
let vact = next_action_picker_1(&craft);
assert_eq!(vact, action_vec![ACTIONS.groundwork]);
craft.run_action(&ACTIONS.careful_synthesis);
let vact = next_action_picker_1(&craft);
assert_eq!(
vact,
action_vec![
ACTIONS.groundwork,
ACTIONS.basic_synthesis,
ACTIONS.careful_synthesis,
ACTIONS.delicate_synthesis
]
);
craft.run_action(&ACTIONS.careful_synthesis);
let vact = next_action_picker_1(&craft);
assert_eq!(
vact,
action_vec![
ACTIONS.groundwork,
ACTIONS.basic_synthesis,
ACTIONS.careful_synthesis,
ACTIONS.delicate_synthesis
]
);
craft.run_action(&ACTIONS.careful_synthesis);
let vact = next_action_picker_1(&craft);
assert_eq!(
vact,
action_vec![
ACTIONS.groundwork,
ACTIONS.basic_synthesis,
ACTIONS.careful_synthesis,
ACTIONS.delicate_synthesis
]
);
craft.run_action(&ACTIONS.careful_synthesis);
// Check odd parameters
craft.buffs.waste_not = 0;
craft.progression = 0;
let vact = next_action_picker_1(&craft);
assert_eq!(
vact,
action_vec![
ACTIONS.basic_synthesis,
ACTIONS.careful_synthesis,
ACTIONS.prudent_synthesis,
ACTIONS.delicate_synthesis
]
);
craft.run_action(&ACTIONS.delicate_synthesis);
let vact = next_action_picker_1(&craft);
assert_eq!(
vact,
action_vec![
ACTIONS.basic_synthesis,
ACTIONS.careful_synthesis,
ACTIONS.prudent_synthesis,
ACTIONS.delicate_synthesis,
ACTIONS.waste_not_ii,
ACTIONS.waste_not
]
);
craft.args.desperate = true;
let vact = next_action_picker_1(&craft);
assert_eq!(
vact,
action_vec![
ACTIONS.basic_synthesis,
ACTIONS.careful_synthesis,
ACTIONS.prudent_synthesis,
ACTIONS.delicate_synthesis,
ACTIONS.groundwork,
ACTIONS.masters_mend,
ACTIONS.waste_not_ii,
ACTIONS.waste_not
]
);
}
#[test]
pub fn test_routes_p1() {
let craft = crate::craft::Craft::three_star();
let mut routes1 = generate_routes_phase1(craft);
for route in routes1.iter() {
println!("{:?}", route.actions);
}
// Literrally any change will break it
// An eq should be implmented to just check a vector of vector versus a route
assert_eq!(routes1.len(), 9);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.waste_not_ii,
&ACTIONS.groundwork,
&ACTIONS.delicate_synthesis,
&ACTIONS.delicate_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.waste_not_ii,
&ACTIONS.groundwork,
&ACTIONS.delicate_synthesis,
&ACTIONS.basic_synthesis,
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.waste_not_ii,
&ACTIONS.groundwork,
&ACTIONS.careful_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.waste_not_ii,
&ACTIONS.groundwork,
&ACTIONS.basic_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.groundwork,
&ACTIONS.delicate_synthesis,
&ACTIONS.delicate_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.groundwork,
&ACTIONS.delicate_synthesis,
&ACTIONS.basic_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.groundwork,
&ACTIONS.prudent_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.groundwork,
&ACTIONS.careful_synthesis
]
);
let route = routes1.pop().unwrap();
assert_eq!(
route.actions,
vec![
&ACTIONS.muscle_memory,
&ACTIONS.manipulation,
&ACTIONS.veneration,
&ACTIONS.groundwork,
&ACTIONS.basic_synthesis
]
);
let route = routes1.pop();
match route {
None => (),
Some(..) => panic!(),
}
}
}