or-tools | Google 's Operations Research tools

 by   google C++ Version: v9.6 License: Apache-2.0

kandi X-RAY | or-tools Summary

kandi X-RAY | or-tools Summary

or-tools is a C++ library. or-tools has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Google Optimization Tools (a.k.a., OR-Tools) is an open-source, fast and portable software suite for solving combinatorial optimization problems. We wrote OR-Tools in C++, but also provide wrappers in Python, C# and Java.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              or-tools has a medium active ecosystem.
              It has 9478 star(s) with 1983 fork(s). There are 295 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 49 open issues and 2598 have been closed. On average issues are closed in 26 days. There are 14 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of or-tools is v9.6

            kandi-Quality Quality

              or-tools has no bugs reported.

            kandi-Security Security

              or-tools has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              or-tools is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              or-tools releases are available to install and integrate.
              Installation instructions are available. Examples and code snippets are not available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of or-tools
            Get all kandi verified functions for this library.

            or-tools Key Features

            No Key Features are available at this moment for or-tools.

            or-tools Examples and Code Snippets

            Problem changing from for loop and if condition to list comprehension and using ortools
            Pythondot img1Lines of Code : 7dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            for f in L_Filas:
                for c in L_Columnas:
                    if tablaOrigD[f+1][c+1]:
                        s.Add(x[f][c][tablaOrigD[f+1][c+1] - 1] == 1)
            
            [s.Add(x[f][c][tablaOrigD[f+1][c+1] - 1] == 1) for f in L_Filas for c in L_Colum
            Adding Disjunctive constraints in google ortools
            Pythondot img2Lines of Code : 7dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
              solver = routing.solver()
            
              x2 = solver.IsEqualCstVar(x, 2)  # You can use x2 == (x == 2).Var()
              y3 = solver.IsEqualCstVar(y, 3)
            
              solver.Add(x2 + y3 >= 1)
            
            Google OR-Tools: Solving an objective function containing max function of multiple variables
            Pythondot img3Lines of Code : 14dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Let:
            c[i] = some indexed set of coefficients
            x[i] = some indexed variable
            
            Desire:
            minimax (c[i]*x[i])
            
            Introduce:
            my_max = real valued variable, non-indexed
            
            Make constraint
            for i in I:
              my_max >= c[i]*x[i]
            
            Knapsack problem with a total item limit in Python
            Pythondot img4Lines of Code : 83dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from ortools.sat.python import cp_model
            
            # DATA
            capacity = 6
            money = 20
            beers = [ 
              {"name":"Beer1",  "type":"Lager",   "price":3.50, "score":4.1},
              {"name":"Beer2",  "type":"Porter",  "price":4.90, "score":4.5},
              {"name":"Beer3",  "typ
            python creating custom syntax
            Pythondot img5Lines of Code : 11dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                def __mul__(self, arg):
                    if isinstance(arg, numbers.Integral):
                        if arg == 1:
                            return self
                        elif arg == 0:
                            return 0
                        cp_model_helper.AssertIsInt64(arg)
                        r
            Allocation optimization problem using python
            Pythondot img6Lines of Code : 107dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # Team Assignment
            
            import pyomo.environ as pyo
            
            ### DATA
            sectors = { 
                   "1A": 80,
                   "1B": 20, 
                   "2A": 10, 
                   "3A": 50,
                   "3B": 20,
                   "3C": 110
                 }
            
            teams = {
               "TeamA":20, 
               "TeamB":15, 
               "TeamC":100,
            Fastest way to find a minimum amount of sets from a set of sets that has the largest union?
            Pythondot img7Lines of Code : 38dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import collections
            from ortools.linear_solver import pywraplp
            
            
            def set_cover(ss):
                solver = pywraplp.Solver.CreateSolver("SCIP")
                solver.Objective().SetMinimization()
                constraints = collections.defaultdict(
                    lambda: solver
            VRP with different vehicle types using or-tools
            Pythondot img8Lines of Code : 25dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # Vehicles list
            trucks = [1, 3, 6, 7, 9, 10]
            vans = [4, 5]
            pickups = [2, 8]
            
            # location list with a tuple (location, truck, van pickup)
            locations = [
              (1, True, True, True), # C-01
              (2, True, True, False), # C-02
              (3, True, False, False
            copy iconCopy
            from ortools.sat.python import cp_model
            
            model = cp_model.CpModel()
            a = model.NewIntVar(0, 10, "")
            
            model.Add(11 <= a <= 30)
            solver = cp_model.CpSolver()
            solver.Solve(model)
            
            print(solver.StatusName())
            
            hours 
            Modified bus scheduling problem in ortools
            Pythondot img10Lines of Code : 168dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            num_shifts = len(shifts)
            
            num_drivers = ceil(float(num_shifts) / working_time)
            
            working_time = 22
            
            break_time = 2
            
            break_interval = [8, 16]
            

            Community Discussions

            QUESTION

            What do limit and symmetry mean in ortools?
            Asked 2022-Apr-09 at 09:42

            I have a problem I am trying to optimize with about 1 million variables and 10 million constraints. CP-SAT takes a long time to find a feasible solution. I was reading the output and I see a few things I don't understand.

            • It tells me that I need to increase symmetry to at least 3. Looking at this link (and assuming it is relevant to the latest version of CP-SAT and using Python) it says

            // Whether we try to automatically detect the symmetries in a model and // exploit them. Currently, at level 1 we detect them in presolve and try // to fix Booleans. At level 2, we also do some form of dynamic symmetry // breaking during search.

            But it doesn't say anything about symmetry at 3 or above. What does it do if you set it to 3?

            • I tried setting symmetry to 3 and now that message has gone but I am left with

            [Symmetry] GraphSymmetryFinder error: During the initial refinement.

            Is this something I should try to resolve, and if so how?

            • There is also a line like:

            [Probing] deterministic_time: 1.00001 (limit: 1) wall_time: 1.21766 (Aborted 10197/201810)

            Is that something to worry about and can I increase limit to make the probing complete rather than abort? limit isn't one of the parameters in solver.parameters it seems. Is limit setting a cap on the number of seconds Probing can run for? What is happening in this probing step?

            ...

            ANSWER

            Answered 2022-Apr-09 at 09:42

            Symmetry detection and probing are optional, potentially costly, phases during presolve.

            Symmetry detection is nice, but does not yet support all constraints. So it can fails. The solver will silently ignore this failure.

            For probing, the best way to improve perf is to use multiple workers (8 or more). Continuous probing is enabled if you have more that 12 workers. Of course, it is best if your computer has that many cores.

            Source https://stackoverflow.com/questions/71806216

            QUESTION

            Implementing IF-ELSE in or-tools linear solver
            Asked 2022-Mar-23 at 16:48

            as part of my code, I'm trying to get the total number of non-zero contracts that my solver is trying to solve so I can add a constraint and put a limit on it. since or-tools doesn't support if statements directly, I decided to use the .OnlyEnforceIf() solution that I found on numerous websites. this is the code I came up with:

            ...

            ANSWER

            Answered 2022-Mar-23 at 16:48

            The API you use is only for CP-SAT.

            Source https://stackoverflow.com/questions/71590899

            QUESTION

            Selenium CSS Selector get only first element while the inspector show 4
            Asked 2022-Mar-20 at 16:57

            I'm trying to automize Linguee dictionary using Selenium.

            For instance, in the image I would like to get an array with [de, para, por, con]. In order to get this, I wrote the following code

            ...

            ANSWER

            Answered 2022-Mar-20 at 16:37

            This is how find_element method works.
            It returns the first matching element on the DOM it finds.
            So in case you are passing it locator matching several elements on the page the first matching element on the DOM will be returned.
            In case you want to get all the elements matching that locator find_elements method should be used instead.
            So, in case you want to get all the texts in elements matching div[class='isMainTerm'] a[class='dictLink'] CSS Selector instead of

            Source https://stackoverflow.com/questions/71548292

            QUESTION

            Ortools VRP error when trying to merge penalties and different start-end depots
            Asked 2022-Feb-15 at 10:14

            I'm trying to solve a VRP problem allowing dropping nodes through penalties and multiple depots.

            Code works fine with penalties and vehicles starting and ending at the same depots:

            ...

            ANSWER

            Answered 2022-Feb-07 at 10:59

            With custom start and ends, you should use Routing.Start(vehicle_index) and Routing.End(vehicle_index) to get the index of these nodes.

            Source https://stackoverflow.com/questions/71017337

            QUESTION

            Protocolbuffer package isString empty error in AnyLogic
            Asked 2022-Jan-31 at 11:13

            I am trying to use custom routing in anylogic. For routing optimization, I am using Google OR-Tools and I have imported all the necessary packages and dependencies in the model properties section.

            I am a rookie after doing some research I made several changes in the protocol buffer .jar file as mentioned in GitHub but still I am facing the same error.

            .

            If I try to remove the protocol buffer dependency from the model properties again I end up getting the same error.

            Thanks in advance.

            ...

            ANSWER

            Answered 2022-Jan-31 at 11:13

            For the protobuf version I STRONGLY recommend you to look at the version specified in the maven pom.xml template since the version should match the version use in the C++ side of the library.

            You can find it here https://github.com/google/or-tools/tree/stable/ortools/java
            note: use the tag related to your or-tools version usually we try to be in sync with the last protobuf release available when we release a new or-tools version.

            note: this is a mandatory requirement in python to avoid any strange behaviour and I expect the same weird undefined behaviour if you also don't follow this..

            Source https://stackoverflow.com/questions/70914857

            QUESTION

            Using NewBoolVar in Google OR-Tools
            Asked 2022-Jan-22 at 00:11

            I am wondering the syntax for logical constraints in Google OR-Tools. I have a nurse scheduling project I have done in CPLEX that I am translating over to Google OR-Tools. I have come across the documentation for channeling constraints in Google OR-Tools, but I am confused. Can you help me understand how I would implement this CPLEX logical constraint in Google OR-Tools? I have an attempt, but it is not working as intended :(

            Context:

            working_assignment_vars_long[r,h,i] is a binary decision variable that denotes whether nurse i in role r is working at the 15-minute interval h (i.e. 1:15PM).

            lunch_break_assignment_vars_long[r,h,i] is a binary decision variable that denotes whether nurse i in role r is on break at the 15-minute interval h (i.e. 1:15PM).

            simple_break_assignment_vars_long[r,h,i] is a binary decision variable that denotes whether nurse i in role r is on break at 15-minute interval h.

            Thus, this constraint in CPLEX is saying that if a given nurse is working 31 or less 15-minute intervals, then they should have 0 lunch breaks and 1 simple break.

            CPLEX logical constraint:

            ...

            ANSWER

            Answered 2022-Jan-22 at 00:11

            In the official documentation it is documented how to do an If-Then-Else expression.

            You aren't constraining b.Not():

            Source https://stackoverflow.com/questions/70808585

            QUESTION

            Constraint optimization in python with OR Tools: How to enforce a multi level constraint?
            Asked 2022-Jan-02 at 09:50

            I have an optimization problem where I have a list of lists of "BoolVar" objects. So something like this:

            ...

            ANSWER

            Answered 2022-Jan-02 at 09:50
            1. OnlyEnforceIf is just an implication. You need to add the reverse direction.

            2. You should stay in the Boolean world:

            Source https://stackoverflow.com/questions/70553100

            QUESTION

            Schedule non-overlapping tasks between two people
            Asked 2021-Dec-29 at 09:26

            I am using Google OR-Tools to solve a maintenance scheduling problem. I have five machines which are all initially broken. I need to schedule tasks for two technicians to fix the machines to minimize the total lost output. Each technicial can fix any of the machines. However, the time taken to fix each machine is different (but known for each machine beforehand). The output from each machine is the same. Thus, the optimal solution is to do the quickest tasks (machine fixes) first and so as many machines are up and running as soon as possible. (This is a toy problem to get me started on something more complex.)

            I've hacked around the job shop problem to solve this for one technician (see working python script below) but I am stuck trying to apply it to two technicians as I can't work out how to handle the no overlap condition between two sets of technicians' tasks.

            ...

            ANSWER

            Answered 2021-Dec-27 at 10:42

            You could model it by creating an array of variables technicianForTask[task] which indicate which technician is doing each task. Then add no-overlap constraints for each pair of intervals, but only enforced if the technician is the same for both the tasks.

            I don't have a working Python installation, but the equivalent c# code would look like this:

            Source https://stackoverflow.com/questions/70493195

            QUESTION

            Cplex giving wrong result
            Asked 2021-Dec-02 at 14:32

            I created a sample test.lp file as follows:

            ...

            ANSWER

            Answered 2021-Dec-02 at 12:20

            QUESTION

            How to create a vehicle route optimization problem using or-tools and google-distance matrix while nullifying the end location only?
            Asked 2021-Nov-28 at 11:00

            I am trying to create a vehicle routing problem for multi-drivers with pickup and drop-off locations. The starting point for each driver is their current location and the ending point would be anywhere they end.

            The input to my algorithm is a series of lot/long locations. The final output would be the best(shortest) route decided for the driver starting from his location and ending at any location. My actual final output is a route that starts at the driver location and ends at the driver location.

            My problem is how can I create the distance matrix while nullifying the end location (the distance from the end node to any other node would be zero).

            These are the functions that convert the lat/long locations to distance matrix >>

            ...

            ANSWER

            Answered 2021-Nov-28 at 11:00

            Apparently, it is as simple as it is answered in the other question. I added a row of zeros and an additional zero at the start of every row after creating the distance matrix > this will tell the algorithm that the distance between the point at index zero and any other point is 0. And I set my end point data["ends"] = 0. So in my case the distance matrix would look like this >>

            Source https://stackoverflow.com/questions/69741122

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install or-tools

            This software suite has been tested under:. OR-Tools currently builds with a Makefile, but also provides Bazel and CMake support. For installation instructions (both source and binary), please visit https://developers.google.com/optimization/introduction/installing.
            Ubuntu 18.04 LTS and up (64-bit);
            Apple macOS Mojave with Xcode 9.x (64-bit);
            Microsoft Windows with Visual Studio 2019 (64-bit).
            We provide a Make based build.Please check the Make build instructions.
            We provide a CMake based build.Please check the CMake build instructions.
            We provide a Bazel based build.Please check the Bazel build instructions.
            The best way to learn how to use OR-Tools is to follow the tutorials in our developer guide:. If you want to learn from code examples, take a look at the examples in the examples directory.

            Support

            The complete documentation for OR-Tools is available at: https://developers.google.com/optimization/.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link