Skip to content

Commit

Permalink
Update docs for external profiles in procedural scheduling (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney authored Oct 23, 2024
1 parent 207126c commit 41aabfc
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions docs/scheduling-and-constraints/procedural/plan-and-sim-results.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TabItem from '@theme/TabItem';
# The Plan & Simulation Results

The two main interfaces you'll query data from are `Plan` and `SimulationResults`. In constraints, they are provided as
separate objects, they are combined into one object called `EditablePlan`.
separate objects, while in scheduling they are combined into one object called `EditablePlan`.

## `Plan`

Expand Down Expand Up @@ -33,29 +33,14 @@ so we assume the duration of the anchor target is `0`.

The directives are always up-to-date, even if the simulation results aren't.

## Simulation Results

The `SimulationResults` object contains the activity instances and resource profiles of a simulation run.

### Instances

Activity instances are the simulated version of a directive; they have a duration, a definite grounded start time
(in the case of anchored activities), and any computed attributes the activity defines, in addition to all the data
stored in the directive.

All instances have an `id: ActivityInstanceId` field, which usually, but not always matches the id of the corresponding
directive. For clarity, it also includes a `directiveId: ActivityDirectiveId?` field which *might be null*, because some
instances are spawned from other activities and don't have a corresponding directive.

You can query instances the same way as directives, using `simResults.instances(...)`.
### External dataset profiles

### Resources

You can query resources with `simResults.resource("/my/resource", <deserializer>)`. Unlike activities, there is no option
You can query resources from *externally uploaded datasets* with `plan.resource("/my/resource", <deserializer>)`.
Unlike activities, there is no option
to use a default deserializer; you must pick one, because it determines the profile type. Each profile type provides a
deserializer for you to use, so for example, you can get a string resource with `simResults.resource("/my/string", Strings.deserializer())`.

If you made your own data structure for your resource (say, `V`), you'll probably want to use the `Constants` profile.
If you made your own data structure to represent the resource values (say, `V`), you'll probably want to use the `Constants` profile.
But unfortunately you have to do any deserialization yourself. If you don't want to, you can just use `.resource("/my/object", Constants::new)`,
but this will return `Constants<SerializedValue>`. To do proper deserialization, call `Constants.deserializer`:

Expand All @@ -66,7 +51,6 @@ but this will return `Constants<SerializedValue>`. To do proper deserialization,
// Segment payload we will deserialize into.
data class Point2(x: Double, y: Double) {}

// note the use of . instead of :: here! v
val myResource = plan.resource("/my/object", Constants.deserializer {
val fields = it.asMap().get()
Point2(fields.get("x").asReal().get(), fields.get("y").asReal().get())
Expand All @@ -80,7 +64,6 @@ val myResource = plan.resource("/my/object", Constants.deserializer {
// Segment payload we will deserialize into.
record Point2(double x, double y) {}

// note the use of . instead of :: here! v
final var myResource = plan.resource("/my/object", Constants.deserializer($ -> {
final var fields = it.asMap().get();
return new Point2(fields.get("x").asReal().get(), fields.get("y").asReal().get());
Expand All @@ -89,3 +72,32 @@ final var myResource = plan.resource("/my/object", Constants.deserializer($ -> {

</TabItem>
</Tabs>

:::tip

The `Plan` object only has access to non-simulated resource uploaded in [external datasets](../../../planning/external-datasets).
To access simulated resources, use a `SimulationResults` object. (see below)

:::

## Simulation Results

The `SimulationResults` object contains the activity instances and resource profiles of a simulation run.

### Instances

Activity instances are the simulated version of a directive; they have a duration, a definite grounded start time
(in the case of anchored activities), and any computed attributes the activity defines, in addition to all the data
stored in the directive.

All instances have an `id: ActivityInstanceId` field, which usually, but not always matches the id of the corresponding
directive. For clarity, it also includes a `directiveId: ActivityDirectiveId?` field which *might be null*, because some
instances are spawned from other activities and don't have a corresponding directive.

You can query instances the same way as directives, using `simResults.instances(...)`.

### Resources

Simulated resources can be accessed exactly the same way as [external resources](#external-dataset-profiles), but through the `SimulationResults` object.
So in the example above, if the `/my/object` resource was simulated instead of uploaded,
you would access it using `simResults.resource("/my/object", Constants.deserializer(...))`;

0 comments on commit 41aabfc

Please sign in to comment.