Skip to content

Commit

Permalink
feat: Adding serde as an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dandxy89 committed Nov 11, 2023
1 parent b31fc63 commit 7e78069
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ publish = false
anyhow = "1.0.75"
pest = "2.7.5"
pest_derive = "2.7.5"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
divan = "0.1.2"

[features]
default = []
serde = ["dep:serde"]
6 changes: 6 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
};

#[derive(Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// A enum representing the bounds of a variable
pub enum VariableType {
/// Unbounded variable (-Infinity, +Infinity)
Expand All @@ -28,12 +29,14 @@ pub enum VariableType {
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Objective {
pub name: String,
pub coefficients: Vec<Coefficient>,
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Coefficient {
pub var_name: String,
pub coefficient: f64,
Expand Down Expand Up @@ -61,6 +64,7 @@ impl TryFrom<Pairs<'_, Rule>> for Coefficient {
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Constraint {
pub name: String,
pub coefficients: Vec<Coefficient>,
Expand All @@ -69,13 +73,15 @@ pub struct Constraint {
}

#[derive(Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Sense {
#[default]
Minimize,
Maximize,
}

#[derive(Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LPDefinition {
pub problem_sense: Sense,
pub variables: HashMap<String, VariableType>,
Expand Down

0 comments on commit 7e78069

Please sign in to comment.