Make it more rusty
This commit is contained in:
43
src/batch.rs
43
src/batch.rs
@@ -110,7 +110,7 @@ pub struct Batch {
|
||||
|
||||
impl Batch {
|
||||
pub fn new(
|
||||
composition: Vec<Vec<Vec<Index>>>,
|
||||
compositions: Vec<Vec<Vec<Index>>>,
|
||||
results: Vec<Vec<f64>>,
|
||||
weights: Vec<Vec<Vec<f64>>>,
|
||||
time: i64,
|
||||
@@ -118,47 +118,48 @@ impl Batch {
|
||||
agents: &HashMap<Index, Agent>,
|
||||
) -> Self {
|
||||
assert!(
|
||||
results.is_empty() || results.len() == composition.len(),
|
||||
results.is_empty() || results.len() == compositions.len(),
|
||||
"TODO: Add a comment here"
|
||||
);
|
||||
assert!(
|
||||
weights.is_empty() || weights.len() == composition.len(),
|
||||
weights.is_empty() || weights.len() == compositions.len(),
|
||||
"TODO: Add a comment here"
|
||||
);
|
||||
|
||||
let this_agent = composition
|
||||
let this_agent = compositions
|
||||
.iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
let elapsed = this_agent
|
||||
.iter()
|
||||
.map(|&idx| (idx, compute_elapsed(agents[&idx].last_time, time)))
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let skills = this_agent
|
||||
.iter()
|
||||
.map(|&idx| {
|
||||
let elapsed = compute_elapsed(agents[idx].last_time, time);
|
||||
|
||||
(
|
||||
idx,
|
||||
*idx,
|
||||
Skill {
|
||||
forward: agents[&idx].receive(elapsed[&idx]),
|
||||
elapsed: elapsed[&idx],
|
||||
forward: agents[idx].receive(elapsed),
|
||||
elapsed,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let events = (0..composition.len())
|
||||
.map(|e| {
|
||||
let teams = (0..composition[e].len())
|
||||
.map(|t| {
|
||||
let items = (0..composition[e][t].len())
|
||||
.map(|a| Item {
|
||||
agent: composition[e][t][a],
|
||||
let events = compositions
|
||||
.iter()
|
||||
.enumerate() // (0..composition.len())
|
||||
.map(|(e, composition)| {
|
||||
let teams = composition
|
||||
.iter()
|
||||
.enumerate() // (0..composition.len())
|
||||
.map(|(t, team)| {
|
||||
let items = team
|
||||
.iter()
|
||||
.map(|&agent| Item {
|
||||
agent,
|
||||
likelihood: N_INF,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -166,7 +167,7 @@ impl Batch {
|
||||
Team {
|
||||
items,
|
||||
output: if results.is_empty() {
|
||||
(composition[e].len() - (t + 1)) as f64
|
||||
(composition.len() - (t + 1)) as f64
|
||||
} else {
|
||||
results[e][t]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user