pub struct GraphBuilder { /* private fields */ }
Expand description

This type allows building a Graph using code rather then using text input.

Notes

  • A “builder” in rust will never be as convenient as one in, say, Python or Juilia. The lack of a rust REPL and the strong type checking are the primary reasons.
  • All error checks are delayed until resolution.

Implementations

Constructor

Returns

This function returns an “builder” containing an unresolved Graph.

Construct a builder with time units in generations.

This function works by calling GraphBuilder::new.

Add a Deme to the graph.

Examples
let start_size = demes::DemeSize::from(100.);
let epoch = demes::UnresolvedEpoch{start_size: Some(start_size), ..Default::default()};
let history = demes::UnresolvedDemeHistory::default();
let mut b = demes::GraphBuilder::new_generations(None);
b.add_deme("A", vec![epoch], history, Some("this is deme A"));
b.resolve().unwrap();
Notes

Add an asymmetric migration

Examples
let start_size = demes::DemeSize::from(100.);
let epoch = demes::UnresolvedEpoch{start_size: Some(start_size), ..Default::default()};
let history = demes::UnresolvedDemeHistory::default();
let mut b = demes::GraphBuilder::new_generations(None);
b.add_deme("A", vec![epoch], history.clone(), Some("this is deme A"));
b.add_deme("B", vec![epoch], history, Some("this is deme B"));
b.add_asymmetric_migration(Some("A"),
                           Some("B"),
                           Some(demes::MigrationRate::from(1e-4)),
                           None, // Using None for the times
                                 // will mean continuous migration for the
                                 // duration for which the demes coexist.
                           None);
b.resolve().unwrap();

Add a symmetric migration

Examples
let start_size = demes::DemeSize::from(100.);
let epoch = demes::UnresolvedEpoch{start_size: Some(start_size), ..Default::default()};
let history = demes::UnresolvedDemeHistory::default();
let mut b = demes::GraphBuilder::new_generations(None);
b.add_deme("A", vec![epoch], history.clone(), Some("this is deme A"));
b.add_deme("B", vec![epoch], history, Some("this is deme B"));
b.add_symmetric_migration(Some(&["A", "B"]),
                          Some(demes::MigrationRate::from(1e-4)),
                          None, // Using None for the times
                                // will mean continuous migration for the
                                // duration for which the demes coexist.
                          None);
b.resolve().unwrap();

Add a migration to the graph.

Note

This function can be inconvenient due to the generics. Prefer add_symmetric_migration or add_asymmetric_migration.

Examples
Adding an asymmetric migration
let start_size = demes::DemeSize::from(100.);
let epoch = demes::UnresolvedEpoch{start_size: Some(start_size), ..Default::default()};
let history = demes::UnresolvedDemeHistory::default();
let mut b = demes::GraphBuilder::new_generations(None);
b.add_deme("A", vec![epoch], history.clone(), Some("this is deme A"));
b.add_deme("B", vec![epoch], history, Some("this is deme B"));
b.add_migration::<String, _, _>(None,
                  Some("A"),
                  Some("B"),
                  Some(demes::MigrationRate::from(1e-4)),
                  None, // Using None for the times
                        // will mean continuous migration for the
                        // duration for which the demes coexist.
                  None);
b.resolve().unwrap();
Adding a symmetric migration
let start_size = demes::DemeSize::from(100.);
let epoch = demes::UnresolvedEpoch{start_size: Some(start_size), ..Default::default()};
let history = demes::UnresolvedDemeHistory::default();
let mut b = demes::GraphBuilder::new_generations(None);
b.add_deme("A", vec![epoch], history.clone(), Some("this is deme A"));
b.add_deme("B", vec![epoch], history, Some("this is deme B"));
b.add_migration::<_, String, String>(Some(&["A", "B"]),
                  None,
                  None,
                  Some(demes::MigrationRate::from(1e-4)),
                  None, // Using None for the times
                        // will mean continuous migration for the
                        // duration for which the demes coexist.
                  None);
b.resolve().unwrap();

Add an UnresolvedPulse to the graph.

Examples
let start_size = demes::DemeSize::from(100.);
let epoch = demes::UnresolvedEpoch{start_size: Some(start_size), ..Default::default()};
let history = demes::UnresolvedDemeHistory::default();
let mut b = demes::GraphBuilder::new_generations(None);
b.add_deme("A", vec![epoch], history.clone(), Some("this is deme A"));
b.add_deme("B", vec![epoch], history, Some("this is deme B"));
b.add_pulse(Some(&["A"]),
            Some("B"),
            Some(demes::Time::from(50.0)),
            Some(vec![demes::Proportion::from(0.5)]));
b.resolve().unwrap();

Generate and return a resolved Graph.

Errors

Returns `DemesError’ if any of the data are invalid.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.