Skip to content

Commit

Permalink
feat: 删除进化算法
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow3aaa committed Nov 9, 2024
1 parent 4fa5cd6 commit 4ac0ab3
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 327 deletions.
53 changes: 0 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dumpsys-rs = { git = "https://github.com/shadow3aaa/dumpsys-rs" }
mimalloc = "0.1.43"
num_cpus = "1.16.0"
rand = "0.8.5"
rusqlite = { version = "0.32.1", features = ["bundled"]}

[build-dependencies]
anyhow = "1.0.93"
Expand Down
51 changes: 0 additions & 51 deletions src/cpu_temp_watcher.rs

This file was deleted.

69 changes: 4 additions & 65 deletions src/framework/scheduler/looper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ use likely_stable::{likely, unlikely};
#[cfg(debug_assertions)]
use log::debug;
use log::info;
use policy::{
controll::calculate_control,
evolution::{evaluate_fitness, load_control_params, mutate_params, open_database, Fitness},
ControllerParams,
};
use rusqlite::Connection;
use policy::{controll::calculate_control, ControllerParams};

use super::{topapp::TimedWatcher, FasData};
use crate::{
cpu_temp_watcher::CpuTempWatcher,
framework::{
config::Config,
error::Result,
Expand All @@ -46,51 +40,15 @@ use crate::{
use buffer::{Buffer, BufferWorkingState};
use clean::Cleaner;

const CONTROLLER_PARAMS: ControllerParams = ControllerParams { kp: 0.0006 };

#[derive(PartialEq)]
enum State {
NotWorking,
Waiting,
Working,
}

struct EvolutionState {
controller_params: ControllerParams,
mutated_controller_params: ControllerParams,
mutate_timer: Instant,
fitness: Fitness,
}

impl EvolutionState {
pub fn reset(&mut self, database: &Connection, pkg: &str) {
self.controller_params =
load_control_params(database, pkg).unwrap_or_else(|_| ControllerParams::default());
self.mutated_controller_params = self.controller_params;
self.fitness = Fitness::MIN;
}

pub fn try_evolution(
&mut self,
buffer: &Buffer,
cpu_temp_watcher: &CpuTempWatcher,
config: &mut Config,
mode: Mode,
) {
if unlikely(self.mutate_timer.elapsed() > Duration::from_millis(100)) {
self.mutate_timer = Instant::now();

if let Some(fitness) = evaluate_fitness(buffer, cpu_temp_watcher, config, mode) {
if fitness > self.fitness {
self.controller_params = self.mutated_controller_params;
}

self.fitness = fitness;
}

self.mutated_controller_params = mutate_params(self.controller_params);
}
}
}

struct FasState {
mode: Mode,
working_state: State,
Expand All @@ -106,22 +64,18 @@ struct AnalyzerState {

pub struct Looper {
analyzer_state: AnalyzerState,
cpu_temp_watcher: CpuTempWatcher,
config: Config,
node: Node,
extension: Extension,
controller: Controller,
windows_watcher: TimedWatcher,
cleaner: Cleaner,
database: Connection,
fas_state: FasState,
evolution_state: EvolutionState,
}

impl Looper {
pub fn new(
analyzer: Analyzer,
cpu_temp_watcher: CpuTempWatcher,
config: Config,
node: Node,
extension: Extension,
Expand All @@ -133,26 +87,18 @@ impl Looper {
restart_counter: 0,
restart_timer: Instant::now(),
},
cpu_temp_watcher,
config,
node,
extension,
controller,
windows_watcher: TimedWatcher::new(),
cleaner: Cleaner::new(),
database: open_database().unwrap(),
fas_state: FasState {
mode: Mode::Balance,
buffer: None,
working_state: State::NotWorking,
delay_timer: Instant::now(),
},
evolution_state: EvolutionState {
controller_params: ControllerParams::default(),
mutated_controller_params: ControllerParams::default(),
mutate_timer: Instant::now(),
fitness: Fitness::MIN,
},
}
}

Expand Down Expand Up @@ -253,18 +199,11 @@ impl Looper {
}

let control = if let Some(buffer) = &self.fas_state.buffer {
self.evolution_state.try_evolution(
buffer,
&self.cpu_temp_watcher,
&mut self.config,
self.fas_state.mode,
);

calculate_control(
buffer,
&mut self.config,
self.fas_state.mode,
self.evolution_state.mutated_controller_params,
CONTROLLER_PARAMS,
)
.unwrap_or_default()
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/framework/scheduler/looper/policy/controll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ fn calculate_control_inner(
current_frametime: Duration,
target_frametime: Duration,
) -> isize {
let error_p =
(current_frametime.as_nanos() as f64 - target_frametime.as_nanos() as f64) * controller_params.kp;
let error_p = (current_frametime.as_nanos() as f64 - target_frametime.as_nanos() as f64)
* controller_params.kp;

#[cfg(debug_assertions)]
debug!("error_p {error_p}");
Expand Down
Loading

0 comments on commit 4ac0ab3

Please sign in to comment.