Skip to main content

GamsOptions

Struct GamsOptions 

Source
pub struct GamsOptions {
    pub universal: UniversalOptions,
    pub mip_gap: Option<f64>,
    pub solver: Option<GamsSolverConfig>,
    pub gams_path: Option<PathBuf>,
}
Available on crate feature gams only.
Expand description

GAMS-specific solver options.

Fields§

§universal: UniversalOptions§mip_gap: Option<f64>§solver: Option<GamsSolverConfig>

Sub-solver selection with optional typed options. Translates to option {LP|MIP} = <name>; plus a <solver>.opt file when options are set.

§gams_path: Option<PathBuf>

Override for the gams executable. When None, "gams" is looked up from PATH.

Implementations§

Source§

impl GamsOptions

Source

pub fn mip_gap(self, gap: f64) -> GamsOptions

Source

pub fn solver(self, s: impl Into<GamsSolverConfig>) -> GamsOptions

Examples found in repository?
examples/process_selection.rs (line 120)
113    pub fn run_gams() -> Result<(), Box<dyn std::error::Error>> {
114        use oximo::gams::{GamsBaronOptions, GamsSolverConfig};
115        use oximo::solvers::Gams;
116        use std::time::Duration;
117
118        let opts = GamsOptions::default()
119            .time_limit(Duration::from_secs(120))
120            .solver(GamsSolverConfig::Baron(GamsBaronOptions::default().eps_r(1e-4)))
121            .verbose(true);
122        solve_and_report("GAMS + BARON", Gams::new(), &opts)
123    }
More examples
Hide additional examples
examples/reaction_path.rs (line 114)
49fn main() -> Result<(), Box<dyn std::error::Error>> {
50    // 34 chemicals: index = yXX - 1 (y01 -> 0, ..., y34 -> 33).
51    const CHEMICALS: [&str; 34] = [
52        "y01", "y02", "y03", "y04", "y05", "y06", "y07", "y08", "y09", "y10", "y11", "y12", "y13",
53        "y14", "y15", "y16", "y17", "y18", "y19", "y20", "y21", "y22", "y23", "y24", "y25", "y26",
54        "y27", "y28", "y29", "y30", "y31", "y32", "y33", "y34",
55    ];
56
57    // (reaction label, product index, reactant indices) - all 0-based.
58    // Transcribed from logicc set in GAMS REACTION model (SEQ=121).
59    let logicc: &[(&str, usize, &[usize])] = &[
60        ("rxn01", 3, &[0, 1, 2]),      // y04 <- y01 + y02 + y03
61        ("rxn02", 5, &[3, 4]),         // y06 <- y04 + y05
62        ("rxn03", 6, &[3, 4]),         // y07 <- y04 + y05
63        ("rxn04", 2, &[3, 4]),         // y03 <- y04 + y05
64        ("rxn05", 10, &[7, 8, 9]),     // y11 <- y08 + y09 + y10
65        ("rxn06", 5, &[10, 11, 12]),   // y06 <- y11 + y12 + y13
66        ("rxn07", 14, &[13, 8, 9, 4]), // y15 <- y14 + y09 + y10 + y05
67        ("rxn08", 5, &[14, 15, 16]),   // y06 <- y15 + y16 + y17
68        ("rxn09", 5, &[17, 18, 11]),   // y06 <- y18 + y19 + y12
69        ("rxn10", 19, &[17, 18, 11]),  // y20 <- y18 + y19 + y12
70        ("rxn11", 8, &[20, 21]),       // y09 <- y21 + y22
71        ("rxn12", 23, &[8, 22]),       // y24 <- y09 + y23
72        ("rxn13", 17, &[23, 16]),      // y18 <- y24 + y17
73        ("rxn14", 20, &[24, 25]),      // y21 <- y25 + y26
74        ("rxn15", 26, &[24, 25]),      // y27 <- y25 + y26
75        ("rxn16", 13, &[2, 27, 28]),   // y14 <- y03 + y28 + y29
76        ("rxn17", 31, &[29, 30, 11]),  // y32 <- y30 + y31 + y12
77        ("rxn18", 7, &[29, 30, 11]),   // y08 <- y30 + y31 + y12
78        ("rxn19", 29, &[24, 32]),      // y30 <- y25 + y33
79        ("rxn20", 12, &[24, 32]),      // y13 <- y25 + y33
80        ("rxn21", 0, &[33, 2]),        // y01 <- y34 + y03
81        ("rxn22", 33, &[13, 27]),      // y34 <- y14 + y28
82    ];
83
84    // y02, y03, y05, y10, y12, y13, y17, y22, y25, y26, y28, y31, y33: fixed to 1.
85    let available: &[usize] = &[1, 2, 4, 9, 11, 12, 16, 21, 24, 25, 27, 30, 32];
86    // y16, y19: fixed to 0.
87    let unavailable: &[usize] = &[15, 18];
88
89    let m = Model::new("reaction_path");
90    let chemicals = Set::strings(CHEMICALS);
91
92    variable!(m, y[v in chemicals], Bin);
93    // Fix availability: raw materials/catalysts to 1, unavailable chemicals to 0.
94    for &i in available {
95        m.fix(y[CHEMICALS[i]], 1.0);
96    }
97    for &i in unavailable {
98        m.fix(y[CHEMICALS[i]], 0.0);
99    }
100
101    // sum_vv (1 - y[vv]) >= 1 - y[v]
102    //    <=>  y[v] - sum_vv y[vv] >= 1 - |reactants|
103    for &(_rx, prod, reactants) in logicc {
104        let n = reactants.len() as f64;
105        constraint!(m, y[CHEMICALS[prod]] - sum!(y[CHEMICALS[vv]] for vv in reactants) >= 1.0 - n);
106    }
107
108    objective!(m, Min, y["y06"]); // acetone
109
110    #[cfg(feature = "gams")]
111    let result = {
112        let opts = GamsOptions::default()
113            .time_limit(std::time::Duration::from_secs(60))
114            .solver(GamsSolverConfig::Cplex(GamsCplexOptions::default()))
115            .verbose(true);
116        let mut solver = Gams::new();
117        solver.solve(&m, &opts)?
118    };
119
120    #[cfg(all(feature = "highs", not(feature = "gams")))]
121    let result = Highs.solve(&m, &HighsOptions::default().verbose(true))?;
122
123    println!("Status : {:?}", result.termination);
124    if let Some(obj) = result.objective() {
125        println!(
126            "Acetone (y06, ch3coch3): {}",
127            if (obj - 1.0).abs() < 1e-6 { "Synthesizable" } else { "Not synthesizable" }
128        );
129    }
130
131    let synthesizable: Vec<&str> = CHEMICALS
132        .iter()
133        .copied()
134        .filter(|name| (result.value_of(y[*name]).unwrap_or(0.0) - 1.0).abs() < 1e-6)
135        .collect();
136    if !synthesizable.is_empty() {
137        println!("Synthesizable chemicals: {}", synthesizable.join(", "));
138    }
139
140    Ok(())
141}
Source

pub fn gams_path(self, p: impl Into<PathBuf>) -> GamsOptions

Trait Implementations§

Source§

impl Clone for GamsOptions

Source§

fn clone(&self) -> GamsOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GamsOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for GamsOptions

Source§

fn default() -> GamsOptions

Returns the “default value” for a type. Read more
Source§

impl HasUniversal for GamsOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UniversalOptionsExt for T
where T: HasUniversal,

Source§

fn time_limit(self, d: Duration) -> Self

Source§

fn threads(self, n: u32) -> Self

Source§

fn verbose(self, on: bool) -> Self

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more