opentripmodel / otm5-change-requests

Tracking and reporting bugs and change requests of the OTM5 specification.
5 stars 1 forks source link

Replace similar constraints with value-bound-constraint #61

Closed bmeesters closed 1 year ago

bmeesters commented 2 years ago

Introduction

In the past few releases we see more and more requests for new constraint types. As a result, the list of constraint types gets quite big and can get overwhelming for parties just starting out with OTM5. We had a few discussions about this and came to the conclusion that there are two paths forward.

  1. Continue as is. The amount of constraints can be a bit overwhelming, but the constraints themselves are precise, and you are not required to use all of them.
  2. Merge constraints that are similar to less constraints, and easier see the similarities between the type of constraints. The benefit would be less constraints to implement while having more modelling power. The downside would be that you 'hid' some of the complexities. It is less overwhelming at first, but there is still the same amount of constraints you need to deal with.

Example

To help decide what would be the best way forward we looked at a more advanced use case and see how both approaches would evolve with the following constraints.

Current approach with constraint for each sub type

This is the original Constraint as defined in https://otm5.opentripmodel.org/#tag/Constraint but extended with some new constraint types (ForkLift to indicate the unloading location needs one to unload the locations, DriverLicense ADR to indicate the driver needs to be in possession of this license to able to operate the vehicle, Tailgate to indicate the vehicle used needs a tailgate to load/unload the goods) to fit the example. The upside of this approach is that it is easier to clearly document each new constraint and the type of values that are allowed. The downside is that the amount of constraints grows rapidly and it becomes hard to see the 'forest' through the trees.

{
  "id":"fa6c683c-7130-4955-9789-f99f2bb4eba3",
  "name":"SUTC consignment with constraints",
  "goods":[
    {
      "entity":{
        "id":"9503d7bd-a9e7-413b-9828-2e6581d1029e",
        "quantity":2,
        "containedGoods":[
          {
            "entity":{
              "adr":{
                "UNNumber":"<UN number>",
                "description":"dangerous gasses",
                "packagingGroup":"???",
                "tunnelCode":"???",
                "language":"NLD"
              },
              "type":"items"
            },
            "associationType":"inline"
          }
        ],
        "equipmentType":"pallet",
        "type":"transportEquipment"
      },
      "associationType":"inline"
    }
  ],
  "actions":[
    {
      "entity":{
        "location":{
          "entity":{
            "geoReference":{
              "name":"Breda",
              "type":"addressGeoReference"
            }
          },
          "associationType":"inline"
        },
        "actionType":"load"
      },
      "associationType":"inline"
    },
    {
      "entity":{
        "location":{
          "entity":{
            "geoReference":{
              "name":"Some warehouse in Amsterdam",
              "type":"addressGeoReference"
            },
            "constraint":{
              "entity":{
                "value":{
                  "and":[
                    {
                      "startTime":"2022-06-02T07:00:00Z",
                      "endTime":"2022-06-02T09:00:00Z",
                      "description":"Location accessible",
                      "type":"timeWindowConstraint"
                    },
                    {
                      "constraintType":"maximum",
                      "maximum":{
                        "value":25000,
                        "unit":"kg"
                      },
                      "description":"vehicle weight",
                      "type":"weightConstraint"
                    },
                    {
                      "constraintType":"maximum",
                      "maximum":{
                        "value":3.8,
                        "unit":"m"
                      },
                      "description":"vehicle height",
                      "type":"weightConstraint"
                    },
                    {
                      "emissionTypes":[
                        "euro6"
                      ],
                      "type":"emissionTypeConstraint"
                    }
                  ],
                  "type":"andConstraint"
                }
              },
              "associationType":"inline"
            }
          },
          "associationType":"inline"
        },
        "constraint":{
          "entity":{
            "value":{
              "startTime":"2022-06-02T07:00:00Z",
              "endTime":"2022-06-02T10:00:00Z",
              "type":"timeWindowConstraint"
            }
          },
          "associationType":"inline"
        },
        "actionType":"unload"
      },
      "associationType":"inline"
    }
  ],
  "constraint":{
    "entity":{
      "value":{
        "value":[
          "ADRLicense"
        ],
        "type":"driverLicenseConstraint"
      }
    },
    "associationType":"inline"
  }
}

Combined constraints

This is a modified constraint type that supports:

{
  "id":"fa6c683c-7130-4955-9789-f99f2bb4eba3",
  "goods":[
    {
      "entity":{
        "id":"9503d7bd-a9e7-413b-9828-2e6581d1029e",
        "quantity":2,
        "containedGoods":[
          {
            "entity":{
              "adr":{
                "UNNumber":"<UN number>",
                "description":"dangerous gasses",
                "packagingGroup":"???",
                "tunnelCode":"???",
                "language":"NLD"
              },
              "type":"items"
            },
            "associationType":"inline"
          }
        ],
        "equipmentType":"pallet",
        "type":"transportEquipment"
      },
      "associationType":"inline"
    }
  ],
  "actions":[
    {
      "entity":{
        "location":{
          "entity":{
            "geoReference":{
              "name":"Breda",
              "type":"addressGeoReference"
            }
          },
          "associationType":"inline"
        },
        "actionType":"load"
      },
      "associationType":"inline"
    },
    {
      "entity":{
        "location":{
          "entity":{
            "geoReference":{
              "name":"Some warehouse in Amsterdam",
              "type":"addressGeoReference"
            }
          },
          "associationType":"inline"
        },
        "constraint":{
          "entity":{
            "value":{
              "startTime":"2022-06-02T07:00:00Z",
              "endTime":"2022-06-02T10:00:00Z",
              "type":"timeWindowConstraint"
            }
          },
          "associationType":"inline"
        },
        "actionType":"unload"
      },
      "associationType":"inline"
    }
  ],
  "constraint":{
    "entity":{
      "value":{
        "needs":[
          "adrLicense"
        ],
        "type":"propertyTypeConstraint"
      }
    },
    "associationType":"inline"
  }
}

Most notably this means a few new constraint types:

image

image

image

But it would also mean we can delete

And would support the earlier requested emissionTypeConstraint.

bmeesters commented 2 years ago

Conclusion

From what I could tell after the discussions we had we want to solve it (in typical Dutch fashion, the 'polder model') by using a little bit of both. Some constraints are worth it to keep as is and others are too similar to keep. The new proposal is:

Though I am unsure if there was any clear conclusion regarding:

bmeesters commented 1 year ago

We have talked about this many times now and came to the conclusion that we want to start with the simplest change as described in the conclusion above, which is replacing a few sub-constraints that are very similar with the valueBoundConstraint. Others are currently not in scope.

bmeesters commented 1 year ago

This is now part of OTM5.5