Handle case where there is no time
This commit is contained in:
23
src/batch.rs
23
src/batch.rs
@@ -46,19 +46,19 @@ impl Agent {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Item {
|
||||
name: String,
|
||||
likelihood: Gaussian,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Team {
|
||||
items: Vec<Item>,
|
||||
output: u16,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Event {
|
||||
teams: Vec<Team>,
|
||||
pub evidence: f64,
|
||||
@@ -91,7 +91,7 @@ fn compute_elapsed(last_time: f64, actual_time: f64) -> f64 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Batch {
|
||||
pub skills: HashMap<String, Skill>,
|
||||
pub events: Vec<Event>,
|
||||
@@ -100,8 +100,8 @@ pub struct Batch {
|
||||
}
|
||||
|
||||
impl Batch {
|
||||
pub fn new(
|
||||
composition: Vec<Vec<Vec<&str>>>,
|
||||
pub fn new<C: AsRef<str> + Clone>(
|
||||
composition: Vec<Vec<Vec<C>>>,
|
||||
results: Vec<Vec<u16>>,
|
||||
time: f64,
|
||||
agents: &mut HashMap<String, Agent>,
|
||||
@@ -119,9 +119,9 @@ impl Batch {
|
||||
this
|
||||
}
|
||||
|
||||
pub fn add_events(
|
||||
pub fn add_events<C: AsRef<str> + Clone>(
|
||||
&mut self,
|
||||
composition: Vec<Vec<Vec<&str>>>,
|
||||
composition: Vec<Vec<Vec<C>>>,
|
||||
results: Vec<Vec<u16>>,
|
||||
agents: &mut HashMap<String, Agent>,
|
||||
) {
|
||||
@@ -129,20 +129,21 @@ impl Batch {
|
||||
.iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.cloned()
|
||||
.map(AsRef::as_ref)
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
for a in this_agent {
|
||||
let elapsed = compute_elapsed(agents[a].last_time, self.time);
|
||||
|
||||
if let Some(skill) = self.skills.get_mut(a) {
|
||||
skill.elapsed = elapsed;
|
||||
skill.forward = agents[a].receive(elapsed);
|
||||
skill.elapsed = elapsed;
|
||||
} else {
|
||||
self.skills.insert(
|
||||
a.to_string(),
|
||||
Skill {
|
||||
forward: agents[a].receive(elapsed),
|
||||
elapsed,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
@@ -156,7 +157,7 @@ impl Batch {
|
||||
.map(|t| {
|
||||
let items = (0..composition[e][t].len())
|
||||
.map(|a| Item {
|
||||
name: composition[e][t][a].to_string(),
|
||||
name: composition[e][t][a].as_ref().to_string(),
|
||||
likelihood: N_INF,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Reference in New Issue
Block a user