Skip to content

Commit

Permalink
fix: wrong directions flipping qubits in aeqts
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-TW committed Oct 18, 2024
1 parent 2365588 commit 58795b0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/aeqts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn aeqts(
let mut solutions: Vec<Solution> = vec![vec![false; items.len()]; n_neighbors as usize];
let mut record = Record::new(format!("csv/ae-qts/{}.csv", test_count));
for i in 0..max_gen {
// println!("Generation {}/{}", i+1, max_gen);
for j in 0..n_neighbors {
neighbors[j as usize] = measure(&qubits);
adjust_solution(items, &mut neighbors[j as usize], capacity);
Expand All @@ -30,29 +29,31 @@ pub fn aeqts(
}
}

// sort solutinos by value
// sort solutions by value
solutions.sort_by(|a, b| {
calculate_values(items, a)
.partial_cmp(&calculate_values(items, b))
.unwrap()
});

if calculate_values(items, &solutions[0]) > calculate_values(items, &best_fit) {
best_fit = solutions[0].clone();
if calculate_values(items, &solutions[solutions.len() - 1])
> calculate_values(items, &best_fit)
{
best_fit = solutions[solutions.len() - 1].clone();
}

record.add_iteration(
i,
calculate_values(items, &solutions[0]),
calculate_weights(items, &solutions[0]),
calculate_values(items, &solutions[solutions.len() - 1]),
calculate_weights(items, &solutions[solutions.len() - 1]),
best_fit.clone(),
qubits.clone(),
);

for j in 0..solutions.len() / 2 {
update_qubits_with_angle(
solutions[j].clone(),
solutions[solutions.len() - j - 1].clone(),
solutions[j].clone(),
&mut qubits,
0.01 / (j + 1) as f64,
);
Expand Down

0 comments on commit 58795b0

Please sign in to comment.