or-tools

shift length constraint in OR-TOOLS RL VRPTW problem?

混江龙づ霸主 提交于 2019-12-11 19:09:01
问题 I'm trying to enforce a shift length constraint in OR-TOOLS RL VRPTW problem. Shift length is the total amount of time the vehicle been in service (transit + wait + service), from arriving to the first location until leaving the last location . It looks like a Time dimension is the perfect choice, but it accumulates the window start of the first location, which isn't good. So to re-iterate - I want a dimension that accumulates the transit time, service time and wait times (for the time window

Obtain list of SAT solutions from ortools

时光怂恿深爱的人放手 提交于 2019-12-11 14:55:40
问题 I'm trying to figure out how to get the complete list of possible solutions from the ortools.sat.python.cp_model . I understand I can print them, as in the example below, but it is not clear to me how to get the values, e.g. as a nested list or list of dicts. I tried writing my own callback class by modifying the VarArraySolutionPrinter and appending solutions to a list attribute, but for some reason this consistently caused the python kernel to crash. Anyway, there must be a more direct way.

Defining nodes that do not have to be visited

淺唱寂寞╮ 提交于 2019-12-11 13:08:02
问题 I'd like to define a routing problem using RoutingModel including nodes that are freed from the must-visit constraint, but have an influence on a capacity dimension if visited. Do you have any suggestions how to do this? 回答1: You can use disjunction constraints to make your nodes optional. You should add each node to its own disjunction group, each having a single element: for node in [0, 1, 2, 3, 4]: routing.AddDisjunction( nodes=[node], penalty=1) Why does this work? In a disjunction group,

Using ortools to select the two smallest integer values in a list

我的梦境 提交于 2019-12-11 06:08:22
问题 I know ortools is overkill here, but this is for my own learning-by-doing purpose. The problem is: How to find the two smallest integer values in a list using ortools? Here's the code I've got, based on another example I got that simply finds the single smallest value. from __future__ import print_function from ortools.sat.python import cp_model # 2. A simple problem # Select the two smallest numbers from a list of integers # Define data cost_data = [ 5, 4, 3, 4, 5, 6, 7, 1, 2, 3 ] num_hours

Installing Google or-tools with gradle project on Windows 10 (Intellij IDEA)

ぃ、小莉子 提交于 2019-12-10 23:16:36
问题 Is it possible to install the library on IntelliJ Idea? or do I have to use Visual Studio 2017? If so, how do I install it? I find the google documentation confusing. 回答1: In case anyone else comes here, this is my configuration for building and running OR-tools with Gradle. First of all, I have a top-level project where I have application-related code, called suite , and a module where I have separated all the OR-Tools related code, called optimization . In the optimization module, I have a

OR-tools consistently returns very sub-optimal TSP solution

浪子不回头ぞ 提交于 2019-12-04 04:46:26
Generating some random Gaussian coordinates, I noticed the TSP-solver returns horrible solutions, however it also returns the same horrible solution over and over again for the same input. Given this code: import numpy import math from ortools.constraint_solver import pywrapcp from ortools.constraint_solver import routing_enums_pb2 import matplotlib %matplotlib inline from matplotlib import pyplot, pylab pylab.rcParams['figure.figsize'] = 20, 10 n_points = 200 orders = numpy.random.randn(n_points, 2) coordinates = orders.tolist() class Distance: def __init__(self, coords): self.coords = coords