danturin #3

Merged
Dandaedre merged 2 commits from danturin into maturin 2023-02-21 23:02:26 +01:00
6 changed files with 24 additions and 26 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
/target
/.idea
*.iml
expected_values.md
# Byte-compiled / optimized / DLL files
__pycache__/

View File

@ -31,7 +31,8 @@ lto = true
[features]
default = []
verbose = []
no_python = []
no_python = [] # Removes the python bindings
fast = [] # Remove some under optimisations that try to find other routes
[lib]
name = "xiv_craft_solver"

View File

@ -157,11 +157,11 @@ impl SolverResult{
impl Parameters{
pub fn from_args(args:& Args) -> Self{
Self{
depth: if args.desperate{10}else{8},
depth: if args.desperate{11}else{8},
threads: args.threads,
verbose: args.verbose,
desperate: args.desperate,
byregot_step: if args.long{8}else{10}
byregot_step: if args.long{6}else{8}
}
}
}

View File

@ -23,7 +23,6 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
#[cfg(feature = "verbose")]
if params.verbose>0{
println!("Solving...\n");
println!("[P1] Starting phase 1...");
}
@ -45,9 +44,9 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
let _phase2_routes = Arc::clone(&arc_phase2_routes);
pool.execute(move || {
if let Some(_route) = solver::generate_routes_phase2(route){
if let Some(mut _route) = solver::generate_routes_phase2(route){
let mut shared = _phase2_routes.lock().unwrap();
shared.push(_route);
shared.append(&mut _route);
};
});
}
@ -71,11 +70,11 @@ pub fn solve_craft<'a>(recipe: Recipe, stats: Stats, params: Parameters) -> Opti
}
// Prune the results for analysis
let mut valid_routes : Vec<Craft> = vec![];
// let mut valid_routes : Vec<Craft> = vec![];
let mut valid_solutions: Vec<SolverResult> = vec![];
for route in phase2_routes.iter(){
if route.quality>=route.recipe.quality{
valid_routes.push(route.clone());
// valid_routes.push(route.clone());
valid_solutions.push(SolverResult::from_craft(route,nb_p1,nb_p2,true));
}
}
@ -171,12 +170,7 @@ pub fn find_fast_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResu
match routes {
Some(_routes) => {
if _routes.len()>0{
//if _routes[0].found_100_percent {
_routes.iter().min_by_key(|key| key.steps)
//} else {
// If the quality didn't reach 100% the fastest is meaningless
// find_quality_route(routes)
//}
_routes.iter().min_by_key(|key| key.steps)
} else { None }
},
None => None,
@ -196,12 +190,7 @@ pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> Option<&SolverResu
match routes {
Some(_routes) => {
if _routes.len()>0{
//if _routes[0].found_100_percent{
_routes.iter().max_by_key(|key| key.durability)
//} else {
// If the craft didn't reach 100% quality the durability is meaningless
// find_quality_route(routes)
//}
_routes.iter().max_by_key(|key| key.durability)
} else {
None
}

View File

@ -130,7 +130,7 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
forbidden_actions.push(&ACTIONS.basic_touch);
}
// Todo, allow earlier byregot if the craft can be finished all the same (useless with always optimize on)
if craft.buffs.inner_quiet >= 8 { //craft.args.byregot_step { // 10
if craft.buffs.inner_quiet >= craft.args.byregot_step { // 10
available_actions.push(&ACTIONS.trained_finesse);
available_actions.push(&ACTIONS.great_strides);
}
@ -152,12 +152,13 @@ pub fn next_action_phase_2<'a>(craft: & Craft<'a>) -> Vec<Option<&'a Action>> {
}
/// Apply all actions to the current route
pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Craft<'a>> {
pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Vec<Craft<'a>>> {
let mut queue = VecDeque::new();
// Todo: Return a vec of relevant functions, instead of the most quality one
let mut top_route: Option<Craft<'a>> = Some(craft.clone()); // Default route, no hq on that one
let mut top_routes: Vec<Craft<'a>> = vec![craft.clone()];
queue.push_back(craft);
while !queue.is_empty() {
@ -170,11 +171,18 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Craft<'a>> {
craft.run_action(action.unwrap());
if action.unwrap() == &ACTIONS.byregot_blessing {
if let Some(top_route) = &mut top_route {
#[cfg(not(feature="fast"))]
if top_route.quality>craft.recipe.quality{
top_routes.push(craft.clone()); // Me memory
}
if top_route.quality < craft.quality {
// TODO: Return several routes, doing so will come at a big performance cost
#[cfg(feature="fast")]
top_routes.push(craft.clone());
*top_route = craft;
}
} else {
println!("Why are we here ?");
top_routes.push(craft.clone());
top_route = Some(craft);
}
} else {
@ -182,5 +190,5 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option<Craft<'a>> {
}
}
}
top_route
Some(top_routes)
}