Querying temporal and spatial constraint networks in PTIME