Skip to content

Commit

Permalink
Rename to Instance::as_{pubo, qubo}_format to emphasize the format …
Browse files Browse the repository at this point in the history
…change (#202)

Split from #200 about Rust SDK side.

- `to_qubo` looks converting non-QUBO instance into QUBO, but this
function only converts its format.
  • Loading branch information
termoshtt authored Dec 11, 2024
1 parent f9ad791 commit 27edccc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/ommx/src/convert/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Instance {
/// - The objective function uses only binary decision variables.
/// - TODO: Binary encoding will be added.
///
pub fn to_pubo(&self) -> Result<BTreeMap<BinaryIds, f64>> {
pub fn as_pubo_format(&self) -> Result<BTreeMap<BinaryIds, f64>> {
if !self.constraints.is_empty() {
bail!("The instance still has constraints. Use penalty method or other way to translate into unconstrained problem first.");
}
Expand Down Expand Up @@ -223,7 +223,7 @@ impl Instance {
/// - TODO: Binary encoding will be added.
/// - The degree of the objective is at most 2.
///
pub fn to_qubo(&self) -> Result<(BTreeMap<BinaryIdPair, f64>, f64)> {
pub fn as_qubo_format(&self) -> Result<(BTreeMap<BinaryIdPair, f64>, f64)> {
if !self.constraints.is_empty() {
bail!("The instance still has constraints. Use penalty method or other way to translate into unconstrained problem first.");
}
Expand Down Expand Up @@ -478,15 +478,15 @@ mod tests {

#[test]
fn test_pubo(instance in Instance::arbitrary_binary_unconstrained()) {
let pubo = instance.to_pubo().unwrap();
let pubo = instance.as_pubo_format().unwrap();
for (_, c) in pubo {
prop_assert!(c.abs() > f64::EPSILON);
}
}

#[test]
fn test_qubo(instance in Instance::arbitrary_quadratic_binary_unconstrained()) {
let (quad, _) = instance.to_qubo().unwrap();
let (quad, _) = instance.as_qubo_format().unwrap();
for (ids, c) in quad {
prop_assert!(ids.0 <= ids.1);
prop_assert!(c.abs() > f64::EPSILON);
Expand Down

0 comments on commit 27edccc

Please sign in to comment.