Code cleanup
This commit is contained in:
@@ -98,7 +98,6 @@ public class VrpResources {
|
||||
solution.Max(timeVar),
|
||||
solution.Min(slackVar),
|
||||
solution.Max(slackVar));
|
||||
var previousIndex = index;
|
||||
index = solution.Value(routing.NextVar(index));
|
||||
}
|
||||
var endTimeVar = timeDimension.CumulVar(index);
|
||||
|
||||
@@ -102,7 +102,6 @@ public class VrpResources {
|
||||
route += manager.indexToNode(index) + " Time(" + solution.min(timeVar) + ","
|
||||
+ solution.max(timeVar) + ") Slack(" + solution.min(slackVar) + ","
|
||||
+ solution.max(slackVar) + ") -> ";
|
||||
long previousIndex = index;
|
||||
index = solution.value(routing.nextVar(index));
|
||||
}
|
||||
IntVar timeVar = timeDimension.cumulVar(index);
|
||||
@@ -135,8 +134,8 @@ public class VrpResources {
|
||||
|
||||
// Create and register a transit callback.
|
||||
// [START transit_callback]
|
||||
final int transitCallbackIndex =
|
||||
routing.registerTransitCallback((long fromIndex, long toIndex) -> {
|
||||
final int transitCallbackIndex = routing.registerTransitCallback(
|
||||
(long fromIndex, long toIndex) -> {
|
||||
// Convert from routing variable Index to user NodeIndex.
|
||||
int fromNode = manager.indexToNode(fromIndex);
|
||||
int toNode = manager.indexToNode(toIndex);
|
||||
|
||||
@@ -12,30 +12,43 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""Constraint optimization example"""
|
||||
# [START program]
|
||||
"""Simple Constraint optimization example."""
|
||||
|
||||
# [START import]
|
||||
from __future__ import print_function
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
# [END import]
|
||||
|
||||
|
||||
def main():
|
||||
"""Entry point of the program"""
|
||||
# [START solver]
|
||||
solver = pywrapcp.Solver('ConstraintExample')
|
||||
# [END solver]
|
||||
|
||||
# Create the variables.
|
||||
# [START variables]
|
||||
num_vals = 3
|
||||
x = solver.IntVar(0, num_vals - 1, 'x')
|
||||
y = solver.IntVar(0, num_vals - 1, 'y')
|
||||
z = solver.IntVar(0, num_vals - 1, 'z')
|
||||
# [END variables]
|
||||
|
||||
# Constraint 0: x != y.
|
||||
# [START constraints]
|
||||
solver.Add(x != y)
|
||||
|
||||
print('Number of constraints =', solver.Constraints())
|
||||
# [END constraints]
|
||||
|
||||
# Call the solver.
|
||||
# [START solve]
|
||||
decision_builder = solver.Phase([x, y, z], solver.CHOOSE_FIRST_UNBOUND,
|
||||
solver.ASSIGN_MIN_VALUE)
|
||||
# [END solve]
|
||||
|
||||
# [START print_solution]
|
||||
solver.NewSearch(decision_builder)
|
||||
while solver.NextSolution():
|
||||
solution = 'Solution:'
|
||||
@@ -44,11 +57,15 @@ def main():
|
||||
print(solution)
|
||||
solver.EndSearch()
|
||||
print("Number of solutions found:", solver.Solutions())
|
||||
print('')
|
||||
print('Advanced usage:')
|
||||
# [END print_solution]
|
||||
|
||||
# [START advanced]
|
||||
print('\nAdvanced usage:')
|
||||
print('Problem solved in ', solver.WallTime(), ' milliseconds')
|
||||
print('Memory usage: ', pywrapcp.Solver.MemoryUsage(), ' bytes')
|
||||
# [END advanced]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
# [END program]
|
||||
|
||||
@@ -94,7 +94,6 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
|
||||
<< solution.Min(time_var) << ", " << solution.Max(time_var)
|
||||
<< ") Slack(" << solution.Min(slack_var) << ", "
|
||||
<< solution.Max(slack_var) << ") -> ";
|
||||
int64 previous_index = index;
|
||||
index = solution.Value(routing.NextVar(index));
|
||||
}
|
||||
auto time_var = time_dimension.CumulVar(index);
|
||||
@@ -198,10 +197,10 @@ void VrpTimeWindows() {
|
||||
// Instantiate route start and end times to produce feasible times.
|
||||
// [START depot_start_end_times]
|
||||
for (int i = 0; i < data.num_vehicles; ++i) {
|
||||
routing.AddVariableMinimizedByFinalizer(
|
||||
time_dimension.CumulVar(routing.End(i)));
|
||||
routing.AddVariableMinimizedByFinalizer(
|
||||
time_dimension.CumulVar(routing.Start(i)));
|
||||
routing.AddVariableMinimizedByFinalizer(
|
||||
time_dimension.CumulVar(routing.End(i)));
|
||||
}
|
||||
// [END depot_start_end_times]
|
||||
|
||||
|
||||
@@ -90,7 +90,6 @@ def print_solution(data, manager, routing, assignment):
|
||||
manager.IndexToNode(index), assignment.Min(time_var),
|
||||
assignment.Max(time_var), assignment.Min(slack_var),
|
||||
assignment.Max(slack_var))
|
||||
previous_index = index
|
||||
index = assignment.Value(routing.NextVar(index))
|
||||
time_var = time_dimension.CumulVar(index)
|
||||
plan_output += ' {0} Time({1},{2})\n'.format(
|
||||
|
||||
@@ -33,8 +33,6 @@ def main():
|
||||
# [END variables]
|
||||
|
||||
# [START constraints]
|
||||
|
||||
# [END constraints]
|
||||
# x + 7 * y <= 17.5.
|
||||
solver.Add(x + 7 * y <= 17.5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user