Industrial background
Road traffic scheduling aims to achieve efficient operation and flow control for a transportation system by properly managing and scheduling transportation resources. How can scheduling be arranged to help improve transportation efficiency and reduce costs? This optimization problem can be modeled and solved by using mathematical programming methods.
For example, there are seven stations, and each station has several entry roads and exit roads. The number beside a road indicates the maximum number of vehicles that this road can carry in unit time. How can vehicles be scheduled to obtain the maximum number of vehicles that depart from station a and finally arrive at station g per unit time?

Business research, data quantification, and mathematical modeling
When using optimization techniques, you need to investigate the needs of business in more detail, organize the relevant business logic and data, and quantify them. Then, you can use a mathematical programming method for modeling.
For more details, see . This section lists only the related mathematical formula.
In the preceding formula, i represents the start station of each road, j represents the arrival station of the road, e represents the initial station, k represents intermediate stations, and r represents the maximum number of vehicles that can pass through the road.
Constraints on the preceding formula:
The number of vehicles that enter an intermediate station is equal to the number of vehicles that leave the station.
Each road has an upper limit on the number of vehicles that are allowed to pass through.
Source code
Optimization Solver supports multiple programming languages or modeling languages. This section provides only one of the languages for reference.
MindOpt APL
Source code for MindOpt APL (you can access to perform a dry run):
##====Source code for MindOpt APL====
clear model;
# Modeling
# net1.mapl
set Station :={"a","b","c","d","e","f","g"};
set Middle := {"b","c","d","e","f"};
set Roads :={<"a","b">,<"b","d">,<"c","d">,<"d","e">,<"e","g">,<"a","c">,<"b","e">,<"c","f">,<"d","f">,<"f","g">};
param entr := "a";
param lb := 0;
param ub[Roads] := <"a","b"> 50, <"b","d"> 40, <"c","d"> 60, <"d","e"> 50, <"e","g"> 70, <"a","c"> 100, <"b","e"> 20, <"c","f"> 20, <"d","f"> 60, <"f","g"> 70;
var x[<i,j> in Roads] >= lb <= ub[i,j];
maximize Total : sum {<entr,j> in Roads } x[entr,j]; # The maximum inbound traffic at a start station.
# Traffic balancing
subto Balance:
forall <k> in Middle do
sum {<i,k> in Roads} x[i,k] == sum {<k,j> in Roads } x[k,j];
print "------------- Solving by using Optimization Solver---------------";
option solver mindopt; # (Optional) Specifies the solver used for solving the problem. Optimization Solver is used by default.
#option mindopt_options 'print=0'; # Sets output levels for the solver to simplify outputs.
solve; # Solves the problem.
print "----------------- Result ---------------";
display; # Displays the result.
print "Maximum road traffic after optimization = " ,sum {<entr,j> in Roads } x[entr,j];Result and result usage
The logs vary based on code. The following section provides a part of the logs.
...
Model summary.
- Num. variables : 10
- Num. constraints : 5
- Num. nonzeros : 16
- Bound range : [2.0e+01,1.0e+02]
- Objective range : [1.0e+00,1.0e+00]
- Matrix range : [1.0e+00,1.0e+00]
...
Simplex method terminated. Time : 0.002s
OPTIMAL; objective 130.00
...
----------------- Result ---------------
Maximum road traffic after optimization = 130The optimal solution is 130. If you want to learn more details of the solution, such as the values of the decision variables and whether the constraints are correct, you can run the print command or obtain the values of the decision variables from the .sol file for programming. You can also run the display command to obtain the values of all variables.
For example, run the following command to verify the constraint that the number of vehicles that enter an intermediate station is equal to the number of vehicles that leave the station.
forall <k> in Middle do
print "Number of vehicles that enter station {}: {}'%k, sum {<i,k> in Roads} x[i,k];
print "-------------";
forall <k> in Middle do
print 'Number of vehicles that leave station {}: {}'%k, sum {<k,j> in Roads} x[k,j];The outputs show that the constraint is met:
Number of vehicles that enter station b: 50
Number of vehicles that enter station c: 80
Number of vehicles that enter station d: 90
Number of vehicles that enter station e: 70
Number of vehicles that enter station f: 60
-------------
Number of vehicles that leave station b: 50
Number of vehicles that leave station c: 80
Number of vehicles that leave station d: 90
Number of vehicles that leave station e: 70
Number of vehicles that leave station f: 60 Run the following code to display the results in CSV format as a solution to the road traffic scheduling problem:
print "{},{},{} "% "Start station","Intermediate station","Number of vehicles" : "Results.csv";
close "Results.csv";
forall {<i,j> in Roads}
print "{},{},{}" % i,j,x[i,j] >> "Results.csv";
close "Results.csv";The results shown in the following table are returned:

The results indicate that a maximum of 130 vehicles can depart from station a. The following figure shows the traffic scheduling.
Among the 130 vehicles that depart from station a, 50 vehicles are distributed to station b and 80 vehicles are distributed to station c.
Among the 50 vehicles that are distributed to station b, 30 vehicles are distributed to station d and 20 vehicles are distributed to station e.
Among the 80 vehicles that are distributed to station c, 60 vehicles are distributed to station d and 20 vehicles are distributed to station f.
Among the 90 vehicles that are gathered at station d, 50 vehicles are distributed to station e and 40 vehicles are distributed to station f.
70 vehicles are gathered at station e.
60 vehicles are gathered at station f. The vehicles at stations e and f are then gathered at exit g. The total number of vehicles at exit g is 130.
