use serde::{Deserialize, Serialize};
use converge_pack::{ExecutionIdentity, FactPayload};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum LpSolveStatus {
Optimal,
Feasible,
Infeasible,
Unbounded,
Error,
Invalid,
}
impl LpSolveStatus {
pub fn is_successful(self) -> bool {
matches!(self, Self::Optimal | Self::Feasible)
}
pub fn as_str(self) -> &'static str {
match self {
Self::Optimal => "optimal",
Self::Feasible => "feasible",
Self::Infeasible => "infeasible",
Self::Unbounded => "unbounded",
Self::Error => "error",
Self::Invalid => "invalid",
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LpVariable {
pub name: String,
#[serde(with = "crate::serde_util::f64_inf")]
pub lb: f64,
#[serde(with = "crate::serde_util::f64_inf")]
pub ub: f64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LpTerm {
pub var: String,
pub coeff: f64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LpConstraint {
pub name: String,
#[serde(with = "crate::serde_util::f64_inf")]
pub lb: f64,
#[serde(with = "crate::serde_util::f64_inf")]
pub ub: f64,
pub terms: Vec<LpTerm>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LpObjective {
pub terms: Vec<LpTerm>,
pub maximize: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LpRequest {
pub id: String,
pub variables: Vec<LpVariable>,
pub constraints: Vec<LpConstraint>,
pub objective: LpObjective,
pub time_limit_seconds: Option<f64>,
}
impl FactPayload for LpRequest {
const FAMILY: &'static str = "ferrox.lp.request";
const VERSION: u16 = 1;
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LpPlan {
pub request_id: String,
pub status: LpSolveStatus,
pub values: Vec<(String, f64)>,
pub objective_value: f64,
pub solver: String,
pub execution_identity: ExecutionIdentity,
}
impl FactPayload for LpPlan {
const FAMILY: &'static str = "ferrox.lp.plan";
const VERSION: u16 = 1;
}