我正在做一个组合优化项目学习锈蚀和我有一个问题,我解决不了自己...不能借`* x`为可变,因为它是还借为不可改变
我已经有2个功能:
pub fn get_pareto_front_offline<'a>(scheduling_jobs: &'a Vec<Vec<u32>>, costs_vector: &'a Vec<(u32, u32)>) -> Vec<(&'a Vec<u32>, &'a (u32, u32))> {
// ...
}
和
pub fn pareto_approach_offline<'a>(list_of_jobs: &'a mut Vec<Vec<u32>>, neighborhood: &'a mut Vec<Vec<u32>>, costs: &'a Vec<(u32, u32)>) -> Vec<(&'a Vec<u32>, &'a (u32, u32))> {
let pareto_front = get_pareto_front_offline(neighborhood, costs);
loop {
if pareto_front == vec![] {
break;
}
neighborhood.clear();
for front in pareto_front.iter() {
neighborhood.push((front.0).clone());
}
}
pareto_front
}
我有一个问题,因为编译器告诉我:
cannot borrow '*neighborhood' as mutable because it is also borrowed as immutableat line 15 col 9
cannot borrow '*neighborhood' as mutable because it is also borrowed as immutableat line 19 col 13
谢谢!你的解决方案正是我的想法......我试图为这个问题制定一个优化的解决方案,但是用我在Rust的“水平”,这真的很难: -/ – WebTogz
在这种情况下,你经常需要一个专门的采集。我认为,'VecDeque'可以解决问题,(但我可能是错的) https://doc.rust-lang.org/std/collections/struct.VecDeque.html 或者您可以使用渠道 https://doc.rust-lang.org/std/sync/mpsc/ – nielsle