From a7f04685070434cb91bcef823ec78bd529aca5dd Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 3 Mar 2024 20:05:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E9=9C=80=E8=A6=81=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=A7=A3=E9=87=8A=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 3 ++- src/cacluate.rs | 18 ++++++++++--- src/evaluate/xuping.rs | 10 +++++-- src/evaluate/xuping/eval.rs | 53 +++++++++++++++++++++++++------------ src/main.rs | 2 +- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb30d1c..8ae297f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ simd = [] opt-level = 3 codegen-units = 1 panic = "abort" -debug = false +debug = true +strip = false lto = true overflow-checks = false diff --git a/src/cacluate.rs b/src/cacluate.rs index 342fbba..430b0bc 100644 --- a/src/cacluate.rs +++ b/src/cacluate.rs @@ -1,10 +1,10 @@ -use crate::name::{Namer, TeamNamer}; +use crate::{evaluate::NamerEvaluater, name::{Namer, TeamNamer}}; use std::{io::Write, path::PathBuf}; use base16384::Base16384Utf8; use colored::Colorize; -use tracing::{info, warn}; +use tracing::{debug, info, warn}; pub fn show_name(namer: &Namer) -> String { format!( @@ -59,6 +59,7 @@ pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) { let mut start_time = std::time::Instant::now(); let mut k: u64 = 0; let mut get_count: u32 = 0; + let xuping = crate::evaluate::xuping::XuPing1_3_1::new(5000.0); // 提前准备好 team_namer let team_namer = TeamNamer::new(&config.team).unwrap(); @@ -68,9 +69,20 @@ pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) { let prop = namer.get_property(); if (prop + config.prop_allow as f32) > config.prop_expect as f32 { - get_count += 1; let name = gen_name(i as u64); let full_name = format!("{}@{}", name, config.team); + // 虚评 + // if crate::evaluate::xuping::XuPing1_3_1::evaluate(&namer) { + // continue; + // } + let xu = crate::evaluate::xuping::XuPing1_3_1::evaluate(&namer); + + debug!("Id:{:>15}|{:>5}|{}|{}", i, full_name, xu, show_name(&namer)); + if xu < 5000.0 { + continue; + } + + get_count += 1; info!("Id:{:>15}|{}|{}", i, full_name, show_name(&namer)); // 写入 (写到最后一行) match std::fs::OpenOptions::new() diff --git a/src/evaluate/xuping.rs b/src/evaluate/xuping.rs index c370bf4..cace257 100644 --- a/src/evaluate/xuping.rs +++ b/src/evaluate/xuping.rs @@ -5,13 +5,19 @@ mod model20; use crate::evaluate::NamerEvaluater; use crate::name::Namer; -pub struct XuPing1_3_1; +pub struct XuPing1_3_1 { + pub limit: f64, +} + +impl XuPing1_3_1 { + pub fn new(limit: f64) -> Self { Self { limit } } +} impl NamerEvaluater for XuPing1_3_1 { const NAME: &'static str = "虚评"; const VERSION: &'static str = "1.3.1"; fn evaluate(name: &Namer) -> f64 { eval::predict_13(name) } - fn check(&self, name: &Namer) -> bool { eval::predict_13(name) > 0.0 } + fn check(&self, name: &Namer) -> bool { eval::predict_13(name) > self.limit } } pub struct XuPing2_0_1015; diff --git a/src/evaluate/xuping/eval.rs b/src/evaluate/xuping/eval.rs index 002d54c..e312ed7 100644 --- a/src/evaluate/xuping/eval.rs +++ b/src/evaluate/xuping/eval.rs @@ -5,6 +5,8 @@ use std::simd::f64x64; #[cfg(feature = "simd")] use std::simd::num::SimdFloat; +use tracing::debug; + use crate::evaluate::xuping::model13 as xuping13; use crate::name::Namer; @@ -14,20 +16,21 @@ pub fn predict_13(name: &Namer) -> f64 { memset(st + 8, 0, 35 * sizeof(int)); for (int i = 0; i < 16; i++) if (context::freq[i]) st[context::skill[i] + 8] = context::freq[i]; */ - // 长度取 64, 方便simd填充 - let mut st: [f64; 64] = [0.0; 64]; - for i in 0..7 { - st[i] = name.name_prop[i] as f64; - } - for i in 0..16 { - if name.skl_freq[i] != 0 { - st[name.skl_id[i] as usize + 8] = name.skl_freq[i] as f64; - } - } // use simd - #[cfg(feature = "simd")] + // #[cfg(feature = "simd")] + #[cfg(not(feature = "simd"))] { + let mut st: [f64; 64] = [0.0; 64]; + // 长度取 64, 方便simd填充 + for i in 0..7 { + st[i] = name.name_prop[i] as f64; + } + for i in 0..16 { + if name.skl_freq[i] != 0 { + st[name.skl_id[i] as usize + 8] = name.skl_freq[i] as f64; + } + } // 先准备数据 let mut target = [0_f64; 989]; target[0..43].copy_from_slice(&st[0..43]); @@ -45,28 +48,44 @@ pub fn predict_13(name: &Namer) -> f64 { let simd_module = simds.as_simd_mut::<64>(); let simd_target = target.as_simd_mut::<64>(); // 前面多出来的 - for i in 0..simd_module.0.len() { + for i in 0..simd_module.0.len() - 1 { sum += simd_module.0[i] * simd_target.0[i]; } + debug!("sum = {}", sum); // 主! 体! let mut tmp = f64x64::splat(0.0); - for i in 0..simd_module.1.len() { + for i in 0..simd_module.1.len() - 1 { tmp += simd_module.1[i] * simd_target.1[i]; } sum += tmp.reduce_sum(); + debug!("sum = {}", sum); // 后面多出来的 - for i in 0..simd_module.2.len() { + for i in 0..simd_module.2.len() - 1 { sum += simd_module.2[i] * simd_target.2[i]; } + debug!("sum = {}", sum); } - #[cfg(not(feature = "simd"))] + // #[cfg(not(feature = "simd"))] + #[cfg(feature = "simd")] { + let mut st: [f64; 43] = [0.0; 43]; + // 长度取 64, 方便simd填充 + for i in 0..7 { + st[i] = name.name_prop[i] as f64; + } + for i in 0..16 { + if name.skl_freq[i] != 0 { + st[name.skl_id[i] as usize + 8] = name.skl_freq[i] as f64; + } + } let mut cnt = 0; for i in 0..43 { - sum += st[i] * MODEL[cnt]; + sum += st[i] * xuping13::MODULE[cnt]; cnt += 1; + } + for i in 0..43 { for j in i..43 { - sum += st[i] * st[j] * MODEL[cnt]; + sum += st[i] * st[j] * xuping13::MODULE[cnt]; cnt += 1; } } diff --git a/src/main.rs b/src/main.rs index 360da10..feb41b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,7 @@ impl Command { } fn main() { - tracing_subscriber::fmt::init(); + tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init(); let mut cli_arg = Command::parse(); // 将数据量处理成可被 thread_count 整除