# File: example/matrixpararun.php

 Classes of Benjamin Vatter > PHP Clarke and Wright Algorithm > example/matrixpararun.php > Download
File: example/matrixpararun.php Example script text/plain parametric run of the class PHP Clarke and Wright Algorithm Solve a truck routing problem with Clarke & Wright By Benjamin Vatter 3 years ago 2,900 bytes

## Contents

 loadData(\$client_nodes,\$client_demands,\$distance_matrix,\$truck_capacity);     if(\$n==0){         \$cw->cwParametricSavings(1,0); //no parametric run case for comparison         }     else{         \$cw->cwParametricSavings();         }     \$cw->sortSavings();     \$cw->cwroutes();     \$cw->finishingTouch();     if(count(\$cw->unsatisfied)<\$min_unstisfied || (count(\$cw->unsatisfied)==\$min_unstisfied && \$min_total_cost>\$cw->total_cost)){         \$min_unstisfied = count(\$cw->unsatisfied);         \$min_total_cost = \$cw->total_cost;         \$saved_routes = \$cw->routes;         \$saved_total_cost = \$cw->total_cost;         \$saved_unstisfied = \$cw->unsatisfied;         \$saved_reassign_cost = \$cw->reassing_cost;     } }     \$time_end = microtime(true);     echo "

Clarke & Wright savings Hueristics with assymetric costs and time windows : Parametric Run \$max iterations

";     foreach (\$saved_routes as \$key => \$value) {         echo "

Route number {\$key}

";         echo "Truck: ".\$value['truck']."
";         echo "Total Distance of Path: ".\$value['total_distance']."
";         echo "Total Time of Path: ".\$value['total_time']."
";         echo "Time back at depot: ".\$value['time_back_at_depot']."
";         echo "Weight capacity of truck : ".\$value['truck_max_weight']." Kg
";         echo "Total weight of order : ".\$value['total_weight']." Kg
";         echo "Volume capacity of truck : ".\$value['truck_max_volume']." M3
";         echo "Total volume of order : ".\$value['total_volume']." M3
";         echo "

";     }     if(count(\$saved_unstisfied)>1){     echo "The following clients weren't visited :
";     ?>
ClientReason

\$reason){ ?>
";     echo "The total cost for the routing problem is : ".\$saved_total_cost." seconds
";     echo "The total excution time of the Hueristics was : ".(\$time_end-\$time_start)." seconds "."
";     echo "The total reassign cost of the process was : ".\$saved_reassign_cost."
"."
";     if(count(\$conversion)>0){         echo "the conversion for duplicate nodes was as follow :
";         foreach (\$conversion as \$key => \$value) {             list(\$from,\$to) = \$value;             \$num = \$key+2;             echo "\$from -> \$to
";         }     }