Skip to header Skip to main navigation Skip to main content Skip to footer
Home

Main navigation

  • About
    • Transport optimization
    • Route optimization
  • Pricing
  • Terms
  • Desktop app
  • API
    • Skill constraints
    • Capacity constraints
    • Time windows
    • Custom distances
  • 👉🏽 Try it online!
    • Import/export CSV
  • English
  • Polish

API – time windows

This page describes advanced features of OptiFacility related to availability time windows. Before reading this section, ensure you have read about the basic features of OptiFacility.

The following JSON file defines an instance of the problem with time window constraints. Additions to the basic JSON file are highlighted:

{
    "UserID": "demo",
    "RequestID": 12347,
    "Comment": "my first request with time window constraints",
    "Quality": 2,
    "AgentSpeed": 45.0,
    "AgentWorkTime": 12.0,
    "AgentVisitTime": 1.0,
    "AgentStartTime": 6.0,
    "CostAgentWork1h": 70.0,
    "CostAgentTravel1km": 1.0,
    "Facilities": [{"Lat":51.929, "Lon":18.615, "TimeConstraints":[{"From":0.0,"To":16.0}]},
                   {"Lat":52.039, "Lon":18.765, "TimeConstraints":[{"From":18.0,"To":20.0}]},
                   {"Lat":51.874, "Lon":18.971, "TimeConstraints":[{"From":35.2,"To":37.4}]},
                   {"Lat":52.058, "Lon":19.177, "TimeConstraints":[{"From":10.0,"To":13.0},
                                                                   {"From":14.0,"To":17.0}]},
                   {"Lat":51.99,  "Lon":18.589},
                   {"Lat":51.865, "Lon":18.765},
                   {"Lat":51.89,  "Lon":19.098},
                   {"Lat":52.014, "Lon":18.89},
                   {"Lat":52.011, "Lon":19.237}],
    "Agents": [{"Lat":51.768, "Lon":19.094,  "AgentStartTime": 9.0}],
    "Task": "FindRoutesCommutingIncluded"
}

The meaning of the highlighted fields is explained below:

  • AgentStartTime – optional field: time of day (in hours) when an agent starts their work. This value will be set as the default value for all agents in this optimization request. If not defined, the default value will be set to 9.0.
  • Facilities: TimeConstraints – an array of objects defining time windows in which the facility can be visited. The facility only needs to be visited during any one of the specified time windows – not all of them. Each time window object consists of two values: "From" and "To". The "From" value defines the earliest moment when an agent can start the visit, while the "To" value defines the latest moment when an agent can finish the visit. This means that if the time between "To" and "From" is shorter than the value of "AgentVisitTime", no agent can visit such a facility during that time window.

    Time windows must be defined in chronological order and must not overlap. Facilities without defined time constraints can be visited at any point in time.

  • Agents: AgentStartTime – optional field: time of day (in hours) when a particular agent starts their work. This value overrides the default one.

Time values in "TimeConstraints" are defined relative to 0.0, which is midnight (the beginning) of the first day. A value of 17.25 means 17:15 (5:15pm). A value of 30.5 means the second day, 6:30am (1*24.0 + 6.5).

Time windows can be used to represent deadlines. To use time windows for this purpose, the "From" value should be set to 0.0, while the "To" value should be set to the actual deadline time. Time windows can be longer than 24 hours.


Questions / contact / accessing / extending OptiFacility: support@mooncoder.com

© Mooncoder 2009−2026