Originally posted by: SystemAdmin
[dgravot@noos.fr said:]
Hello,
You might also want to enforce the consecutive flight info directly into your data. In the following sample, I assume that trips possible connections are a given. The connection graph has trips as nodes and connections between flights as edges. The problem is now to find a partition of all nodes by paths in the graph, which can be formulated in different ways using CP. Following code uses a bijection between variables "follow" and "previous" defined for each node. Two dummy nodes are added (source and sink). Therefore, the number of flights will be the number of trips with the sink as a successor (or, equivalent, the number of trips with the source as a predecessor).
/*********************************************
* OPL 6.1.1 Model
* Author: dgravot
* Creation Date: 27 Apr 2009 at 19:07:28
*********************************************/
// assume we have a set of Trips O-D . Each trip must be covered.
// we can model the flight assigment to trip by saying that each trip belongs to a path
// we also have to force each trip to be covered exactly once.
// to count the number of paths, or to bound this number, we introduce dummy nodes source and sink
// each beginning of a trip is connected to the source
// each end of a trip is connected to the sink
using CP;
int nbTrips = ...;
range trips = 1..nbTrips;
int Source = 0;
int Sink = nbTrips+1;
tuple Link
{
int o;//first trip index
int d;//second trip index
}
{Link} links with o in trips,d in trips= ...;//assume this graph is acyclic
{int} followPossible[t in trips] = {d | <t,d> in links} union {Sink};
{int} previousPossible[t in trips] = {o | <o,t> in links} union {Source};
dvar int follow[t in trips];
dvar int previous[t in trips];
dexpr int nbFlights = count(all (t in trips) follow[t],Sink);
minimize nbFlights; //or other : min<=nbFlights<=max<br />
constraints
{
forall(t in trips)
{
follow[t] in followPossible[t];
previous[t] in previousPossible[t];
}
inverse(follow, previous);
}
#DecisionOptimization#OPLusingCPOptimizer