diff --git a/.github/workflows/boost_version.yml b/.github/workflows/boost_version.yml index 62719b3f0..2c61a85e5 100644 --- a/.github/workflows/boost_version.yml +++ b/.github/workflows/boost_version.yml @@ -30,6 +30,7 @@ jobs: pgver=$(psql --version | grep -Po '(?<=psql \(PostgreSQL\) )[^;]+(?=\.\d \()') echo "PGVER=${pgver}" >> $GITHUB_ENV echo "PGIS=3" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Add PostgreSQL APT repository run: | @@ -66,25 +67,35 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure run: | export PATH=/usr/lib/postgresql/${PGVER}/bin:$PATH mkdir build cd build - cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Debug -DWITH_DOC=OFF -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Debug -DWITH_DOC=OFF -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build run: | diff --git a/.github/workflows/check-queries.yml b/.github/workflows/check-queries.yml index 9d9bb7e1a..e60cbaafc 100644 --- a/.github/workflows/check-queries.yml +++ b/.github/workflows/check-queries.yml @@ -31,6 +31,7 @@ jobs: echo "PGVER=${PGVER}" >> $GITHUB_ENV echo "PGPORT=5432" >> $GITHUB_ENV echo "PGIS=3" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Add PostgreSQL APT repository run: | @@ -56,25 +57,35 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure run: | export PATH=/usr/lib/postgresql/${PGVER}/bin:$PATH mkdir build cd build - cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Debug -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Debug -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build run: | diff --git a/.github/workflows/clang.yml b/.github/workflows/clang.yml index cc3766ad8..e020c1df7 100644 --- a/.github/workflows/clang.yml +++ b/.github/workflows/clang.yml @@ -33,6 +33,7 @@ jobs: PGP=5433 if [ "${{ matrix.psql }}" == "${pgver}" ]; then PGP=5432; fi echo "PGPORT=5432" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Add PostgreSQL APT repository run: | @@ -59,25 +60,35 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure run: | export PATH=/usr/lib/postgresql/${PGVER}/bin:$PATH mkdir build cd build - CXX=clang++ CC=clang cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=${{ matrix.release }} -DWITH_DOC=OFF -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + CXX=clang++ CC=clang cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=${{ matrix.release }} -DWITH_DOC=OFF -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build run: | diff --git a/.github/workflows/doc-check.yml b/.github/workflows/doc-check.yml index 1b4c99b8c..bcdcb5bfc 100644 --- a/.github/workflows/doc-check.yml +++ b/.github/workflows/doc-check.yml @@ -38,6 +38,7 @@ jobs: PROCESS=${{ true }} fi echo "PROCESS=${PROCESS}" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Get postgres version if: env.PROCESS == 'true' @@ -80,18 +81,28 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure if: env.PROCESS == 'true' @@ -102,7 +113,7 @@ jobs: cmake -DLINKCHECK=ON -DHTML=ON -DWITH_DOC=ON \ -DDE=ON -DES=ON -DFR=ON -DJA=ON -DIT=ON \ -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Release \ - -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Check Links if: env.PROCESS == 'true' diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 2d6368d0f..d932e37f6 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -29,6 +29,7 @@ jobs: pgver=$(psql --version | grep -Po '(?<=psql \(PostgreSQL\) )[^;]+(?=\.\d \()') echo "PGVER=${pgver}" >> $GITHUB_ENV echo "PGIS=3" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Add PostgreSQL APT repository run: | @@ -60,18 +61,28 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure link checks run: | @@ -80,7 +91,7 @@ jobs: cd build cmake -DPOSTGRESQL_VERSION=${PGVER} -DCMAKE_BUILD_TYPE=Release \ -DWITH_DOC=ON -DES=ON \ - -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build Documentation run: | diff --git a/.github/workflows/locale-and-website.yml b/.github/workflows/locale-and-website.yml index f0568fb96..d62d26523 100644 --- a/.github/workflows/locale-and-website.yml +++ b/.github/workflows/locale-and-website.yml @@ -30,6 +30,7 @@ jobs: echo "PGPORT=5432" >> $GITHUB_ENV echo "PGIS=3" >> $GITHUB_ENV echo "PROJECT_VERSION=${PROJECT_VERSION}" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Extract branch name and commit hash run: | @@ -70,25 +71,35 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure run: | export PATH=/usr/lib/postgresql/${PGVER}/bin:$PATH mkdir build cd build - cmake -DPOSTGRESQL_VERSION=${PGVER} -DDOC_USE_BOOTSTRAP=ON -DWITH_DOC=ON -DBUILD_DOXY=ON -DCMAKE_BUILD_TYPE=Release -DLOCALE=ON -DES=ON -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + cmake -DPOSTGRESQL_VERSION=${PGVER} -DDOC_USE_BOOTSTRAP=ON -DWITH_DOC=ON -DBUILD_DOXY=ON -DCMAKE_BUILD_TYPE=Release -DLOCALE=ON -DES=ON -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build run: | diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 1ce3b6007..490bbe12a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -27,11 +27,11 @@ jobs: run: | brew install openssl asio glpk - - name: Build VROOM v1.10.0 + - name: Build VROOM v1.11.0 run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.11.0.tar.gz + tar -zvxf v1.11.0.tar.gz + cd vroom-1.11.0/src # Source: https://github.com/VROOM-Project/vroom/issues/378 ln -s /usr/local/opt/openssl/include/openssl /usr/local/include diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58ccc570f..828a00df0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,7 @@ jobs: echo "PGPORT=5432" >> $GITHUB_ENV echo "PGIS=3" >> $GITHUB_ENV echo "PROJECT_VERSION=${PROJECT_VERSION}" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Verify Tag Name run: | @@ -78,25 +79,35 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure run: | export PATH=/usr/lib/postgresql/${PGVER}/bin:$PATH mkdir build cd build - cmake -DPOSTGRESQL_VERSION=${PGVER} -DDOC_USE_BOOTSTRAP=ON -DWITH_DOC=ON -DBUILD_DOXY=ON -DCMAKE_BUILD_TYPE=Release -DES=ON -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + cmake -DPOSTGRESQL_VERSION=${PGVER} -DDOC_USE_BOOTSTRAP=ON -DWITH_DOC=ON -DBUILD_DOXY=ON -DCMAKE_BUILD_TYPE=Release -DES=ON -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build run: | diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index ee25ea280..70986144d 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -37,6 +37,7 @@ jobs: PGP=5433 if [ "${{ matrix.psql }}" == "${pgver}" ]; then PGP=5432; fi echo "PGPORT=${PGP}" >> $GITHUB_ENV + echo "VROOMVER=1.11.0" >> $GITHUB_ENV - name: Add PostgreSQL APT repository run: | @@ -62,25 +63,35 @@ jobs: run: | sudo apt-get install libssl-dev libasio-dev libglpk-dev - - name: Build VROOM v1.10.0 + - name: Cache VROOM + id: cache-vroom + uses: actions/cache@v2 + env: + cache-name: vroom + with: + path: | + ~/vroom-${{ env.VROOMVER }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.VROOMVER }} + + - name: Build VROOM + if: steps.cache-vroom.outputs.cache-hit != 'true' run: | - wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v1.10.0.tar.gz - tar -zvxf v1.10.0.tar.gz - cd vroom-1.10.0/src + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${{ env.VROOMVER }}.tar.gz -O /tmp/${{ env.VROOMVER }}.tar.gz + tar -zvxf /tmp/${{ env.VROOMVER }}.tar.gz -C ~/ + cd ~/vroom-${{ env.VROOMVER }}/src # Create object file with position independent code using -fPIC flag sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + cd ~/vroom-${{ env.VROOMVER }}/src make - cd .. - echo "VROOM_INSTALL_PATH=$(pwd)" >> $GITHUB_ENV - name: Configure run: | export PATH=/usr/lib/postgresql/${{ matrix.psql }}/bin:$PATH mkdir build cd build - cmake -DPOSTGRESQL_VERSION=${{ matrix.psql }} -DCMAKE_BUILD_TYPE=${{ matrix.release }} -DWITH_DOC=OFF -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} .. + cmake -DPOSTGRESQL_VERSION=${{ matrix.psql }} -DCMAKE_BUILD_TYPE=${{ matrix.release }} -DWITH_DOC=OFF -DVROOM_INSTALL_PATH=$HOME/vroom-${{ env.VROOMVER }} .. - name: Build run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index f840df4d2..789944919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ set(DOXYGEN_MINIMUM_VERSION "1.7") set(SPHINX_MINIMUM_VERSION "1.8") set(POSTGRESQL_MINIMUM_VERSION "12.0") set(BOOST_MINIMUM_VERSION "1.65.0") -set(VROOM_MINIMUM_VERSION "1.10.0") +set(VROOM_MINIMUM_VERSION "1.11.0") message(STATUS "DOXYGEN_MINIMUM_VERSION=${DOXYGEN_MINIMUM_VERSION}") message(STATUS "SPHINX_MINIMUM_VERSION=${SPHINX_MINIMUM_VERSION}") diff --git a/NEWS b/NEWS index af868f168..8e1dfd633 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,33 @@ v0.3.0 Release Notes ******************************************************************************* +To see all issues & pull requests closed by this release see the [Git closed milestone for 0.3.0 ](https://github.com/pgRouting/vrprouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%200.3.0%22) on Github. + +*Modification of experimental functions* + +- VROOM + + - vrp_vroom + - vrp_vroomJobs + - vrp_vroomShipments + - vrp_vroomPlain + - vrp_vroomJobsPlain + - vrp_vroomShipmentsPlain + +*Added support for VROOM 1.11.0 (#24)* + +- Added setup time in jobs and shipments to refine service time modeling. +- Added support for custom cost matrices, along with the duration matrix. + - Using start_id, end_id, duration, cost as matrix table columns. +- Added timeout and exploration_level parameters to vroom-category functions. +- Added max_tasks column in vehicles. +- Added tests for empty skills arrays. +- Added custom scaling logic for speed_factor. +- Modified parameter names to make the naming consistent. + +*Fixes* + +- Honor client cancel requests for vroom-category functions. v0.2.0 Release Notes ******************************************************************************* diff --git a/README.md b/README.md index 5b4886f6b..3858aff88 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Status of the project can be found [here](https://github.com/pgRouting/vrproutin ## INTRODUCTION vrpRouting extends the pgRouting/PostGIS/PostgreSQL geospatial database to provide algorithms for Vehicle Routing Problems. -It requires VROOM as a dependency for building and computing the VRP solution. This release is compatible with VROOM version 1.10.0 +It requires VROOM as a dependency for building and computing the VRP solution. This release is compatible with VROOM version 1.11.0 This library is under development and currently contains the following functions: @@ -38,6 +38,8 @@ This library is under development and currently contains the following functions * `vrp_vroomJobs` * `vrp_vroomShipments` +The detailed steps for installation can be found [here](https://vrp.pgrouting.org/latest/en/installation.html). + ## REQUIREMENTS Building requirements @@ -48,7 +50,7 @@ Building requirements * The Boost Graph Library (BGL) >= 1.65 * CMake >= 3.12 * Sphinx > 4.0.0 -* VROOM >= 1.10.0 +* VROOM >= 1.11.0 User's requirements -------------------- diff --git a/cmake/pgr/Version.cmake b/cmake/pgr/Version.cmake index bc249eb99..d42545065 100644 --- a/cmake/pgr/Version.cmake +++ b/cmake/pgr/Version.cmake @@ -11,9 +11,9 @@ set(PROJECT_SHORT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}${PR set(PROJECT_FULL_VERSION "v${PROJECT_VERSION}${PROJECT_VERSION_DEV}") if (PROJECT_VERSION_DEV) - set(PROJECT_DOC_LINK "https://docs.pgrouting.org/dev/en") + set(PROJECT_DOC_LINK "https://vrp.pgrouting.org/dev/en") else() - set(PROJECT_DOC_LINK "https://docs.pgrouting.org/${PROJECT_LIB_VERSION}/en") + set(PROJECT_DOC_LINK "https://vrp.pgrouting.org/${PROJECT_LIB_VERSION}/en") endif() diff --git a/doc/general/installation.rst b/doc/general/installation.rst index 584b2b9b1..b156877a0 100644 --- a/doc/general/installation.rst +++ b/doc/general/installation.rst @@ -34,7 +34,7 @@ To get this release, download the repository or download the .. code-block:: bash git clone git://github.com/pgRouting/vrprouting.git - cd pgrouting + cd vrprouting git checkout v${PROJECT_VERSION} @@ -42,7 +42,7 @@ To get this release, download the repository or download the .. code-block:: bash - wget -O pgrouting-${PROJECT_VERSION}.tar.gz https://github.com/pgRouting/vrprouting/archive/v${PROJECT_VERSION}.tar.gz + wget -O vrprouting-${PROJECT_VERSION}.tar.gz https://github.com/pgRouting/vrprouting/archive/v${PROJECT_VERSION}.tar.gz Short Version @@ -53,8 +53,8 @@ Extracting the tar ball .. code-block:: bash - tar xvfz pgrouting-${PROJECT_VERSION}.tar.gz - cd pgrouting-${PROJECT_VERSION} + tar xvfz vrprouting-${PROJECT_VERSION}.tar.gz + cd vrprouting-${PROJECT_VERSION} To compile assuming you have all the dependencies in your search path: @@ -62,7 +62,7 @@ To compile assuming you have all the dependencies in your search path: mkdir build cd build - cmake .. + cmake .. make sudo make install @@ -106,17 +106,17 @@ To be able to compile vrpRouting, make sure that the following dependencies are .. TODO fill this numbers based on what is on the CMakeLists -* C++ compilers with support of C++14 and C11 -* Postgresql version >= 12 -* The Boost Graph Library (BGL). Version >= 1.65 -* CMake >= 3.2 - +* C and C++ compilers with C++17 standard support +* Postgresql version >= TBD +* The Boost Graph Library (BGL) >= 1.65 +* CMake >= 3.12 +* VROOM >= ${VROOM_MINIMUM_VERSION} .. rubric:: optional dependencies For user's documentation -* Sphinx >= TBD +* Sphinx > 4.0.0 * Latex For developer's documentation @@ -138,14 +138,16 @@ Installing the compilation dependencies .. rubric:: Database dependencies -This example is for PostgreSQL 10 +This example is for PostgreSQL 13 and PostGIS 3 .. code-block:: none sudo apt-get install - postgresql-10 \ - postgresql-server-dev-10 \ - postgresql-10-postgis + postgresql-13 \ + postgresql-server-dev-13 \ + postgresql-13-postgis-3 \ + postgresql-13-postgis-3-scripts \ + postgresql-13-pgrouting .. rubric:: Build dependencies @@ -157,6 +159,27 @@ This example is for PostgreSQL 10 g++ \ libboost-graph-dev +.. rubric:: Build dependencies (VROOM) + +Install VROOM dependencies + +.. code-block:: none + + sudo apt-get install libssl-dev libasio-dev libglpk-dev + +Build VROOM v${VROOM_MINIMUM_VERSION} + +.. code-block:: none + + wget https://github.com/VROOM-Project/vroom/archive/refs/tags/v${VROOM_MINIMUM_VERSION}.tar.gz + tar -zvxf v${VROOM_MINIMUM_VERSION}.tar.gz + cd vroom-${VROOM_MINIMUM_VERSION}/src + + # Create object file with position independent code using -fPIC flag + sed -i 's/CXXFLAGS = /CXXFLAGS = -fPIC /' makefile + + make + .. rubric:: Optional dependencies For documentation and testing @@ -167,7 +190,7 @@ For documentation and testing texlive \ doxygen \ libtap-parser-sourcehandler-pgtap-perl \ - postgresql-10-pgtap + postgresql-13-pgtap .. _install_configuring: @@ -190,11 +213,12 @@ Configurable variables .. rubric:: To see the variables that can be configured +Here, the variable VROOM_INSTALL_PATH corresponds to the location of the root directory of VROOM. .. code-block:: bash $ cd build - $ cmake -L .. + $ cmake -DVROOM_INSTALL_PATH=/path/to/vroom-dir/ -L .. .. rubric:: Configuring The Documentation @@ -217,7 +241,7 @@ Configuring with documentation .. code-block:: bash - $ cmake -DWITH_DOC=ON .. + $ cmake -DVROOM_INSTALL_PATH=${VROOM_INSTALL_PATH} -DWITH_DOC=ON .. .. note:: Most of the effort of the documentation has being on the html files. diff --git a/doc/general/release_notes.rst b/doc/general/release_notes.rst index 95b6da671..dae339e1c 100644 --- a/doc/general/release_notes.rst +++ b/doc/general/release_notes.rst @@ -25,6 +25,33 @@ To see the full list of changes check the list of `Git commits `_ on Github. + +.. rubric:: Modification of experimental functions + +- VROOM + + - vrp_vroom + - vrp_vroomJobs + - vrp_vroomShipments + - vrp_vroomPlain + - vrp_vroomJobsPlain + - vrp_vroomShipmentsPlain + +.. rubric:: Added support for VROOM 1.11.0 (#24) + +- Added setup time in jobs and shipments to refine service time modeling. +- Added support for custom cost matrices, along with the duration matrix. + - Using start_id, end_id, duration, cost as matrix table columns. +- Added timeout and exploration_level parameters to vroom-category functions. +- Added max_tasks column in vehicles. +- Added tests for empty skills arrays. +- Added custom scaling logic for speed_factor. +- Modified parameter names to make the naming consistent. + +.. rubric:: Fixes + +- Honor client cancel requests for vroom-category functions. v0.2.0 Release Notes ******************************************************************************* diff --git a/doc/general/vroom-category.rst b/doc/general/vroom-category.rst index 247228327..31675eebb 100644 --- a/doc/general/vroom-category.rst +++ b/doc/general/vroom-category.rst @@ -91,10 +91,20 @@ Terminologies - **Capacity (for vehicle)**: Every vehicle may have some capacity, denoting the multidimensional quantities. A vehicle can serve only those sets of tasks such that the total sum of the quantity does not exceed the vehicle capacity, at any point of the route. - **Time Window**: An interval of time during which some activity can be performed, such as working hours of the vehicle, break of the vehicle, or service start time for a task. - **Break**: Array of time windows, denoting valid slots for the break start of a vehicle. +- **Setup time**: Setup times serve as a mean to describe the time it takes to get started for a task at a given location. + This models a duration that should not be re-applied for other tasks following at the same place. + So the total "action time" for a task is ``setup + service`` upon arriving at a new location or + ``service`` only if performing a new task at the previous vehicle location. - **Service time**: The additional time to be spent by a vehicle while serving a task. - **Travel time**: The total time the vehicle travels during its route. - **Waiting time**: The total time the vehicle is idle, i.e. it is neither traveling nor servicing any task. It is generally the time spent by a vehicle waiting for a task service to open. +.. |timestamp| replace:: ``TIMESTAMP`` or ``INTEGER`` +.. |interval| replace:: ``INTERVAL`` or ``INTEGER`` +.. |interval0| replace:: '00:00:00'::INTERVAL or :math:`0` +.. |tw_open_default| replace:: '1970-01-01 00:00:00'::TIMESTAMP or :math:`0` +.. |tw_close_default| replace:: '2106-02-07 06:28:15'::TIMESTAMP or :math:`4294967295` + Inner Queries ------------------------------------------------------------------------------- @@ -138,7 +148,7 @@ Time Windows SQL Time Matrix SQL ............................................................................... -.. include:: ../../src/common/matrixRows_input.c +.. include:: ../../src/common/vroom/matrix_input.c :start-after: vrp_vroom start :end-before: vrp_vroom end diff --git a/doc/vroom/vrp_vroom.rst b/doc/vroom/vrp_vroom.rst index b02d6414b..01c85bea9 100644 --- a/doc/vroom/vrp_vroom.rst +++ b/doc/vroom/vrp_vroom.rst @@ -26,6 +26,10 @@ vrp_vroom - Experimental .. rubric:: Availability +Version 0.3.0 + +* Function **modified** for VROOM 1.11.0 + Version 0.2.0 * New **experimental** function @@ -45,10 +49,20 @@ shipments. Signature ------------------------------------------------------------------------------- +.. rubric:: Summary + .. include:: ../sql/vroom/vrp_vroom.sql :start-after: signature start :end-before: signature end +Optional parameters are `named parameters` and have a default value. + +.. rubric:: Using defaults + +.. include:: ../sql/vroom/vrp_vroom.sql + :start-after: default signature start + :end-before: default signature end + **Example**: This example is based on the modified VROOM Data of the :doc:`sampledata` network. The modification in the tables is mentioned at the end of the :doc:`sampledata`. @@ -56,6 +70,12 @@ The modification in the tables is mentioned at the end of the :doc:`sampledata`. :start-after: -- q1 :end-before: -- q2 +.. |timestamp| replace:: ``TIMESTAMP`` +.. |interval| replace:: ``INTERVAL`` +.. |interval0| replace:: '00:00:00'::INTERVAL +.. |tw_open_default| replace:: '1970-01-01 00:00:00'::TIMESTAMP +.. |tw_close_default| replace:: '2106-02-07 06:28:15'::TIMESTAMP + Parameters ------------------------------------------------------------------------------- @@ -63,6 +83,13 @@ Parameters :start-after: parameters start :end-before: parameters end +Optional Parameters +............................................................................... + +.. include:: ../sql/vroom/vrp_vroom.sql + :start-after: optional parameters start + :end-before: optional parameters end + Inner Queries ------------------------------------------------------------------------------- diff --git a/doc/vroom/vrp_vroomJobs.rst b/doc/vroom/vrp_vroomJobs.rst index 6c568a622..135872a95 100644 --- a/doc/vroom/vrp_vroomJobs.rst +++ b/doc/vroom/vrp_vroomJobs.rst @@ -26,6 +26,10 @@ vrp_vroomJobs - Experimental .. rubric:: Availability +Version 0.3.0 + +* Function **modified** for VROOM 1.11.0 + Version 0.2.0 * New **experimental** function @@ -44,10 +48,20 @@ This function can be used to get the solution to a problem involving only jobs. Signature ------------------------------------------------------------------------------- +.. rubric:: Summary + .. include:: ../sql/vroom/vrp_vroomJobs.sql :start-after: signature start :end-before: signature end +Optional parameters are `named parameters` and have a default value. + +.. rubric:: Using defaults + +.. include:: ../sql/vroom/vrp_vroomJobs.sql + :start-after: default signature start + :end-before: default signature end + **Example**: This example is based on the modified VROOM Data of the :doc:`sampledata` network. The modification in the tables is mentioned at the end of the :doc:`sampledata`. @@ -55,6 +69,12 @@ The modification in the tables is mentioned at the end of the :doc:`sampledata`. :start-after: -- q1 :end-before: -- q2 +.. |timestamp| replace:: ``TIMESTAMP`` +.. |interval| replace:: ``INTERVAL`` +.. |interval0| replace:: '00:00:00'::INTERVAL +.. |tw_open_default| replace:: '1970-01-01 00:00:00'::TIMESTAMP +.. |tw_close_default| replace:: '2106-02-07 06:28:15'::TIMESTAMP + Parameters ------------------------------------------------------------------------------- @@ -62,6 +82,13 @@ Parameters :start-after: parameters start :end-before: parameters end +Optional Parameters +............................................................................... + +.. include:: ../sql/vroom/vrp_vroom.sql + :start-after: optional parameters start + :end-before: optional parameters end + Inner Queries ------------------------------------------------------------------------------- diff --git a/doc/vroom/vrp_vroomJobsPlain.rst b/doc/vroom/vrp_vroomJobsPlain.rst index db7a5c73f..63537e8b7 100644 --- a/doc/vroom/vrp_vroomJobsPlain.rst +++ b/doc/vroom/vrp_vroomJobsPlain.rst @@ -18,7 +18,7 @@ vrp_vroomJobsPlain - Experimental =============================================================================== -``vrp_vroomJobsPlain`` - Vehicle Routing Problem with VROOM, involving only jobs. +``vrp_vroomJobsPlain`` - Vehicle Routing Problem with VROOM, involving only jobs, with plain integer values instead of TIMESTAMP or INTERVAL. .. include:: experimental.rst :start-after: begin-warn-expr @@ -26,6 +26,10 @@ vrp_vroomJobsPlain - Experimental .. rubric:: Availability +Version 0.3.0 + +* Function **modified** for VROOM 1.11.0 + Version 0.2.0 * New **experimental** function @@ -44,16 +48,32 @@ This function can be used to get the solution to a problem involving only jobs. Signature ------------------------------------------------------------------------------- -.. include:: ../sql/vroom/vrp_vroomJobs.sql +.. rubric:: Summary + +.. include:: ../sql/vroom/vrp_vroomJobsPlain.sql :start-after: signature start :end-before: signature end +Optional parameters are `named parameters` and have a default value. + +.. rubric:: Using defaults + +.. include:: ../sql/vroom/vrp_vroomJobsPlain.sql + :start-after: default signature start + :end-before: default signature end + **Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: .. literalinclude:: doc-vrp_vroomJobsPlain.queries :start-after: -- q1 :end-before: -- q2 +.. |timestamp| replace:: ``INTEGER`` +.. |interval| replace:: ``INTEGER`` +.. |interval0| replace:: :math:`0` +.. |tw_open_default| replace:: :math:`0` +.. |tw_close_default| replace:: :math:`4294967295` + Parameters ------------------------------------------------------------------------------- @@ -61,6 +81,13 @@ Parameters :start-after: parameters start :end-before: parameters end +Optional Parameters +............................................................................... + +.. include:: ../sql/vroom/vrp_vroomPlain.sql + :start-after: optional parameters start + :end-before: optional parameters end + Inner Queries ------------------------------------------------------------------------------- diff --git a/doc/vroom/vrp_vroomPlain.rst b/doc/vroom/vrp_vroomPlain.rst index 79788d290..9b4a0911b 100644 --- a/doc/vroom/vrp_vroomPlain.rst +++ b/doc/vroom/vrp_vroomPlain.rst @@ -18,7 +18,7 @@ vrp_vroomPlain - Experimental =============================================================================== -``vrp_vroomPlain`` - Vehicle Routing Problem with VROOM, involving both jobs and shipments. +``vrp_vroomPlain`` - Vehicle Routing Problem with VROOM, involving both jobs and shipments, with plain integer values instead of TIMESTAMP or INTERVAL. .. include:: experimental.rst :start-after: begin-warn-expr @@ -26,6 +26,10 @@ vrp_vroomPlain - Experimental .. rubric:: Availability +Version 0.3.0 + +* Function **modified** for VROOM 1.11.0 + Version 0.2.0 * New **experimental** function @@ -45,16 +49,32 @@ shipments. Signature ------------------------------------------------------------------------------- -.. include:: ../sql/vroom/vrp_vroom.sql +.. rubric:: Summary + +.. include:: ../sql/vroom/vrp_vroomPlain.sql :start-after: signature start :end-before: signature end +Optional parameters are `named parameters` and have a default value. + +.. rubric:: Using defaults + +.. include:: ../sql/vroom/vrp_vroomPlain.sql + :start-after: default signature start + :end-before: default signature end + **Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: .. literalinclude:: doc-vrp_vroomPlain.queries :start-after: -- q1 :end-before: -- q2 +.. |timestamp| replace:: ``INTEGER`` +.. |interval| replace:: ``INTEGER`` +.. |interval0| replace:: :math:`0` +.. |tw_open_default| replace:: :math:`0` +.. |tw_close_default| replace:: :math:`4294967295` + Parameters ------------------------------------------------------------------------------- @@ -62,6 +82,13 @@ Parameters :start-after: parameters start :end-before: parameters end +Optional Parameters +............................................................................... + +.. include:: ../sql/vroom/vrp_vroomPlain.sql + :start-after: optional parameters start + :end-before: optional parameters end + Inner Queries ------------------------------------------------------------------------------- diff --git a/doc/vroom/vrp_vroomShipments.rst b/doc/vroom/vrp_vroomShipments.rst index 5903a0b0b..a0aba0580 100644 --- a/doc/vroom/vrp_vroomShipments.rst +++ b/doc/vroom/vrp_vroomShipments.rst @@ -26,6 +26,10 @@ vrp_vroomShipments - Experimental .. rubric:: Availability +Version 0.3.0 + +* Function **modified** for VROOM 1.11.0 + Version 0.2.0 * New **experimental** function @@ -44,10 +48,20 @@ This function can be used to get the solution to a problem involving only shipme Signature ------------------------------------------------------------------------------- +.. rubric:: Summary + .. include:: ../sql/vroom/vrp_vroomShipments.sql :start-after: signature start :end-before: signature end +Optional parameters are `named parameters` and have a default value. + +.. rubric:: Using defaults + +.. include:: ../sql/vroom/vrp_vroomShipments.sql + :start-after: default signature start + :end-before: default signature end + **Example**: This example is based on the modified VROOM Data of the :doc:`sampledata` network. The modification in the tables is mentioned at the end of the :doc:`sampledata`. @@ -55,6 +69,12 @@ The modification in the tables is mentioned at the end of the :doc:`sampledata`. :start-after: -- q1 :end-before: -- q2 +.. |timestamp| replace:: ``TIMESTAMP`` +.. |interval| replace:: ``INTERVAL`` +.. |interval0| replace:: '00:00:00'::INTERVAL +.. |tw_open_default| replace:: '1970-01-01 00:00:00'::TIMESTAMP +.. |tw_close_default| replace:: '2106-02-07 06:28:15'::TIMESTAMP + Parameters ------------------------------------------------------------------------------- @@ -62,6 +82,13 @@ Parameters :start-after: parameters start :end-before: parameters end +Optional Parameters +............................................................................... + +.. include:: ../sql/vroom/vrp_vroom.sql + :start-after: optional parameters start + :end-before: optional parameters end + Inner Queries ------------------------------------------------------------------------------- diff --git a/doc/vroom/vrp_vroomShipmentsPlain.rst b/doc/vroom/vrp_vroomShipmentsPlain.rst index 093f8582e..88e86d152 100644 --- a/doc/vroom/vrp_vroomShipmentsPlain.rst +++ b/doc/vroom/vrp_vroomShipmentsPlain.rst @@ -18,7 +18,7 @@ vrp_vroomShipmentsPlain - Experimental =============================================================================== -``vrp_vroomShipmentsPlain`` - Vehicle Routing Problem with VROOM, involving only shipments. +``vrp_vroomShipmentsPlain`` - Vehicle Routing Problem with VROOM, involving only shipments, with plain integer values instead of TIMESTAMP or INTERVAL. .. include:: experimental.rst :start-after: begin-warn-expr @@ -26,6 +26,10 @@ vrp_vroomShipmentsPlain - Experimental .. rubric:: Availability +Version 0.3.0 + +* Function **modified** for VROOM 1.11.0 + Version 0.2.0 * New **experimental** function @@ -44,16 +48,32 @@ This function can be used to get the solution to a problem involving only shipme Signature ------------------------------------------------------------------------------- -.. include:: ../sql/vroom/vrp_vroomShipments.sql +.. rubric:: Summary + +.. include:: ../sql/vroom/vrp_vroomShipmentsPlain.sql :start-after: signature start :end-before: signature end +Optional parameters are `named parameters` and have a default value. + +.. rubric:: Using defaults + +.. include:: ../sql/vroom/vrp_vroomShipmentsPlain.sql + :start-after: default signature start + :end-before: default signature end + **Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: .. literalinclude:: doc-vrp_vroomShipmentsPlain.queries :start-after: -- q1 :end-before: -- q2 +.. |timestamp| replace:: ``INTEGER`` +.. |interval| replace:: ``INTEGER`` +.. |interval0| replace:: :math:`0` +.. |tw_open_default| replace:: :math:`0` +.. |tw_close_default| replace:: :math:`4294967295` + Parameters ------------------------------------------------------------------------------- @@ -61,6 +81,13 @@ Parameters :start-after: parameters start :end-before: parameters end +Optional Parameters +............................................................................... + +.. include:: ../sql/vroom/vrp_vroomPlain.sql + :start-after: optional parameters start + :end-before: optional parameters end + Inner Queries ------------------------------------------------------------------------------- diff --git a/docqueries/vroom/doc-vrp_vroom.result b/docqueries/vroom/doc-vrp_vroom.result index 85468ee55..6deb0b5b9 100644 --- a/docqueries/vroom/doc-vrp_vroom.result +++ b/docqueries/vroom/doc-vrp_vroom.result @@ -27,6 +27,8 @@ ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING ALTER TABLE ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); +ALTER TABLE /* -- q1 */ SELECT * FROM vrp_vroom( @@ -76,29 +78,29 @@ FROM vrp_vroom( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, $matrix$ - SELECT * FROM ( + SELECT start_id, end_id, make_interval(secs => duration) AS duration FROM ( VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load diff --git a/docqueries/vroom/doc-vrp_vroom.test.sql b/docqueries/vroom/doc-vrp_vroom.test.sql index dc9494d3b..d3944bf03 100644 --- a/docqueries/vroom/doc-vrp_vroom.test.sql +++ b/docqueries/vroom/doc-vrp_vroom.test.sql @@ -11,6 +11,8 @@ ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USI ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); + /* -- q1 */ SELECT * FROM vrp_vroom( @@ -29,29 +31,29 @@ FROM vrp_vroom( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, $matrix$ - SELECT * FROM ( + SELECT start_id, end_id, make_interval(secs => duration) AS duration FROM ( VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); /* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomJobs.result b/docqueries/vroom/doc-vrp_vroomJobs.result index 990086503..97d6bf916 100644 --- a/docqueries/vroom/doc-vrp_vroomJobs.result +++ b/docqueries/vroom/doc-vrp_vroomJobs.result @@ -27,6 +27,8 @@ ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING ALTER TABLE ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); +ALTER TABLE /* -- q1 */ SELECT * FROM vrp_vroomJobs( @@ -58,23 +60,23 @@ FROM vrp_vroomJobs( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, $matrix$ - SELECT * FROM ( + SELECT start_id, end_id, make_interval(secs => duration) AS duration FROM ( VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load diff --git a/docqueries/vroom/doc-vrp_vroomJobs.test.sql b/docqueries/vroom/doc-vrp_vroomJobs.test.sql index 5974cb279..b5c8782e3 100644 --- a/docqueries/vroom/doc-vrp_vroomJobs.test.sql +++ b/docqueries/vroom/doc-vrp_vroomJobs.test.sql @@ -11,6 +11,7 @@ ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USI ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); /* -- q1 */ SELECT * FROM vrp_vroomJobs( @@ -27,23 +28,23 @@ FROM vrp_vroomJobs( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, $matrix$ - SELECT * FROM ( + SELECT start_id, end_id, make_interval(secs => duration) AS duration FROM ( VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); /* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomJobsPlain.result b/docqueries/vroom/doc-vrp_vroomJobsPlain.result index d520a7371..e2c08b56b 100644 --- a/docqueries/vroom/doc-vrp_vroomJobsPlain.result +++ b/docqueries/vroom/doc-vrp_vroomJobsPlain.result @@ -33,13 +33,13 @@ FROM vrp_vroomJobsPlain( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, @@ -49,7 +49,7 @@ FROM vrp_vroomJobsPlain( (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load diff --git a/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql b/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql index aa82a70c4..45ab67143 100644 --- a/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql +++ b/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql @@ -14,13 +14,13 @@ FROM vrp_vroomJobsPlain( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, @@ -30,7 +30,7 @@ FROM vrp_vroomJobsPlain( (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); /* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomPlain.result b/docqueries/vroom/doc-vrp_vroomPlain.result index 32a9adadf..7b47d32e2 100644 --- a/docqueries/vroom/doc-vrp_vroomPlain.result +++ b/docqueries/vroom/doc-vrp_vroomPlain.result @@ -51,19 +51,19 @@ FROM vrp_vroomPlain( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, @@ -73,7 +73,7 @@ FROM vrp_vroomPlain( (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load diff --git a/docqueries/vroom/doc-vrp_vroomPlain.test.sql b/docqueries/vroom/doc-vrp_vroomPlain.test.sql index 11140d50e..8dce884c4 100644 --- a/docqueries/vroom/doc-vrp_vroomPlain.test.sql +++ b/docqueries/vroom/doc-vrp_vroomPlain.test.sql @@ -16,19 +16,19 @@ FROM vrp_vroomPlain( $jobs$ SELECT * FROM ( VALUES (1414, 2), (1515, 3) - ) AS C(id, location_index) + ) AS C(id, location_id) $jobs$, NULL, $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, @@ -38,7 +38,7 @@ FROM vrp_vroomPlain( (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); /* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomShipments.result b/docqueries/vroom/doc-vrp_vroomShipments.result index 9b180bc5b..86a49a16d 100644 --- a/docqueries/vroom/doc-vrp_vroomShipments.result +++ b/docqueries/vroom/doc-vrp_vroomShipments.result @@ -27,6 +27,8 @@ ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING ALTER TABLE ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); +ALTER TABLE /* -- q1 */ SELECT * FROM vrp_vroomShipments( @@ -63,23 +65,23 @@ FROM vrp_vroomShipments( $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, $matrix$ - SELECT * FROM ( + SELECT start_id, end_id, make_interval(secs => duration) AS duration FROM ( VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load diff --git a/docqueries/vroom/doc-vrp_vroomShipments.test.sql b/docqueries/vroom/doc-vrp_vroomShipments.test.sql index d7ad0754f..826fe5af1 100644 --- a/docqueries/vroom/doc-vrp_vroomShipments.test.sql +++ b/docqueries/vroom/doc-vrp_vroomShipments.test.sql @@ -11,6 +11,7 @@ ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USI ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); /* -- q1 */ SELECT * FROM vrp_vroomShipments( @@ -27,23 +28,23 @@ FROM vrp_vroomShipments( $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, $matrix$ - SELECT * FROM ( + SELECT start_id, end_id, make_interval(secs => duration) AS duration FROM ( VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); /* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result index e6d4e89b9..726b7c3a4 100644 --- a/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result +++ b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result @@ -38,13 +38,13 @@ FROM vrp_vroomShipmentsPlain( $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, @@ -54,7 +54,7 @@ FROM vrp_vroomShipmentsPlain( (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load diff --git a/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql index ba20c6937..3631bb1f2 100644 --- a/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql +++ b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql @@ -14,13 +14,13 @@ FROM vrp_vroomShipmentsPlain( $shipments$ SELECT * FROM ( VALUES (100, 1, 4) - ) AS C(id, p_location_index, d_location_index) + ) AS C(id, p_location_id, d_location_id) $shipments$, NULL, $vehicles$ SELECT * FROM ( VALUES (1, 1, 4) - ) AS C(id, start_index, end_index) + ) AS C(id, start_id, end_id) $vehicles$, NULL, NULL, @@ -30,7 +30,7 @@ FROM vrp_vroomShipmentsPlain( (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), (3, 1, 197), (3, 2, 2256), (3, 4, 1102), (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) - ) AS C(start_vid, end_vid, agg_cost) + ) AS C(start_id, end_id, duration) $matrix$ ); /* -- q3 */ diff --git a/include/c_common/get_check_data.h b/include/c_common/get_check_data.h index c8fdf224c..3c067f210 100644 --- a/include/c_common/get_check_data.h +++ b/include/c_common/get_check_data.h @@ -92,6 +92,12 @@ spi_getText( TupleDesc *tupdesc, Column_info_t info); +/** @brief gets the vehicle max tasks value */ +int32_t +spi_getMaxTasks( + HeapTuple *tuple, + TupleDesc *tupdesc, + Column_info_t info); /** @name timestamp related * @{ */ @@ -141,6 +147,9 @@ MatrixIndex get_MatrixIndex(HeapTuple*, TupleDesc*, Column_info_t, MatrixIndex); /** get Duration from data */ Duration get_Duration(HeapTuple*, TupleDesc*, Column_info_t, Duration); +/** get TravelCost from data */ +TravelCost get_Cost(HeapTuple*, TupleDesc*, Column_info_t, TravelCost); + /** get Kind from data */ char get_Kind(HeapTuple*, TupleDesc*, Column_info_t, char); diff --git a/include/c_common/matrixRows_input.h b/include/c_common/matrixRows_input.h index 2c3c473c0..5e3169981 100644 --- a/include/c_common/matrixRows_input.h +++ b/include/c_common/matrixRows_input.h @@ -42,10 +42,4 @@ void get_matrixRows_plain( Matrix_cell_t **rows, size_t *total_rows); -/** @brief Get the travel time matrix of vroom with integer types*/ -void get_matrixRows_vroom_plain( - char *sql, - Matrix_cell_t **rows, - size_t *total_rows); - #endif // INCLUDE_C_COMMON_MATRIXROWS_INPUT_H_ diff --git a/include/c_common/vroom/matrix_input.h b/include/c_common/vroom/matrix_input.h new file mode 100644 index 000000000..e3f39a8e0 --- /dev/null +++ b/include/c_common/vroom/matrix_input.h @@ -0,0 +1,52 @@ +/*PGR-GNU***************************************************************** +File: matrix_input.h + +Copyright (c) 2021 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2021 Ashish Kumar +Mail: ashishkr23438@gmail.com + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#ifndef INCLUDE_C_COMMON_VROOM_MATRIX_INPUT_H_ +#define INCLUDE_C_COMMON_VROOM_MATRIX_INPUT_H_ +#pragma once + +#include + +#include "c_common/get_check_data.h" +#include "c_types/column_info_t.h" +#include "c_types/vroom/vroom_matrix_t.h" + +#ifdef PROFILE +#include "c_common/debug_macro.h" +#include "c_common/time_msg.h" +#endif + +/** @brief Reads the VROOM matrix */ +void +get_vroom_matrix( + char *matrix_sql, + Vroom_matrix_t **matrix, + size_t *total_matrix_rows, + bool is_plain); + +#endif // INCLUDE_C_COMMON_VROOM_MATRIX_INPUT_H_ diff --git a/include/c_types/typedefs.h b/include/c_types/typedefs.h index 9a8117d2c..0c547becf 100644 --- a/include/c_types/typedefs.h +++ b/include/c_types/typedefs.h @@ -41,6 +41,7 @@ using Id = int64_t; using Idx = uint64_t; using MatrixIndex = int64_t; using Duration = uint32_t; +using TravelCost = uint32_t; using Priority = uint32_t; using Distance = uint32_t; using Skill = uint32_t; @@ -54,6 +55,7 @@ using Short_vehicle_rt = struct Short_vehicle_rt; using Vroom_job_t = struct Vroom_job_t; using Vroom_shipment_t = struct Vroom_shipment_t; using Vroom_vehicle_t = struct Vroom_vehicle_t; +using Vroom_matrix_t = struct Vroom_matrix_t; using Vroom_break_t = struct Vroom_break_t; using Vroom_time_window_t = struct Vroom_time_window_t; using Vroom_rt = struct Vroom_rt; @@ -75,6 +77,7 @@ typedef int64_t Id; typedef uint64_t Idx; typedef int64_t MatrixIndex; typedef uint32_t Duration; +typedef uint32_t TravelCost; typedef uint32_t Priority; typedef uint32_t Distance; typedef uint32_t Skill; @@ -88,6 +91,7 @@ typedef struct Short_vehicle_rt Short_vehicle_rt; typedef struct Vroom_job_t Vroom_job_t; typedef struct Vroom_shipment_t Vroom_shipment_t; typedef struct Vroom_vehicle_t Vroom_vehicle_t; +typedef struct Vroom_matrix_t Vroom_matrix_t; typedef struct Vroom_break_t Vroom_break_t; typedef struct Vroom_time_window_t Vroom_time_window_t; typedef struct Vroom_rt Vroom_rt; diff --git a/include/c_types/vroom/vroom_job_t.h b/include/c_types/vroom/vroom_job_t.h index 76e3af6b5..a112785a9 100644 --- a/include/c_types/vroom/vroom_job_t.h +++ b/include/c_types/vroom/vroom_job_t.h @@ -39,7 +39,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. name | description :----- | :------- id | The job's identifier -location_index | Location index of job in matrix +location_id | Location index of job in matrix +setup | Job setup duration service | Job service duration delivery | Quantities for delivery delivery_size | Number of delivery quantities @@ -51,8 +52,9 @@ priority | Priority level of job */ struct Vroom_job_t { Idx id; /** The job's identifier */ - MatrixIndex location_index; /** Location index of job in matrix */ + MatrixIndex location_id; /** Location index of job in matrix */ + Duration setup; /** Job setup duration */ Duration service; /** Job service duration */ Amount *delivery; /** Quantities for delivery */ diff --git a/include/c_types/vroom/vroom_matrix_t.h b/include/c_types/vroom/vroom_matrix_t.h new file mode 100644 index 000000000..8bff753bf --- /dev/null +++ b/include/c_types/vroom/vroom_matrix_t.h @@ -0,0 +1,54 @@ +/*PGR-GNU***************************************************************** +File: vroom_matrix_t.h + +Copyright (c) 2021 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2021 Ashish Kumar +Mail: ashishkr23438@gmail.com + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ +/*! @file */ + +#ifndef INCLUDE_C_TYPES_VROOM_VROOM_MATRIX_T_H_ +#define INCLUDE_C_TYPES_VROOM_VROOM_MATRIX_T_H_ +#pragma once + +#include "c_types/typedefs.h" + +/** @brief Matrix's attributes + +@note C/C++/postgreSQL connecting structure for input +name | description +:----- | :------- +start_id | Start node identifier +end_id | End node identifier +duration | Duration to travel from start to end +cost | Cost to travel from start to end +*/ +struct Vroom_matrix_t { + MatrixIndex start_id; /** Start node identifier */ + MatrixIndex end_id; /** End node identifier */ + + Duration duration; /** Duration to travel from start to end */ + TravelCost cost; /** Cost to travel from start to end */ +}; + +#endif // INCLUDE_C_TYPES_VROOM_VROOM_MATRIX_T_H_ diff --git a/include/c_types/vroom/vroom_shipment_t.h b/include/c_types/vroom/vroom_shipment_t.h index ed61b60c4..6a91bfdaf 100644 --- a/include/c_types/vroom/vroom_shipment_t.h +++ b/include/c_types/vroom/vroom_shipment_t.h @@ -39,9 +39,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. name | description :----- | :------- id | Shipment identifier -p_location_index | Pickup location index in matrix +p_location_id | Pickup location index in matrix +p_setup | Pickup setup time p_service | Pickup service time -d_location_index | Delivery location index in matrix +d_location_id | Delivery location index in matrix +d_setup | Delivery setup time d_service | Delivery service time amount | Quantities for shipment amount_size | Number of quantities @@ -53,11 +55,13 @@ struct Vroom_shipment_t { Idx id; /** Shipment identifier */ /** pickup shipment */ - MatrixIndex p_location_index; /** Pickup location index in matrix */ + MatrixIndex p_location_id; /** Pickup location index in matrix */ + Duration p_setup; /** Pickup setup time */ Duration p_service; /** Pickup service time */ /** delivery shipment */ - MatrixIndex d_location_index; /** Delivery location index in matrix */ + MatrixIndex d_location_id; /** Delivery location index in matrix */ + Duration d_setup; /** Delivery setup time */ Duration d_service; /** Delivery service time */ Amount *amount; /** Quantities for shipment */ diff --git a/include/c_types/vroom/vroom_time_window_t.h b/include/c_types/vroom/vroom_time_window_t.h index 99e7dd86b..862872a3c 100644 --- a/include/c_types/vroom/vroom_time_window_t.h +++ b/include/c_types/vroom/vroom_time_window_t.h @@ -40,14 +40,14 @@ name | description :----- | :------- id | Identifier of the job/shipment/break kind | Whether the shipment is a pickup ('p') or a delivery ('d') -start_time | Time window start time -end_time | Time window end time +tw_open | Time window opening time +tw_close | Time window closing time */ struct Vroom_time_window_t { Idx id; char kind; - Duration start_time; - Duration end_time; + Duration tw_open; + Duration tw_close; }; #endif // INCLUDE_C_TYPES_VROOM_VROOM_TIME_WINDOW_T_H_ diff --git a/include/c_types/vroom/vroom_vehicle_t.h b/include/c_types/vroom/vroom_vehicle_t.h index 4231297e3..cef344ee3 100644 --- a/include/c_types/vroom/vroom_vehicle_t.h +++ b/include/c_types/vroom/vroom_vehicle_t.h @@ -39,20 +39,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. name | description :----- | :------- id | The vehicle's identifier -start_index | Start location index in matrix -end_index | End location index in matrix +start_id | Start location index in matrix +end_id | End location index in matrix capacity | Vehicle's capacity array capacity_size | Vehicle's capacity array size skills | Vehicle's skills skills_size | Number of vehicle's skills -time_window_start | Time window start time -time_window_end | Time window end time +tw_open | Time window start time +tw_close | Time window end time speed_factor | Vehicle travel time multiplier +max_tasks | Max number of tasks in a route for the vehicle */ struct Vroom_vehicle_t { Idx id; /** The vehicle's identifier */ - MatrixIndex start_index; /** Start location index in matrix */ - MatrixIndex end_index; /** End location index in matrix */ + MatrixIndex start_id; /** Start location index in matrix */ + MatrixIndex end_id; /** End location index in matrix */ Amount *capacity; /** Vehicle's capacity array */ size_t capacity_size; /** Vehicle's capacity array size */ @@ -60,10 +61,12 @@ struct Vroom_vehicle_t { Skill *skills; /** Vehicle's skills */ size_t skills_size; /** Number of vehicle's skills */ - Duration time_window_start; /** Time window start time */ - Duration time_window_end; /** Time window end time */ + Duration tw_open; /** Time window start time */ + Duration tw_close; /** Time window end time */ double speed_factor; /** Vehicle travel time multiplier */ + + int32_t max_tasks; /** Max number of tasks in a route for the vehicle */ }; diff --git a/include/cpp_common/base_matrix.h b/include/cpp_common/base_matrix.h index 16be2d7cf..a3ba0023f 100644 --- a/include/cpp_common/base_matrix.h +++ b/include/cpp_common/base_matrix.h @@ -64,7 +64,7 @@ class Base_Matrix { Base_Matrix() = default; /** @brief Constructs a matrix for only specific identifiers */ Base_Matrix(Matrix_cell_t *, size_t, const Identifiers&, Multiplier); - Base_Matrix(Matrix_cell_t *, size_t, const Identifiers &); + Base_Matrix(Vroom_matrix_t *, size_t, const Identifiers &, double); explicit Base_Matrix(const std::map, Id> &, Multiplier); /** @name status of the matrix @@ -73,7 +73,8 @@ class Base_Matrix { /** @brief does the matrix values not given by the user? */ bool has_no_infinity() const; - vroom::Matrix get_vroom_matrix() const; + vroom::Matrix get_vroom_duration_matrix() const; + vroom::Matrix get_vroom_cost_matrix() const; /** @brief does the matrix obeys the triangle inequality? */ bool obeys_triangle_inequality() const; @@ -120,6 +121,12 @@ class Base_Matrix { * m_time_matrix[i][j] i and j are index from the ids */ std::vector> m_time_matrix; + + /** @brief the cost matrix for vroom + * + * m_cost_matrix[i][j] i and j are index from the ids + */ + std::vector> m_cost_matrix; }; } // namespace base diff --git a/include/cpp_common/interruption.h b/include/cpp_common/interruption.h index c09686141..312b9dcad 100644 --- a/include/cpp_common/interruption.h +++ b/include/cpp_common/interruption.h @@ -27,9 +27,60 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #ifndef INCLUDE_CPP_COMMON_INTERRUPTION_H_ #define INCLUDE_CPP_COMMON_INTERRUPTION_H_ +#ifdef _MSC_VER +#define __PGR_PRETTY_FUNCTION__ __FUNCSIG__ +#else +#define __PGR_PRETTY_FUNCTION__ __PRETTY_FUNCTION__ +#endif + extern "C" { -#include + +#ifdef _MSC_VER + #include +#include + +#else +/* + * Instead of including all the files + * copy/paste what is used + * IMPORTANT: this copy/paste might depend on the postgreSQL version + */ +#include + +/* + * https://doxygen.postgresql.org/c_8h.html#a166c1d950e659804f0e3247aad99a81f + */ +#define PGDLLIMPORT + +/* + * https://doxygen.postgresql.org/miscadmin_8h_source.html + */ +extern PGDLLIMPORT volatile sig_atomic_t InterruptPending; +extern void ProcessInterrupts(void); + +#if __GNUC__ >= 3 +#define unlikely(x) __builtin_expect((x) != 0, 0) +#else +#define unlikely(x) ((x) != 0) +#endif + +/* Test whether an interrupt is pending */ +#ifndef WIN32 +#define INTERRUPTS_PENDING_CONDITION() (unlikely(InterruptPending)) +#else +extern void pgwin32_dispatch_queued_signals(void); +#define INTERRUPTS_PENDING_CONDITION() \ + (unlikely(UNBLOCKED_SIGNAL_QUEUE()) ? pgwin32_dispatch_queued_signals() : 0, \ + unlikely(InterruptPending)) +#endif + +/* Service interrupt, if one is pending and it's safe to service it now */ +#define CHECK_FOR_INTERRUPTS() \ + do { \ + if (INTERRUPTS_PENDING_CONDITION()) ProcessInterrupts(); \ + } while (0) +#endif } #endif // INCLUDE_CPP_COMMON_INTERRUPTION_H_ diff --git a/include/cpp_common/vrp_vroom_problem.hpp b/include/cpp_common/vrp_vroom_problem.hpp index be9309bb1..87bcef85a 100644 --- a/include/cpp_common/vrp_vroom_problem.hpp +++ b/include/cpp_common/vrp_vroom_problem.hpp @@ -29,22 +29,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_CPP_COMMON_VRP_VROOM_PROBLEM_HPP_ #pragma once -#include -#include #include +#include #include #include +#include +#include "c_types/matrix_cell_t.h" +#include "c_types/vroom/vroom_break_t.h" #include "c_types/vroom/vroom_job_t.h" #include "c_types/vroom/vroom_rt.h" -#include "c_types/vroom/vroom_break_t.h" #include "c_types/vroom/vroom_shipment_t.h" #include "c_types/vroom/vroom_time_window_t.h" #include "c_types/vroom/vroom_vehicle_t.h" -#include "c_types/matrix_cell_t.h" -#include "cpp_common/pgr_messages.h" #include "cpp_common/base_matrix.h" - +#include "cpp_common/interruption.h" +#include "cpp_common/pgr_messages.h" #include "structures/vroom/input/input.h" #include "structures/vroom/job.h" #include "structures/vroom/vehicle.h" @@ -72,13 +72,13 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { vroom::TimeWindow get_vroom_time_window(const Vroom_time_window_t &time_window) const { return - vroom::TimeWindow(time_window.start_time, - time_window.end_time); + vroom::TimeWindow(time_window.tw_open, + time_window.tw_close); } vroom::TimeWindow - get_vroom_time_window(Duration start_time, Duration end_time) const { - return vroom::TimeWindow(start_time, end_time); + get_vroom_time_window(Duration tw_open, Duration tw_close) const { + return vroom::TimeWindow(tw_open, tw_close); } std::vector @@ -176,9 +176,9 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { get_vroom_skills(job.skills, job.skills_size); std::vector time_windows = get_vroom_time_windows(job_tws); - vroom::Index location_index = - static_cast(m_matrix.get_index(job.location_index)); - return vroom::Job(job.id, location_index, job.service, delivery, pickup, + vroom::Index location_id = + static_cast(m_matrix.get_index(job.location_id)); + return vroom::Job(job.id, location_id, job.setup, job.service, delivery, pickup, skills, job.priority, time_windows); } @@ -236,16 +236,18 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { get_vroom_time_windows(pickup_tws); std::vector d_time_windows = get_vroom_time_windows(delivery_tws); - vroom::Index p_location_index = static_cast( - m_matrix.get_index(shipment.p_location_index)); - vroom::Index d_location_index = static_cast( - m_matrix.get_index(shipment.d_location_index)); - vroom::Job pickup = vroom::Job(shipment.id, vroom::JOB_TYPE::PICKUP, - p_location_index, shipment.p_service, amount, - skills, shipment.priority, p_time_windows); + vroom::Index p_location_id = static_cast( + m_matrix.get_index(shipment.p_location_id)); + vroom::Index d_location_id = static_cast( + m_matrix.get_index(shipment.d_location_id)); + vroom::Job pickup = vroom::Job( + shipment.id, vroom::JOB_TYPE::PICKUP, p_location_id, + shipment.p_setup, shipment.p_service, amount, + skills, shipment.priority, p_time_windows); vroom::Job delivery = vroom::Job( - shipment.id, vroom::JOB_TYPE::DELIVERY, d_location_index, - shipment.d_service, amount, skills, shipment.priority, d_time_windows); + shipment.id, vroom::JOB_TYPE::DELIVERY, d_location_id, + shipment.d_setup, shipment.d_service, amount, + skills, shipment.priority, d_time_windows); return std::make_pair(pickup, delivery); } @@ -351,22 +353,23 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { vroom::Skills skills = get_vroom_skills(vehicle.skills, vehicle.skills_size); vroom::TimeWindow time_window = - get_vroom_time_window(vehicle.time_window_start, - vehicle.time_window_end); + get_vroom_time_window(vehicle.tw_open, + vehicle.tw_close); std::vector v_breaks = get_vroom_breaks(breaks, breaks_tws); - std::optional start_index; - std::optional end_index; + std::optional start_id; + std::optional end_id; // Set the value of start or end index only if they are present - if (vehicle.start_index != -1) { - start_index = static_cast(m_matrix.get_index(vehicle.start_index)); + if (vehicle.start_id != -1) { + start_id = static_cast(m_matrix.get_index(vehicle.start_id)); } - if (vehicle.end_index != -1) { - end_index = static_cast(m_matrix.get_index(vehicle.end_index)); + if (vehicle.end_id != -1) { + end_id = static_cast(m_matrix.get_index(vehicle.end_id)); } - return vroom::Vehicle(vehicle.id, start_index, end_index, + return vroom::Vehicle(vehicle.id, start_id, end_id, vroom::DEFAULT_PROFILE, capacity, skills, time_window, - v_breaks, "", vehicle.speed_factor); + v_breaks, "", vehicle.speed_factor, + static_cast(vehicle.max_tasks)); } void problem_add_vehicle( @@ -418,8 +421,8 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { ///@} - void add_matrix(vrprouting::base::Base_Matrix time_matrix) { - m_matrix = time_matrix; + void add_matrix(vrprouting::base::Base_Matrix matrix) { + m_matrix = matrix; } void get_amount(vroom::Amount vroom_amount, Amount **amount) { @@ -488,8 +491,12 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { return results; } - std::vector < Vroom_rt > solve() { + std::vector solve(int32_t exploration_level, int32_t timeout, + int32_t loading_time) { std::vector results; + + /* abort in case an interruption occurs (e.g. the query is being cancelled) */ + CHECK_FOR_INTERRUPTS(); try { const unsigned int amount_size = m_vehicles.size() @@ -506,11 +513,22 @@ class Vrp_vroom_problem : public vrprouting::Pgr_messages { for (const auto &shipment : m_shipments) { problem_instance.add_shipment(shipment.first, shipment.second); } - vroom::Matrix matrix = m_matrix.get_vroom_matrix(); - problem_instance.set_matrix(vroom::DEFAULT_PROFILE, std::move(matrix)); - - auto solution = problem_instance.solve(5, 4); - results = get_results(solution); + vroom::Matrix duration_matrix = m_matrix.get_vroom_duration_matrix(); + vroom::Matrix cost_matrix = m_matrix.get_vroom_cost_matrix(); + problem_instance.set_durations_matrix(vroom::DEFAULT_PROFILE, std::move(duration_matrix)); + problem_instance.set_costs_matrix(vroom::DEFAULT_PROFILE, std::move(cost_matrix)); + + unsigned threads = 4; + if (timeout < 0) { + auto solution = problem_instance.solve( + static_cast(exploration_level), threads); + results = get_results(solution); + } else { + int timeout_ms = (loading_time <= timeout * 1000) ? (timeout * 1000 - loading_time) : 0; + auto solution = problem_instance.solve( + static_cast(exploration_level), threads, timeout_ms); + results = get_results(solution); + } } catch (const vroom::Exception &ex) { throw; } catch (const std::exception &ex) { diff --git a/include/drivers/vroom/vroom_driver.h b/include/drivers/vroom/vroom_driver.h index 83a3b8ccd..e91af2c29 100644 --- a/include/drivers/vroom/vroom_driver.h +++ b/include/drivers/vroom/vroom_driver.h @@ -44,7 +44,11 @@ extern "C" { Vroom_vehicle_t *vehicles, size_t total_vehicles, Vroom_break_t *breaks, size_t total_breaks, Vroom_time_window_t *breaks_tws, size_t total_breaks_tws, - Matrix_cell_t *matrix_cells_arr, size_t total_cells, + Vroom_matrix_t *matrix_cells_arr, size_t total_cells, + + int32_t exploration_level, + int32_t timeout, + int32_t loading_time, Vroom_rt **return_tuples, size_t *return_count, diff --git a/pgtap/vroom/edge_cases.sql b/pgtap/vroom/edge_cases.sql index 8a3af4711..b99061269 100644 --- a/pgtap/vroom/edge_cases.sql +++ b/pgtap/vroom/edge_cases.sql @@ -2,7 +2,7 @@ BEGIN; SET search_path TO 'vroom', 'public'; SET client_min_messages TO ERROR; -SELECT CASE WHEN min_version('0.2.0') THEN plan (38) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (54) ELSE plan(1) END; CREATE OR REPLACE FUNCTION edge_cases() RETURNS SETOF TEXT AS @@ -13,9 +13,9 @@ DECLARE rest_sql TEXT; BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; @@ -41,7 +41,7 @@ BEGIN PREPARE empty_breaks_time_windows AS SELECT * FROM breaks_time_windows WHERE id = -1; PREPARE matrix AS SELECT * FROM matrix; - PREPARE empty_matrix AS SELECT * FROM matrix WHERE start_vid = -1; + PREPARE empty_matrix AS SELECT * FROM matrix WHERE start_id = -1; PREPARE vroom_sql AS SELECT * FROM vrp_vroomPlain( @@ -55,6 +55,40 @@ BEGIN 'matrix' ); + RETURN QUERY + SELECT set_eq('vroom_sql', + $$ + VALUES + (1, 1, 1, 1, 1, -1, 300, 0, 0, 0, ARRAY[30]), + (2, 1, 1, 2, 5, 1, 300, 0, 0, 0, ARRAY[30]), + (3, 1, 1, 3, 2, 2, 350, 50, 250, 900, ARRAY[30]), + (4, 1, 1, 4, 3, 5, 1500, 50, 2250, 11850, ARRAY[40]), + (5, 1, 1, 5, 3, 3, 15650, 100, 2250, 0, ARRAY[60]), + (6, 1, 1, 6, 4, 5, 17950, 150, 2250, 225, ARRAY[50]), + (7, 1, 1, 7, 4, 3, 20425, 150, 2250, 200, ARRAY[30]), + (8, 1, 1, 8, 6, -1, 22925, 200, 0, 0, ARRAY[30]), + (9, 2, 2, 1, 1, -1, 275, 0, 0, 0, ARRAY[70]), + (10, 2, 2, 2, 5, 2, 275, 0, 10, 0, ARRAY[70]), + (11, 2, 2, 3, 2, 5, 360, 75, 250, 665, ARRAY[70]), + (12, 2, 2, 4, 2, 3, 1325, 125, 250, 1400, ARRAY[70]), + (13, 2, 2, 5, 2, 4, 2975, 125, 250, 550, ARRAY[70]), + (14, 2, 2, 6, 6, -1, 3775, 125, 0, 0, ARRAY[70]), + (15, 3, 3, 1, 1, -1, 0, 0, 0, 0, ARRAY[20]), + (16, 3, 3, 2, 5, 3, 0, 0, 0, 0, ARRAY[20]), + (17, 3, 3, 3, 2, 1, 0, 0, 250, 3625, ARRAY[20]), + (18, 3, 3, 4, 3, 4, 3875, 0, 2250, 2500, ARRAY[40]), + (19, 3, 3, 5, 4, 4, 8700, 75, 2250, 225, ARRAY[20]), + (20, 3, 3, 6, 6, -1, 11250, 150, 0, 0, ARRAY[20]), + (21, 4, 4, 1, 1, -1, 250, 0, 0, 0, ARRAY[0]), + (22, 4, 4, 2, 5, 4, 250, 0, 0, 0, ARRAY[0]), + (23, 4, 4, 3, 3, 2, 275, 25, 2250, 100, ARRAY[10]), + (24, 4, 4, 4, 3, 1, 2650, 50, 2250, 0, ARRAY[20]), + (25, 4, 4, 5, 4, 2, 4990, 140, 2250, 0, ARRAY[10]), + (26, 4, 4, 6, 4, 1, 7351, 251, 2250, 17574, ARRAY[0]), + (27, 4, 4, 7, 6, -1, 27200, 276, 0, 0, ARRAY[0]) + $$, + 'Query with the vroomdata' + ); -- tests for no jobs/shipments, no vehicles, or no matrix @@ -105,7 +139,7 @@ BEGIN PREPARE jobs_neg_priority AS SELECT * FROM vrp_vroomPlain( - 'SELECT id, location_index, service, delivery, pickup, skills, -1 AS priority FROM jobs', + 'SELECT id, location_id, service, delivery, pickup, skills, -1 AS priority FROM jobs', 'jobs_time_windows', 'shipments', 'shipments_time_windows', @@ -124,7 +158,7 @@ BEGIN PREPARE jobs_101_priority AS SELECT * FROM vrp_vroomPlain( - 'SELECT id, location_index, service, delivery, pickup, skills, 101 AS priority FROM jobs', + 'SELECT id, location_id, service, delivery, pickup, skills, 101 AS priority FROM jobs', 'jobs_time_windows', 'shipments', 'shipments_time_windows', @@ -143,7 +177,7 @@ BEGIN PREPARE jobs_zero_priority AS SELECT * FROM vrp_vroomPlain( - 'SELECT id, location_index, service, delivery, pickup, skills, 0 AS priority FROM jobs', + 'SELECT id, location_id, service, delivery, pickup, skills, 0 AS priority FROM jobs', 'jobs_time_windows', 'shipments', 'shipments_time_windows', @@ -157,7 +191,7 @@ BEGIN PREPARE jobs_100_priority AS SELECT * FROM vrp_vroomPlain( - 'SELECT id, location_index, service, delivery, pickup, skills, 0 AS priority FROM jobs', + 'SELECT id, location_id, service, delivery, pickup, skills, 0 AS priority FROM jobs', 'jobs_time_windows', 'shipments', 'shipments_time_windows', @@ -176,7 +210,7 @@ BEGIN SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', - 'SELECT id, p_location_index, p_service, d_location_index, d_service, + 'SELECT id, p_location_id, p_service, d_location_id, d_service, amount, skills, -1 AS priority FROM shipments', 'shipments_time_windows', 'vehicles', @@ -196,7 +230,7 @@ BEGIN SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', - 'SELECT id, p_location_index, p_service, d_location_index, d_service, + 'SELECT id, p_location_id, p_service, d_location_id, d_service, amount, skills, 101 AS priority FROM shipments', 'shipments_time_windows', 'vehicles', @@ -216,7 +250,7 @@ BEGIN SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', - 'SELECT id, p_location_index, p_service, d_location_index, d_service, + 'SELECT id, p_location_id, p_service, d_location_id, d_service, amount, skills, 0 AS priority FROM shipments', 'shipments_time_windows', 'vehicles', @@ -231,7 +265,7 @@ BEGIN SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', - 'SELECT id, p_location_index, p_service, d_location_index, d_service, + 'SELECT id, p_location_id, p_service, d_location_id, d_service, amount, skills, 100 AS priority FROM shipments', 'shipments_time_windows', 'vehicles', @@ -254,7 +288,7 @@ BEGIN 'vehicles', 'breaks', 'breaks_time_windows', - 'SELECT * FROM matrix WHERE start_vid != 5 AND end_vid != 5' + 'SELECT * FROM matrix WHERE start_id != 5 AND end_id != 5' ); RETURN QUERY SELECT throws_ok( @@ -273,7 +307,7 @@ BEGIN 'vehicles', 'breaks', 'breaks_time_windows', - 'SELECT * FROM matrix WHERE start_vid != end_vid' + 'SELECT * FROM matrix WHERE start_id != end_id' ); RETURN QUERY SELECT set_eq('missing_same_vid_on_matrix', 'vroom_sql', 'Cost between same vertex is always 0'); @@ -287,7 +321,7 @@ BEGIN 'vehicles', 'breaks', 'breaks_time_windows', - 'SELECT * FROM matrix WHERE start_vid < end_vid' + 'SELECT * FROM matrix WHERE start_id < end_id' ); RETURN QUERY SELECT set_eq('missing_reverse_cost_on_matrix', 'vroom_sql', 'Reverse cost is equal to the cost, if not specified'); @@ -413,9 +447,9 @@ BEGIN -- vehicles time windows validate PREPARE vehicles_equal_tw AS - SELECT id, start_index, end_index, capacity, skills, 3000 AS tw_open, 3000 AS tw_close, speed_factor FROM vehicles; + SELECT id, start_id, end_id, capacity, skills, 3000 AS tw_open, 3000 AS tw_close, speed_factor FROM vehicles; PREPARE vehicles_invalid_tw AS - SELECT id, start_index, end_index, capacity, skills, 3001 AS tw_open, 3000 AS tw_close, speed_factor FROM vehicles; + SELECT id, start_id, end_id, capacity, skills, 3001 AS tw_open, 3000 AS tw_close, speed_factor FROM vehicles; PREPARE vehicles_equal_tw_problem AS SELECT * FROM vrp_vroomPlain( @@ -453,8 +487,8 @@ BEGIN -- Query with jobs having only one of delivery or pickup amount should succeed - PREPARE jobs_only_delivery AS SELECT id, location_index, service, delivery, skills, priority FROM jobs; - PREPARE jobs_only_pickup AS SELECT id, location_index, service, pickup, skills, priority FROM jobs; + PREPARE jobs_only_delivery AS SELECT id, location_id, service, delivery, skills, priority FROM jobs; + PREPARE jobs_only_pickup AS SELECT id, location_id, service, pickup, skills, priority FROM jobs; PREPARE jobs_only_delivery_problem AS SELECT * FROM vrp_vroomPlain( 'jobs_only_delivery', @@ -481,37 +515,37 @@ BEGIN RETURN QUERY SELECT lives_ok('jobs_only_pickup_problem', 'Problem with jobs having only pickup amount'); - -- Query with vehicles having only one of start_index or end_index should succeed + -- Query with vehicles having only one of start_id or end_id should succeed - PREPARE vehicles_only_start_index AS SELECT id, start_index, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; - PREPARE vehicles_only_end_index AS SELECT id, end_index, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; - PREPARE vehicles_only_start_index_problem AS + PREPARE vehicles_only_start_id AS SELECT id, start_id, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; + PREPARE vehicles_only_end_id AS SELECT id, end_id, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; + PREPARE vehicles_only_start_id_problem AS SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', 'shipments_time_windows', - 'vehicles_only_start_index', + 'vehicles_only_start_id', 'breaks', 'breaks_time_windows', 'matrix' ); - PREPARE vehicles_only_end_index_problem AS + PREPARE vehicles_only_end_id_problem AS SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', 'shipments_time_windows', - 'vehicles_only_end_index', + 'vehicles_only_end_id', 'breaks', 'breaks_time_windows', 'matrix' ); - RETURN QUERY SELECT lives_ok('vehicles_only_start_index_problem', 'Problem with vehicles having only start_index'); - RETURN QUERY SELECT lives_ok('vehicles_only_end_index_problem', 'Problem with vehicles having only end_index'); + RETURN QUERY SELECT lives_ok('vehicles_only_start_id_problem', 'Problem with vehicles having only start_id'); + RETURN QUERY SELECT lives_ok('vehicles_only_end_id_problem', 'Problem with vehicles having only end_id'); - -- Query with vehicles having neither start_index nor end_index must fail + -- Query with vehicles having neither start_id nor end_id must fail PREPARE vehicles_no_index AS SELECT id, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; PREPARE vehicles_no_index_problem AS @@ -529,21 +563,21 @@ BEGIN SELECT throws_ok( 'vehicles_no_index_problem', 'XX000', - 'At least one out of start_index or end_index must be present', - 'Problem with vehicles having neither start_index nor end_index' + 'At least one out of start_id or end_id must be present', + 'Problem with vehicles having neither start_id nor end_id' ); -- Number of quantities of delivery, pickup, amount and capacity must be the same PREPARE jobs_inconsistent_delivery AS - SELECT id, location_index, service, ARRAY[10, 20]::BIGINT[] AS delivery, pickup, skills, priority FROM jobs; + SELECT id, location_id, service, ARRAY[10, 20]::BIGINT[] AS delivery, pickup, skills, priority FROM jobs; PREPARE jobs_inconsistent_pickup AS - SELECT id, location_index, service, delivery, ARRAY[10, 20]::BIGINT[] AS pickup, skills, priority FROM jobs; + SELECT id, location_id, service, delivery, ARRAY[10, 20]::BIGINT[] AS pickup, skills, priority FROM jobs; PREPARE shipments_inconsistent_amount AS - SELECT id, p_location_index, p_service, d_location_index, d_service, ARRAY[10, 20]::BIGINT[] AS amount, skills, priority FROM shipments; + SELECT id, p_location_id, p_service, d_location_id, d_service, ARRAY[10, 20]::BIGINT[] AS amount, skills, priority FROM shipments; PREPARE vehicles_inconsistent_capacity AS - SELECT id, start_index, end_index, ARRAY[10, 20]::BIGINT[] AS capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; + SELECT id, start_id, end_id, ARRAY[10, 20]::BIGINT[] AS capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; PREPARE jobs_inconsistent_delivery_problem AS SELECT * FROM vrp_vroomPlain( @@ -626,17 +660,17 @@ BEGIN ); - -- If speed_factor and agg_cost are multiplied by same number, result should be same + -- If speed_factor and duration are multiplied by same number, result should be same PREPARE vehicles_2x_speed AS - SELECT id, start_index, end_index, capacity, skills, tw_open, tw_close, 2 * speed_factor AS speed_factor FROM vehicles; + SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, 2 * speed_factor AS speed_factor FROM vehicles; PREPARE matrix_2x_distance AS - SELECT start_vid, end_vid, 2 * agg_cost AS agg_cost FROM matrix; + SELECT start_id, end_id, 2 * duration AS duration FROM matrix; PREPARE vehicles_4x_speed AS - SELECT id, start_index, end_index, capacity, skills, tw_open, tw_close, 4 * speed_factor AS speed_factor FROM vehicles; + SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, 4 * speed_factor AS speed_factor FROM vehicles; PREPARE matrix_4x_distance AS - SELECT start_vid, end_vid, 4 * agg_cost AS agg_cost FROM matrix; + SELECT start_id, end_id, 4 * duration AS duration FROM matrix; PREPARE vehicles_2x_speed_problem AS SELECT * FROM vrp_vroomPlain( @@ -794,6 +828,374 @@ BEGIN 'Problem with one job and one shipment having id 2' ); + PREPARE exploration_level_negative AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix', + exploration_level => -1 + ); + RETURN QUERY + SELECT throws_ok( + 'exploration_level_negative', + 'P0001', + 'Invalid value found on ''exploration_level''', + 'Problem with negative exploration_level' + ); + + PREPARE exploration_level_greater_5 AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix', + exploration_level => 6 + ); + RETURN QUERY + SELECT throws_ok( + 'exploration_level_greater_5', + 'P0001', + 'Invalid value found on ''exploration_level''', + 'Problem with exploration_level => 6' + ); + + PREPARE exploration_level_0 AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix', + exploration_level => 0 + ); + RETURN QUERY + SELECT set_eq('exploration_level_0', + $$ + VALUES + (1, 1, 1, 1, 1, -1, 300, 0, 0, 0, ARRAY[20]), + (2, 1, 1, 2, 5, 1, 300, 0, 0, 0, ARRAY[20]), + (3, 1, 1, 3, 2, 1, 300, 0, 250, 3325, ARRAY[20]), + (4, 1, 1, 4, 3, 4, 3875, 0, 2250, 2500, ARRAY[40]), + (5, 1, 1, 5, 4, 4, 8700, 75, 2250, 225, ARRAY[20]), + (6, 1, 1, 6, 3, 5, 11265, 165, 2250, 2085, ARRAY[30]), + (7, 1, 1, 7, 3, 3, 15650, 215, 2250, 0, ARRAY[50]), + (8, 1, 1, 8, 4, 5, 17950, 265, 2250, 225, ARRAY[40]), + (9, 1, 1, 9, 4, 3, 20425, 265, 2250, 200, ARRAY[20]), + (10, 1, 1, 10, 6, -1, 22925, 315, 0, 0, ARRAY[20]), + (11, 2, 2, 1, 1, -1, 275, 0, 0, 0, ARRAY[50]), + (12, 2, 2, 2, 5, 2, 275, 0, 10, 0, ARRAY[50]), + (13, 2, 2, 3, 2, 2, 335, 50, 250, 915, ARRAY[50]), + (14, 2, 2, 4, 2, 5, 1590, 140, 250, 0, ARRAY[50]), + (15, 2, 2, 5, 3, 1, 1890, 190, 2250, 0, ARRAY[60]), + (16, 2, 2, 6, 4, 1, 4165, 215, 2250, 20760, ARRAY[50]), + (17, 2, 2, 7, 6, -1, 27200, 240, 0, 0, ARRAY[50]), + (18, 3, 4, 1, 1, -1, 250, 0, 0, 0, ARRAY[50]), + (19, 3, 4, 2, 5, 4, 250, 0, 0, 0, ARRAY[50]), + (20, 3, 4, 3, 3, 2, 275, 25, 2250, 100, ARRAY[60]), + (21, 3, 4, 4, 2, 3, 2650, 50, 250, 75, ARRAY[60]), + (22, 3, 4, 5, 2, 4, 2975, 50, 250, 550, ARRAY[60]), + (23, 3, 4, 6, 4, 2, 3865, 140, 2250, 385, ARRAY[50]), + (24, 3, 4, 7, 6, -1, 6590, 230, 0, 0, ARRAY[50]) + $$, + 'Query with the vroomdata and exploration_level => 0' + ); + + PREPARE exploration_level_5 AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix', + exploration_level => 5 + ); + RETURN QUERY + SELECT set_eq('exploration_level_5', 'vroom_sql', 'Problem with exploration_level => 5'); + + + PREPARE timeout_0 AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix', + timeout => 0 + ); + RETURN QUERY + SELECT set_eq('timeout_0', + $$ + VALUES + (1, 1, 1, 1, 1, -1, 300, 0, 0, 0, ARRAY[110]), + (2, 1, 1, 2, 5, 1, 300, 0, 0, 0, ARRAY[110]), + (3, 1, 1, 3, 2, 2, 350, 50, 250, 900, ARRAY[110]), + (4, 1, 1, 4, 2, 5, 1590, 140, 250, 0, ARRAY[110]), + (5, 1, 1, 5, 2, 4, 1890, 190, 250, 1635, ARRAY[110]), + (6, 1, 1, 6, 2, 1, 3865, 280, 250, 0, ARRAY[110]), + (7, 1, 1, 7, 6, -1, 4115, 280, 0, 0, ARRAY[110]), + (8, 2, 4, 1, 1, -1, 250, 0, 0, 0, ARRAY[10]), + (9, 2, 4, 2, 5, 4, 250, 0, 0, 0, ARRAY[10]), + (10, 2, 4, 3, 3, 2, 275, 25, 2250, 100, ARRAY[20]), + (11, 2, 4, 4, 2, 3, 2650, 50, 250, 75, ARRAY[20]), + (12, 2, 4, 5, 3, 1, 2975, 50, 2250, 0, ARRAY[30]), + (13, 2, 4, 6, 4, 2, 5315, 140, 2250, 0, ARRAY[20]), + (14, 2, 4, 7, 3, 4, 7692, 267, 2250, 0, ARRAY[40]), + (15, 2, 4, 8, 4, 4, 10017, 342, 2250, 0, ARRAY[20]), + (16, 2, 4, 9, 3, 5, 12357, 432, 2250, 993, ARRAY[30]), + (17, 2, 4, 10, 3, 3, 15650, 482, 2250, 0, ARRAY[50]), + (18, 2, 4, 11, 4, 5, 17950, 532, 2250, 225, ARRAY[40]), + (19, 2, 4, 12, 4, 3, 20425, 532, 2250, 200, ARRAY[20]), + (20, 2, 4, 13, 4, 1, 23020, 677, 2250, 1905, ARRAY[10]), + (21, 2, 4, 14, 6, -1, 27200, 702, 0, 0, ARRAY[10]) + $$, + 'Query with the vroomdata and timeout => 0' + ); + + PREPARE timeout_negative AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix', + timeout => -1 + ); + RETURN QUERY + SELECT set_eq('exploration_level_5', 'vroom_sql', 'Problem with timeout => -1'); + + PREPARE vehicles_negative_task AS + SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, speed_factor, -1 AS max_tasks FROM vehicles; + + PREPARE vehicles_0_task AS + SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, speed_factor, 0 AS max_tasks FROM vehicles; + + PREPARE vehicles_1_task AS + SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, speed_factor, 1 AS max_tasks FROM vehicles; + + PREPARE problem_negative_tasks AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles_negative_task', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT throws_ok( + 'problem_negative_tasks', + 'XX000', + 'Invalid max_tasks value -1', + 'Problem with max_tasks as -1' + ); + + PREPARE problem_0_tasks AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles_0_task', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT is_empty('problem_0_tasks', 'Problem with max_tasks as 0'); + + PREPARE problem_1_task AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles_1_task', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT set_eq('problem_1_task', + $$ + VALUES + (1, 1, 1, 1, 1, -1, 300, 0, 0, 0, ARRAY[30]), + (2, 1, 1, 2, 5, 1, 300, 0, 0, 0, ARRAY[30]), + (3, 1, 1, 3, 2, 2, 350, 50, 250, 900, ARRAY[30]), + (4, 1, 1, 4, 6, -1, 1550, 100, 0, 0, ARRAY[30]), + (5, 2, 2, 1, 1, -1, 275, 0, 0, 0, ARRAY[10]), + (6, 2, 2, 2, 5, 2, 275, 0, 10, 0, ARRAY[10]), + (7, 2, 2, 3, 2, 3, 375, 90, 250, 2350, ARRAY[10]), + (8, 2, 2, 4, 6, -1, 2975, 90, 0, 0, ARRAY[10]), + (9, 3, 3, 1, 1, -1, 0, 0, 0, 0, ARRAY[20]), + (10, 3, 3, 2, 5, 3, 0, 0, 0, 0, ARRAY[20]), + (11, 3, 3, 3, 2, 1, 0, 0, 250, 3625, ARRAY[20]), + (12, 3, 3, 4, 6, -1, 3875, 0, 0, 0, ARRAY[20]), + (13, 4, 4, 1, 1, -1, 250, 0, 0, 0, ARRAY[40]), + (14, 4, 4, 2, 5, 4, 250, 0, 0, 0, ARRAY[40]), + (15, 4, 4, 3, 2, 4, 250, 0, 250, 3275, ARRAY[40]), + (16, 4, 4, 4, 6, -1, 3775, 0, 0, 0, ARRAY[40]) + $$, + 'Query with max_tasks as 1' + ); + + PREPARE empty_skills_1 AS + SELECT * FROM vrp_vroomPlain( + 'SELECT id, location_id, service, delivery, pickup, ARRAY[]::INTEGER[] AS skills, priority FROM jobs', + 'jobs_time_windows', + 'SELECT id, p_location_id, p_service, d_location_id, d_service, amount, ARRAY[]::INTEGER[] AS skills, priority FROM shipments', + 'shipments_time_windows', + 'SELECT id, start_id, end_id, capacity, ARRAY[]::INTEGER[] AS skills, tw_open, tw_close, speed_factor, max_tasks FROM vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + + RETURN QUERY + SELECT set_eq('empty_skills_1', 'vroom_sql', 'Test for empty skills array - 1'); + + PREPARE empty_skills_2 AS + SELECT * FROM vrp_vroomPlain( + 'SELECT id, location_id, service, delivery, pickup, ARRAY[]::INTEGER[] AS skills, priority FROM jobs', + 'jobs_time_windows', + 'SELECT id, p_location_id, p_service, d_location_id, d_service, amount, ARRAY[]::INTEGER[] AS skills, priority FROM shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + + RETURN QUERY + SELECT set_eq('empty_skills_2', 'vroom_sql', 'Test for empty skills array - 2'); + + PREPARE problem_negative_speed_factor AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, -1 AS speed_factor, max_tasks FROM vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT throws_ok( + 'problem_negative_speed_factor', + 'XX000', + 'Invalid speed_factor -1.000000', + 'Problem with speed_factor as -1' + ); + + PREPARE problem_0_speed_factor AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, 0 AS speed_factor, max_tasks FROM vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT throws_ok( + 'problem_negative_speed_factor', + 'XX000', + 'Invalid speed_factor -1.000000', + 'Problem with speed_factor as 0' + ); + + UPDATE vehicles SET speed_factor = 5.01 WHERE id = 4; + PREPARE problem_more_than_5times_speed_factor AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT throws_ok( + 'problem_more_than_5times_speed_factor', + 'XX000', + 'The speed_factor 5.01 is more than five times the speed factor 1', + 'Problem with one speed factor more than five times the other' + ); + UPDATE vehicles SET speed_factor = 1.0 WHERE id = 4; + + PREPARE problem_speed_factor_5times_scaled AS + SELECT * FROM vrp_vroomPlain( + 'jobs', + 'jobs_time_windows', + 'shipments', + 'shipments_time_windows', + 'SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close, speed_factor * 5 AS speed_factor, max_tasks FROM vehicles', + 'breaks', + 'breaks_time_windows', + 'matrix' + ); + RETURN QUERY + SELECT set_eq('problem_speed_factor_5times_scaled', + $$ + VALUES + (1, 1, 1, 1, 1, -1, 300, 0, 0, 0, ARRAY[30]), + (2, 1, 1, 2, 5, 1, 300, 0, 0, 0, ARRAY[30]), + (3, 1, 1, 3, 2, 2, 310, 10, 250, 940, ARRAY[30]), + (4, 1, 1, 4, 3, 5, 1500, 10, 2250, 11850, ARRAY[40]), + (5, 1, 1, 5, 3, 3, 15610, 20, 2250, 0, ARRAY[60]), + (6, 1, 1, 6, 4, 5, 17870, 30, 2250, 305, ARRAY[50]), + (7, 1, 1, 7, 4, 3, 20425, 30, 2250, 200, ARRAY[30]), + (8, 1, 1, 8, 6, -1, 22885, 40, 0, 0, ARRAY[30]), + (9, 2, 2, 1, 1, -1, 275, 0, 0, 0, ARRAY[70]), + (10, 2, 2, 2, 5, 2, 275, 0, 10, 0, ARRAY[70]), + (11, 2, 2, 3, 2, 5, 300, 15, 250, 725, ARRAY[70]), + (12, 2, 2, 4, 2, 3, 1285, 25, 250, 1440, ARRAY[70]), + (13, 2, 2, 5, 2, 4, 2975, 25, 250, 550, ARRAY[70]), + (14, 2, 2, 6, 6, -1, 3775, 25, 0, 0, ARRAY[70]), + (15, 3, 3, 1, 1, -1, 0, 0, 0, 0, ARRAY[20]), + (16, 3, 3, 2, 5, 3, 0, 0, 0, 0, ARRAY[20]), + (17, 3, 3, 3, 2, 1, 0, 0, 250, 3625, ARRAY[20]), + (18, 3, 3, 4, 3, 4, 3875, 0, 2250, 2500, ARRAY[40]), + (19, 3, 3, 5, 4, 4, 8640, 15, 2250, 285, ARRAY[20]), + (20, 3, 3, 6, 6, -1, 11190, 30, 0, 0, ARRAY[20]), + (21, 4, 4, 1, 1, -1, 250, 0, 0, 0, ARRAY[0]), + (22, 4, 4, 2, 5, 4, 250, 0, 0, 0, ARRAY[0]), + (23, 4, 4, 3, 3, 2, 255, 5, 2250, 120, ARRAY[10]), + (24, 4, 4, 4, 3, 1, 2630, 10, 2250, 0, ARRAY[20]), + (25, 4, 4, 5, 4, 2, 4898, 28, 2250, 0, ARRAY[10]), + (26, 4, 4, 6, 4, 1, 7170, 50, 2250, 17755, ARRAY[0]), + (27, 4, 4, 7, 6, -1, 27180, 55, 0, 0, ARRAY[0]) + $$, + 'Query with speed factor scaled five times' + ); + END; $BODY$ LANGUAGE plpgsql; diff --git a/pgtap/vroom/inner_query.sql b/pgtap/vroom/inner_query.sql index d0a33a2de..9edce9829 100644 --- a/pgtap/vroom/inner_query.sql +++ b/pgtap/vroom/inner_query.sql @@ -1,18 +1,18 @@ BEGIN; SET search_path TO 'vroom', 'public'; -SELECT CASE WHEN min_version('0.2.0') THEN plan (1099) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (3504) ELSE plan(1) END; /* SELECT * FROM vrp_vroomPlain( - $$SELECT id, location_index, service, delivery, pickup, skills, priority FROM jobs$$, + $$SELECT id, location_id, service, delivery, pickup, skills, priority FROM jobs$$, $$SELECT id, tw_open, tw_close FROM jobs_time_windows$$, - $$SELECT id, p_location_index, p_service, d_location_index, d_service, amount, skills, priority FROM shipments$$, + $$SELECT id, p_location_id, p_service, d_location_id, d_service, amount, skills, priority FROM shipments$$, $$SELECT id, kind, tw_open, tw_close FROM shipments_time_windows$$, - $$SELECT id, start_index, end_index, capacity, skills, tw_open, tw_close FROM vehicles$$, + $$SELECT id, start_id, end_id, capacity, skills, tw_open, tw_close FROM vehicles$$, $$SELECT id, vehicle_id, service FROM breaks$$, $$SELECT id, tw_open, tw_close FROM breaks_time_windows$$, - $$SELECT start_vid, end_vid, agg_cost FROM matrix$$ + $$SELECT start_id, end_id, duration FROM matrix$$ ); */ @@ -151,10 +151,10 @@ RETURNS SETOF TEXT AS $BODY$ DECLARE inner_query_table TEXT := 'jobs'; - params TEXT[] := ARRAY['id', 'location_index', 'service', 'delivery', 'pickup', 'skills', 'priority']; + params TEXT[] := ARRAY['id', 'location_id', 'service', 'delivery', 'pickup', 'skills', 'priority']; BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'location_index'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'location_id'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'delivery'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'pickup'); RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); @@ -174,11 +174,11 @@ RETURNS SETOF TEXT AS $BODY$ DECLARE inner_query_table TEXT := 'shipments'; - params TEXT[] := ARRAY['id', 'p_location_index', 'p_service', 'd_location_index', 'd_service', 'amount', 'skills', 'priority']; + params TEXT[] := ARRAY['id', 'p_location_id', 'p_service', 'd_location_id', 'd_service', 'amount', 'skills', 'priority']; BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'p_location_index'); - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'd_location_index'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'p_location_id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'd_location_id'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'amount'); RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'priority'); @@ -199,11 +199,11 @@ RETURNS SETOF TEXT AS $BODY$ DECLARE inner_query_table TEXT := 'vehicles'; - params TEXT[] := ARRAY['id', 'start_index', 'end_index', 'capacity', 'skills', 'tw_open', 'tw_close', 'speed_factor']; + params TEXT[] := ARRAY['id', 'start_id', 'end_id', 'capacity', 'skills', 'tw_open', 'tw_close', 'speed_factor', 'max_tasks']; BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'start_index'); - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_index'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'start_id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_id'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'capacity'); RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); RETURN QUERY SELECT test_anyNumerical(fn, inner_query_table, start_sql, rest_sql, params, 'speed_factor'); @@ -214,6 +214,7 @@ BEGIN RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); END IF; + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'max_tasks'); END; $BODY$ LANGUAGE plpgsql; @@ -224,11 +225,16 @@ RETURNS SETOF TEXT AS $BODY$ DECLARE inner_query_table TEXT := 'matrix'; - params TEXT[] := ARRAY['start_vid', 'end_vid', 'agg_cost']; + params TEXT[] := ARRAY['start_id', 'end_id', 'duration', 'cost']; BEGIN - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'start_vid'); - RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_vid'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'agg_cost'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'start_id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_id'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'duration'); + ELSE + RETURN QUERY SELECT test_Interval(fn, inner_query_table, start_sql, rest_sql, params, 'duration'); + END IF; + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'cost'); END; $BODY$ LANGUAGE plpgsql; @@ -292,7 +298,7 @@ $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query(is_plain BOOLEAN) +CREATE OR REPLACE FUNCTION inner_query(is_plain BOOLEAN, additional TEXT) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -302,9 +308,9 @@ DECLARE inner_query_table TEXT; BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; @@ -318,50 +324,50 @@ BEGIN start_sql := ''; rest_sql := ', $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_jobs(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, '; rest_sql := ', $$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; inner_query_table := 'jobs_time_windows'; RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, '; rest_sql := ', $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_shipments(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, '; rest_sql := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; inner_query_table := 'shipments_time_windows'; RETURN QUERY SELECT inner_query_shipments_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, '; rest_sql := ', $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, '; - rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, ' || '$$SELECT * FROM breaks$$, '; - rest_sql := ', $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM matrix$$' || additional; inner_query_table := 'breaks_time_windows'; RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, ' || '$$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, '; - rest_sql := ')'; + rest_sql := additional; RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql, is_plain); @@ -374,34 +380,34 @@ BEGIN END IF; start_sql := ''; rest_sql := ', $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_jobs(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, '; rest_sql := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; inner_query_table := 'jobs_time_windows'; RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, '; rest_sql := ', $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, ' || '$$SELECT * FROM vehicles$$, '; - rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, '; - rest_sql := ', $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM matrix$$' || additional; inner_query_table := 'breaks_time_windows'; RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, '; - rest_sql := ')'; + rest_sql := additional; RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql, is_plain); @@ -414,33 +420,33 @@ BEGIN END IF; start_sql := ''; rest_sql := ', $$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_shipments(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, '; rest_sql := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || - '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; inner_query_table := 'shipments_time_windows'; RETURN QUERY SELECT inner_query_shipments_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, '; - rest_sql := ', $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, '; - rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$' || additional; RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, '; - rest_sql := ', $$SELECT * FROM matrix$$)'; + rest_sql := ', $$SELECT * FROM matrix$$' || additional; inner_query_table := 'breaks_time_windows'; RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, '; - rest_sql := ')'; + rest_sql := additional; RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql, is_plain); END; @@ -448,7 +454,9 @@ $BODY$ LANGUAGE plpgsql; -SELECT inner_query(is_plain => TRUE); +SELECT inner_query(is_plain => TRUE, additional => ', exploration_level => 5)'); +SELECT inner_query(is_plain => TRUE, additional => ', timeout => -1)'); +SELECT inner_query(is_plain => TRUE, additional => ', exploration_level => 5, timeout => -1)'); -- Adjust the column types to the expected types for vroom functions with timestamps/interval ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); @@ -463,8 +471,12 @@ ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USI ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); + +SELECT inner_query(is_plain => FALSE, additional => ', exploration_level => 5)'); +SELECT inner_query(is_plain => FALSE, additional => ', timeout => $$-00:00:01$$::INTERVAL)'); +SELECT inner_query(is_plain => FALSE, additional => ', exploration_level => 5, timeout => $$-00:00:01$$::INTERVAL)'); -SELECT inner_query(is_plain => FALSE); SELECT * FROM finish(); ROLLBACK; diff --git a/pgtap/vroom/no_crash_test.sql b/pgtap/vroom/no_crash_test.sql index c8db335e2..e8799f3a8 100644 --- a/pgtap/vroom/no_crash_test.sql +++ b/pgtap/vroom/no_crash_test.sql @@ -2,7 +2,7 @@ BEGIN; SET search_path TO 'vroom', 'public'; SET client_min_messages TO ERROR; -SELECT CASE WHEN min_version('0.2.0') THEN plan (92) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (116) ELSE plan(1) END; CREATE OR REPLACE FUNCTION no_crash(is_plain BOOLEAN) RETURNS SETOF TEXT AS @@ -13,9 +13,9 @@ DECLARE error_messages TEXT[]; non_empty_args INTEGER[]; BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; @@ -53,7 +53,9 @@ BEGIN '$$vehicles$$', '$$breaks$$', '$$breaks_time_windows$$', - '$$matrix$$' + '$$matrix$$', + 'exploration_level => 5', + 'timeout => -1' ]::TEXT[]; subs = ARRAY[ 'NULL', @@ -63,7 +65,9 @@ BEGIN 'NULL', 'NULL', 'NULL', - 'NULL' + 'NULL', + 'exploration_level => NULL', + 'timeout => NULL' ]::TEXT[]; error_messages = ARRAY[ '', @@ -73,13 +77,17 @@ BEGIN 'Vehicles SQL must not be NULL', '', '', - 'Matrix SQL must not be NULL' + 'Matrix SQL must not be NULL', + '', + '' ]::TEXT[]; - non_empty_args = ARRAY[0, 1, 2, 3, 4, 6, 7]::INTEGER[]; + non_empty_args = ARRAY[0, 1, 2, 3, 4, 6, 7, 9, 10]::INTEGER[]; IF is_plain = TRUE THEN + params[10] = 'timeout => -1'; RETURN query SELECT * FROM no_crash_test('vrp_vroomPlain', params, subs, error_messages, non_empty_args); ELSE + params[10] = 'timeout => $$-00:00:01$$::INTERVAL'; RETURN query SELECT * FROM no_crash_test('vrp_vroom', params, subs, error_messages, non_empty_args); END IF; @@ -89,7 +97,9 @@ BEGIN '$$vehicles$$', '$$breaks$$', '$$breaks_time_windows$$', - '$$matrix$$' + '$$matrix$$', + 'exploration_level => 5', + 'timeout => -1' ]::TEXT[]; subs = ARRAY[ 'NULL', @@ -97,7 +107,9 @@ BEGIN 'NULL', 'NULL', 'NULL', - 'NULL' + 'NULL', + 'exploration_level => NULL', + 'timeout => NULL' ]::TEXT[]; error_messages = ARRAY[ 'Jobs SQL must not be NULL', @@ -105,13 +117,17 @@ BEGIN 'Vehicles SQL must not be NULL', '', '', - 'Matrix SQL must not be NULL' + 'Matrix SQL must not be NULL', + '', + '' ]::TEXT[]; - non_empty_args = ARRAY[0, 2, 4, 5]::INTEGER[]; + non_empty_args = ARRAY[0, 2, 4, 5, 7, 8]::INTEGER[]; IF is_plain = TRUE THEN + params[8] = 'timeout => -1'; RETURN query SELECT * FROM no_crash_test('vrp_vroomJobsPlain', params, subs, error_messages, non_empty_args); ELSE + params[8] = 'timeout => $$-00:00:01$$::INTERVAL'; RETURN query SELECT * FROM no_crash_test('vrp_vroomJobs', params, subs, error_messages, non_empty_args); END IF; @@ -121,7 +137,9 @@ BEGIN '$$vehicles$$', '$$breaks$$', '$$breaks_time_windows$$', - '$$matrix$$' + '$$matrix$$', + 'exploration_level => 5', + 'timeout => -1' ]::TEXT[]; subs = ARRAY[ 'NULL', @@ -129,7 +147,9 @@ BEGIN 'NULL', 'NULL', 'NULL', - 'NULL' + 'NULL', + 'exploration_level => NULL', + 'timeout => NULL' ]::TEXT[]; error_messages = ARRAY[ 'Shipments SQL must not be NULL', @@ -137,13 +157,17 @@ BEGIN 'Vehicles SQL must not be NULL', '', '', - 'Matrix SQL must not be NULL' + 'Matrix SQL must not be NULL', + '', + '' ]::TEXT[]; - non_empty_args = ARRAY[0, 2, 4, 5]::INTEGER[]; + non_empty_args = ARRAY[0, 2, 4, 5, 7, 8]::INTEGER[]; IF is_plain = TRUE THEN + params[8] = 'timeout => -1'; RETURN query SELECT * FROM no_crash_test('vrp_vroomShipmentsPlain', params, subs, error_messages, non_empty_args); ELSE + params[8] = 'timeout => $$-00:00:01$$::INTERVAL'; RETURN query SELECT * FROM no_crash_test('vrp_vroomShipments', params, subs, error_messages, non_empty_args); END IF; @@ -169,6 +193,7 @@ ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USI ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); SELECT * FROM no_crash(is_plain => FALSE); diff --git a/pgtap/vroom/types_check.sql b/pgtap/vroom/types_check.sql index ee296c513..ea851f8bc 100644 --- a/pgtap/vroom/types_check.sql +++ b/pgtap/vroom/types_check.sql @@ -1,16 +1,16 @@ BEGIN; SET search_path TO 'vroom', 'public'; -SELECT CASE WHEN min_version('0.2.0') THEN plan (30) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (30) ELSE plan(1) END; CREATE OR REPLACE FUNCTION types_check() RETURNS SETOF TEXT AS $BODY$ BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; @@ -18,15 +18,15 @@ BEGIN RETURN QUERY SELECT has_function('vrp_vroomplain'); RETURN QUERY - SELECT has_function('vrp_vroomplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text']); + SELECT has_function('vrp_vroomplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'integer']); RETURN QUERY - SELECT function_returns('vrp_vroomplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + SELECT function_returns('vrp_vroomplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'integer'], 'setof record'); -- parameter names RETURN QUERY SELECT bag_has( $$SELECT proargnames from pg_proc where proname = 'vrp_vroomplain'$$, - $$SELECT '{"","","","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + $$SELECT '{"","","","","","","","","exploration_level","timeout","seq","vehicle_seq","vehicle_id","step_seq","step_type",' '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ ); @@ -35,7 +35,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomplain'$$, $$VALUES - ('{25,25,25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + ('{25,25,25,25,25,25,25,25,23,23,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) $$ ); @@ -44,15 +44,15 @@ BEGIN RETURN QUERY SELECT has_function('vrp_vroom'); RETURN QUERY - SELECT has_function('vrp_vroom', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text']); + SELECT has_function('vrp_vroom', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'interval']); RETURN QUERY - SELECT function_returns('vrp_vroom', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + SELECT function_returns('vrp_vroom', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'interval'], 'setof record'); -- parameter names RETURN QUERY SELECT bag_has( $$SELECT proargnames from pg_proc where proname = 'vrp_vroom'$$, - $$SELECT '{"","","","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + $$SELECT '{"","","","","","","","","exploration_level","timeout","seq","vehicle_seq","vehicle_id","step_seq","step_type",' '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ ); @@ -61,7 +61,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroom'$$, $$VALUES - ('{25,25,25,25,25,25,25,25,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) + ('{25,25,25,25,25,25,25,25,23,1186,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) $$ ); @@ -70,15 +70,15 @@ BEGIN RETURN QUERY SELECT has_function('vrp_vroomjobsplain'); RETURN QUERY - SELECT has_function('vrp_vroomjobsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text']); + SELECT has_function('vrp_vroomjobsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'integer']); RETURN QUERY - SELECT function_returns('vrp_vroomjobsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + SELECT function_returns('vrp_vroomjobsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'integer'], 'setof record'); -- parameter names RETURN QUERY SELECT bag_has( $$SELECT proargnames from pg_proc where proname = 'vrp_vroomjobsplain'$$, - $$SELECT '{"","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + $$SELECT '{"","","","","","","exploration_level","timeout","seq","vehicle_seq","vehicle_id","step_seq","step_type",' '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ ); @@ -87,7 +87,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomjobsplain'$$, $$VALUES - ('{25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + ('{25,25,25,25,25,25,23,23,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) $$ ); @@ -96,15 +96,15 @@ BEGIN RETURN QUERY SELECT has_function('vrp_vroomjobs'); RETURN QUERY - SELECT has_function('vrp_vroomjobs', ARRAY['text', 'text', 'text', 'text', 'text', 'text']); + SELECT has_function('vrp_vroomjobs', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'interval']); RETURN QUERY - SELECT function_returns('vrp_vroomjobs', ARRAY['text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + SELECT function_returns('vrp_vroomjobs', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'interval'], 'setof record'); -- parameter names RETURN QUERY SELECT bag_has( $$SELECT proargnames from pg_proc where proname = 'vrp_vroomjobs'$$, - $$SELECT '{"","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + $$SELECT '{"","","","","","","exploration_level","timeout","seq","vehicle_seq","vehicle_id","step_seq","step_type",' '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ ); @@ -113,7 +113,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomjobs'$$, $$VALUES - ('{25,25,25,25,25,25,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) + ('{25,25,25,25,25,25,23,1186,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) $$ ); @@ -122,15 +122,15 @@ BEGIN RETURN QUERY SELECT has_function('vrp_vroomshipmentsplain'); RETURN QUERY - SELECT has_function('vrp_vroomshipmentsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text']); + SELECT has_function('vrp_vroomshipmentsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'integer']); RETURN QUERY - SELECT function_returns('vrp_vroomshipmentsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + SELECT function_returns('vrp_vroomshipmentsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'integer'], 'setof record'); -- parameter names RETURN QUERY SELECT bag_has( $$SELECT proargnames from pg_proc where proname = 'vrp_vroomshipmentsplain'$$, - $$SELECT '{"","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + $$SELECT '{"","","","","","","exploration_level","timeout","seq","vehicle_seq","vehicle_id","step_seq","step_type",' '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ ); @@ -139,7 +139,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomshipmentsplain'$$, $$VALUES - ('{25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + ('{25,25,25,25,25,25,23,23,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) $$ ); @@ -148,15 +148,15 @@ BEGIN RETURN QUERY SELECT has_function('vrp_vroomshipments'); RETURN QUERY - SELECT has_function('vrp_vroomshipments', ARRAY['text', 'text', 'text', 'text', 'text', 'text']); + SELECT has_function('vrp_vroomshipments', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'interval']); RETURN QUERY - SELECT function_returns('vrp_vroomshipments', ARRAY['text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + SELECT function_returns('vrp_vroomshipments', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'integer', 'interval'], 'setof record'); -- parameter names RETURN QUERY SELECT bag_has( $$SELECT proargnames from pg_proc where proname = 'vrp_vroomshipments'$$, - $$SELECT '{"","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + $$SELECT '{"","","","","","","exploration_level","timeout","seq","vehicle_seq","vehicle_id","step_seq","step_type",' '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ ); @@ -165,7 +165,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomshipments'$$, $$VALUES - ('{25,25,25,25,25,25,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) + ('{25,25,25,25,25,25,23,1186,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) $$ ); END; diff --git a/pgtap/vroom/vroom-plain-eq-timestamp.test.sql b/pgtap/vroom/vroom-plain-eq-timestamp.test.sql index 6c9cdcc01..02afcc1a5 100644 --- a/pgtap/vroom/vroom-plain-eq-timestamp.test.sql +++ b/pgtap/vroom/vroom-plain-eq-timestamp.test.sql @@ -2,7 +2,7 @@ BEGIN; SET search_path TO 'vroom', 'public'; SET client_min_messages TO ERROR; -SELECT CASE WHEN min_version('0.2.0') THEN plan (22) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (22) ELSE plan(1) END; CREATE or REPLACE FUNCTION vroom_plain_eq_timestamp() RETURNS SETOF TEXT AS @@ -12,13 +12,13 @@ DECLARE jobsPlain TEXT := '$$SELECT * FROM jobs'; jobsPlain_sql TEXT; - jobs TEXT := '$$SELECT id, location_index, make_interval(secs => service) AS service, delivery, pickup, skills, priority FROM jobs'; + jobs TEXT := '$$SELECT id, location_id, make_interval(secs => service) AS service, delivery, pickup, skills, priority FROM jobs'; jobs_sql TEXT; shipmentsPlain TEXT := '$$SELECT * FROM shipments'; shipmentsPlain_sql TEXT; - shipments TEXT := '$$SELECT id, p_location_index, make_interval(secs => p_service) AS p_service, ' || - 'd_location_index, make_interval(secs => d_service) AS d_service, amount, skills, priority FROM shipments'; + shipments TEXT := '$$SELECT id, p_location_id, make_interval(secs => p_service) AS p_service, ' || + 'd_location_id, make_interval(secs => d_service) AS d_service, amount, skills, priority FROM shipments'; shipments_sql TEXT; jobsPlain_time_windows TEXT := '$$SELECT * FROM jobs_time_windows$$'; @@ -30,14 +30,15 @@ DECLARE '(to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close FROM shipments_time_windows$$'; restPlain_sql TEXT := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$' || - ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$, exploration_level => 5, timeout => -1)'; - rest_sql TEXT := ', $$SELECT id, start_index, end_index, capacity, skills, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open' || - ', (to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close, speed_factor FROM vehicles$$' || + rest_sql TEXT := ', $$SELECT id, start_id, end_id, capacity, skills, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open' || + ', (to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close, speed_factor, max_tasks FROM vehicles$$' || ', $$SELECT id, vehicle_id, make_interval(secs => service) AS service FROM breaks$$' || ', $$SELECT id, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open' || ', (to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close FROM breaks_time_windows$$, ' || - '$$SELECT * FROM matrix$$)'; + '$$SELECT start_id, end_id, make_interval(secs => duration) AS duration, cost FROM matrix$$, ' || + 'exploration_level => 5, timeout => $$-00:00:01$$::INTERVAL)'; returnPlain_sql TEXT := 'SELECT * FROM vrp_vroomPlain('; return_sql TEXT := 'SELECT seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, ' || @@ -50,9 +51,9 @@ DECLARE id_filter TEXT; data TEXT; BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; @@ -66,6 +67,8 @@ BEGIN jobsPlain_sql := jobsPlain || id_filter || jobsPlain_time_windows; shipmentsPlain_sql := shipmentsPlain || id_filter || shipmentsPlain_time_windows; vroomPlain_sql := returnPlain_sql || jobsPlain_sql || ', ' || shipmentsPlain_sql || restPlain_sql; + RAISE WARNING '%', vroom_sql; + RAISE WARNING '%', vroomPlain_sql; RETURN query SELECT set_eq(vroom_sql, vroomPlain_sql); END LOOP; END LOOP; diff --git a/pgtap/vroom/vroomJobs-eq-vroom.test.sql b/pgtap/vroom/vroomJobs-eq-vroom.test.sql index 0e77c3e1a..c13315aee 100644 --- a/pgtap/vroom/vroomJobs-eq-vroom.test.sql +++ b/pgtap/vroom/vroomJobs-eq-vroom.test.sql @@ -2,7 +2,7 @@ BEGIN; SET search_path TO 'vroom', 'public'; SET client_min_messages TO ERROR; -SELECT CASE WHEN min_version('0.2.0') THEN plan (22) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (22) ELSE plan(1) END; CREATE or REPLACE FUNCTION vroomJobs_eq_vroom() RETURNS SETOF TEXT AS @@ -13,14 +13,14 @@ DECLARE empty_time_windows TEXT := '$$SELECT * FROM jobs_time_windows WHERE id = -1$$'; shipments_sql TEXT := ', $$SELECT * FROM shipments WHERE id = -1$$, $$SELECT * FROM shipments_time_windows WHERE id = -1$$'; rest_sql TEXT := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$' || - ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$, exploration_level => 5, timeout => -1)'; vroom_sql TEXT; vroomJobs_sql TEXT; data TEXT; BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; diff --git a/pgtap/vroom/vroomShipments-eq-vroom.test.sql b/pgtap/vroom/vroomShipments-eq-vroom.test.sql index f801f69e9..26cdd3650 100644 --- a/pgtap/vroom/vroomShipments-eq-vroom.test.sql +++ b/pgtap/vroom/vroomShipments-eq-vroom.test.sql @@ -2,7 +2,7 @@ BEGIN; SET search_path TO 'vroom', 'public'; SET client_min_messages TO ERROR; -SELECT CASE WHEN min_version('0.2.0') THEN plan (22) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.3.0') THEN plan (22) ELSE plan(1) END; CREATE or REPLACE FUNCTION vroomShipments_eq_vroom() RETURNS SETOF TEXT AS @@ -13,14 +13,14 @@ DECLARE shipments_sql TEXT; empty_time_windows TEXT := '$$SELECT * FROM shipments_time_windows WHERE id = -1$$'; rest_sql TEXT := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$' || - ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$, exploration_level => 5, timeout => -1)'; vroom_sql TEXT; vroomShipments_sql TEXT; data TEXT; BEGIN - IF NOT min_version('0.2.0') THEN + IF NOT min_version('0.3.0') THEN RETURN QUERY - SELECT skip(1, 'Function is new on 0.2.0'); + SELECT skip(1, 'Function is modified on 0.3.0'); RETURN; END IF; diff --git a/sql/sigs/vrprouting--0.3.sig b/sql/sigs/vrprouting--0.3.sig index 18a1cca00..c289dae9c 100644 --- a/sql/sigs/vrprouting--0.3.sig +++ b/sql/sigs/vrprouting--0.3.sig @@ -32,10 +32,10 @@ _vrp_vehiclesattime(text,timestamp without time zone,boolean) vrp_version() vrp_viewrouteraw(text,text,text,text,bigint,double precision) vrp_viewroute(text,text,text,text,bigint,double precision) -vrp_vroomjobsplain(text,text,text,text,text,text) -vrp_vroomjobs(text,text,text,text,text,text) -vrp_vroomplain(text,text,text,text,text,text,text,text) -vrp_vroomshipmentsplain(text,text,text,text,text,text) -vrp_vroomshipments(text,text,text,text,text,text) -vrp_vroom(text,text,text,text,text,text,text,text) -_vrp_vroom(text,text,text,text,text,text,text,text,smallint,boolean) +vrp_vroomjobsplain(text,text,text,text,text,text,integer,integer) +vrp_vroomjobs(text,text,text,text,text,text,integer,interval) +vrp_vroomplain(text,text,text,text,text,text,text,text,integer,integer) +vrp_vroomshipmentsplain(text,text,text,text,text,text,integer,integer) +vrp_vroomshipments(text,text,text,text,text,text,integer,interval) +_vrp_vroom(text,text,text,text,text,text,text,text,integer,integer,smallint,boolean) +vrp_vroom(text,text,text,text,text,text,text,text,integer,interval) diff --git a/sql/vroom/_vrp_vroom.sql b/sql/vroom/_vrp_vroom.sql index 6d3fa62b5..27e9949c0 100644 --- a/sql/vroom/_vrp_vroom.sql +++ b/sql/vroom/_vrp_vroom.sql @@ -36,6 +36,10 @@ CREATE FUNCTION _vrp_vroom( breaks_sql TEXT, breaks_time_windows_sql TEXT, matrix_sql TEXT, + + exploration_level INTEGER, + timeout INTEGER, + fn SMALLINT, is_plain BOOLEAN, @@ -56,5 +60,5 @@ LANGUAGE C VOLATILE; -- COMMENTS -COMMENT ON FUNCTION _vrp_vroom(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, SMALLINT, BOOLEAN) +COMMENT ON FUNCTION _vrp_vroom(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, SMALLINT, BOOLEAN) IS 'pgRouting internal function'; diff --git a/sql/vroom/vrp_vroom.sql b/sql/vroom/vrp_vroom.sql index bcd6597b6..78069541e 100644 --- a/sql/vroom/vrp_vroom.sql +++ b/sql/vroom/vrp_vroom.sql @@ -35,7 +35,7 @@ signature start Jobs SQL, Jobs Time Windows SQL, Shipments SQL, Shipments Time Windows SQL, Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, - Matrix SQL) -- Experimental on v0.2 + Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2 RETURNS SET OF (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, @@ -43,6 +43,22 @@ signature start signature end +default signature start + +.. code-block:: none + + vrp_vroom( + Jobs SQL, Jobs Time Windows SQL, + Shipments SQL, Shipments Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL) + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +default signature end + parameters start ============================== =========== ========================================================= @@ -66,6 +82,26 @@ Parameter Type Description parameters end +optional parameters start + +===================== ============ ============================= ================================================= +Parameter Type Default Description +===================== ============ ============================= ================================================= +**exploration_level** ``INTEGER`` :math:`5` Exploration level to use while solving. + + - Ranges from ``[0, 5]`` + - A smaller exploration level gives faster result. + +**timeout** ``INTERVAL`` '-00:00:01'::INTERVAL Timeout value to stop the solving process. + + - Gives the best possible solution within a time + limit. Note that some additional seconds may be + required to return back the data. + - Any negative timeout value is ignored. +===================== ============ ============================= ================================================= + +optional parameters end + result start Returns set of @@ -102,21 +138,13 @@ Column Type Description - ``-1``: If the step is starting/ending location. -**arrival** ``TIMESTAMP`` Estimated time of arrival at this step, in seconds. +**arrival** |timestamp| Estimated time of arrival at this step. - - ``INTEGER`` for plain VROOM functions. +**travel_time** |interval| Cumulated travel time upon arrival at this step. -**travel_time** ``INTERVAL`` Cumulated travel time upon arrival at this step, in seconds +**service_time** |interval| Service time at this step. - - ``INTEGER`` for plain VROOM functions. - -**service_time** ``INTERVAL`` Service time at this step, in seconds - - - ``INTEGER`` for plain VROOM functions. - -**waiting_time** ``INTERVAL`` Waiting time upon arrival at this step, in seconds. - - - ``INTEGER`` for plain VROOM functions. +**waiting_time** |interval| Waiting time upon arrival at this step. **load** ``BIGINT`` Vehicle load after step completion (with capacity constraints) =================== ================= ================================================= @@ -135,6 +163,9 @@ CREATE FUNCTION vrp_vroom( TEXT, -- breaks_time_windows_sql (required) TEXT, -- matrix_sql (required) + exploration_level INTEGER DEFAULT 5, + timeout INTERVAL DEFAULT '-00:00:01'::INTERVAL, + OUT seq BIGINT, OUT vehicle_seq BIGINT, OUT vehicle_id BIGINT, @@ -148,42 +179,51 @@ CREATE FUNCTION vrp_vroom( OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ +BEGIN + IF exploration_level < 0 OR exploration_level > 5 THEN + RAISE EXCEPTION 'Invalid value found on ''exploration_level''' + USING HINT = format('Value found: %s. It must lie in the range 0 to 5 (inclusive)', exploration_level); + END IF; + + RETURN QUERY SELECT - seq, - vehicle_seq, - vehicle_id, - step_seq, - step_type, - task_id, - (to_timestamp(arrival) at time zone 'UTC')::TIMESTAMP, - make_interval(secs => travel_time), - make_interval(secs => service_time), - make_interval(secs => waiting_time), - load + A.seq, + A.vehicle_seq, + A.vehicle_id, + A.step_seq, + A.step_type, + A.task_id, + (to_timestamp(A.arrival) at time zone 'UTC')::TIMESTAMP, + make_interval(secs => A.travel_time), + make_interval(secs => A.service_time), + make_interval(secs => A.waiting_time), + A.load FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), _pgr_get_statement($4), _pgr_get_statement($5), _pgr_get_statement($6), - _pgr_get_statement($7), _pgr_get_statement($8), 0::SMALLINT, false); + _pgr_get_statement($7), _pgr_get_statement($8), exploration_level, + EXTRACT(epoch FROM timeout)::INTEGER, 0::SMALLINT, false) A; +END; $BODY$ -LANGUAGE SQL VOLATILE; +LANGUAGE plpgsql VOLATILE; -- COMMENTS -COMMENT ON FUNCTION vrp_vroom(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +COMMENT ON FUNCTION vrp_vroom(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTERVAL) IS 'vrp_vroom - EXPERIMENTAL - Parameters: - Jobs SQL with columns: - id, location_index [, service, delivery, pickup, skills, priority, time_windows] + id, location_id [, service, delivery, pickup, skills, priority, time_windows] - Jobs Time Windows SQL with columns: id, tw_open, tw_close - Shipments SQL with columns: - p_id, p_location_index [, p_service, p_time_windows], - d_id, d_location_index [, d_service, d_time_windows] [, amount, skills, priority] + p_id, p_location_id [, p_service, p_time_windows], + d_id, d_location_id [, d_service, d_time_windows] [, amount, skills, priority] - Shipments Time Windows SQL with columns: id, kind, tw_open, tw_close - Vehicles SQL with columns: - id, start_index, end_index + id, start_id, end_id [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] - Breaks SQL with columns: id [, service] @@ -191,6 +231,9 @@ IS 'vrp_vroom id, tw_open, tw_close - Matrix SQL with columns: start_vid, end_vid, agg_cost +- Optional parameters + - exploration_level := 5 + - timeout := ''-00:00:01''::INTERVAL - Documentation: - ${PROJECT_DOC_LINK}/vrp_vroom.html '; diff --git a/sql/vroom/vrp_vroomJobs.sql b/sql/vroom/vrp_vroomJobs.sql index 4c493a733..3ce77f84d 100644 --- a/sql/vroom/vrp_vroomJobs.sql +++ b/sql/vroom/vrp_vroomJobs.sql @@ -34,7 +34,7 @@ signature start vrp_vroomJobs( Jobs SQL, Jobs Time Windows SQL, Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, - Matrix SQL) -- Experimental on v0.2 + Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2 RETURNS SET OF (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, @@ -42,6 +42,21 @@ signature start signature end +default signature start + +.. code-block:: none + + vrp_vroomJobs( + Jobs SQL, Jobs Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL) + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +default signature end + parameters start ============================== =========== ========================================================= @@ -72,6 +87,9 @@ CREATE FUNCTION vrp_vroomJobs( TEXT, -- breaks_time_windows_sql (required) TEXT, -- matrix_sql (required) + exploration_level INTEGER DEFAULT 5, + timeout INTERVAL DEFAULT '-00:00:01'::INTERVAL, + OUT seq BIGINT, OUT vehicle_seq BIGINT, OUT vehicle_id BIGINT, @@ -85,37 +103,46 @@ CREATE FUNCTION vrp_vroomJobs( OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ +BEGIN + IF exploration_level < 0 OR exploration_level > 5 THEN + RAISE EXCEPTION 'Invalid value found on ''exploration_level''' + USING HINT = format('Value found: %s. It must lie in the range 0 to 5 (inclusive)', exploration_level); + END IF; + + RETURN QUERY SELECT - seq, - vehicle_seq, - vehicle_id, - step_seq, - step_type, - task_id, - (to_timestamp(arrival) at time zone 'UTC')::TIMESTAMP, - make_interval(secs => travel_time), - make_interval(secs => service_time), - make_interval(secs => waiting_time), - load + A.seq, + A.vehicle_seq, + A.vehicle_id, + A.step_seq, + A.step_type, + A.task_id, + (to_timestamp(A.arrival) at time zone 'UTC')::TIMESTAMP, + make_interval(secs => A.travel_time), + make_interval(secs => A.service_time), + make_interval(secs => A.waiting_time), + A.load FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), NULL, NULL, _pgr_get_statement($3), _pgr_get_statement($4), - _pgr_get_statement($5), _pgr_get_statement($6), 1::SMALLINT, false); + _pgr_get_statement($5), _pgr_get_statement($6), exploration_level, + EXTRACT(epoch FROM timeout)::INTEGER, 1::SMALLINT, false) A; +END; $BODY$ -LANGUAGE SQL VOLATILE; +LANGUAGE plpgsql VOLATILE; -- COMMENTS -COMMENT ON FUNCTION vrp_vroomJobs(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +COMMENT ON FUNCTION vrp_vroomJobs(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTERVAL) IS 'vrp_vroomJobs - EXPERIMENTAL - Parameters: - Jobs SQL with columns: - id, location_index [, service, delivery, pickup, skills, priority, time_windows] + id, location_id [, service, delivery, pickup, skills, priority, time_windows] - Jobs Time Windows SQL with columns: id, tw_open, tw_close - Vehicles SQL with columns: - id, start_index, end_index + id, start_id, end_id [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] - Breaks SQL with columns: id [, service] @@ -123,6 +150,9 @@ IS 'vrp_vroomJobs id, tw_open, tw_close - Matrix SQL with columns: start_vid, end_vid, agg_cost +- Optional parameters + - exploration_level := 5 + - timeout := ''-00:00:01''::INTERVAL - Documentation: - ${PROJECT_DOC_LINK}/vrp_vroomJobs.html '; diff --git a/sql/vroom/vrp_vroomJobsPlain.sql b/sql/vroom/vrp_vroomJobsPlain.sql index fb6dd9061..6d9d97d1b 100644 --- a/sql/vroom/vrp_vroomJobsPlain.sql +++ b/sql/vroom/vrp_vroomJobsPlain.sql @@ -26,6 +26,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ +/* +signature start + +.. code-block:: none + + vrp_vroomJobsPlain( + Jobs SQL, Jobs Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2 + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +signature end + +default signature start + +.. code-block:: none + + vrp_vroomJobsPlain( + Jobs SQL, Jobs Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL) + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +default signature end +*/ + -- v0.2 CREATE FUNCTION vrp_vroomJobsPlain( TEXT, -- jobs_sql (required) @@ -35,6 +67,9 @@ CREATE FUNCTION vrp_vroomJobsPlain( TEXT, -- breaks_time_windows_sql (required) TEXT, -- matrix_sql (required) + exploration_level INTEGER DEFAULT 5, + timeout INTEGER DEFAULT -1, + OUT seq BIGINT, OUT vehicle_seq BIGINT, OUT vehicle_id BIGINT, @@ -48,26 +83,35 @@ CREATE FUNCTION vrp_vroomJobsPlain( OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ +BEGIN + IF exploration_level < 0 OR exploration_level > 5 THEN + RAISE EXCEPTION 'Invalid value found on ''exploration_level''' + USING HINT = format('Value found: %s. It must lie in the range 0 to 5 (inclusive)', exploration_level); + END IF; + + RETURN QUERY SELECT * FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), NULL, NULL, _pgr_get_statement($3), _pgr_get_statement($4), - _pgr_get_statement($5), _pgr_get_statement($6), 1::SMALLINT, true); + _pgr_get_statement($5), _pgr_get_statement($6), + exploration_level, timeout, 1::SMALLINT, true); +END; $BODY$ -LANGUAGE SQL VOLATILE; +LANGUAGE plpgsql VOLATILE; -- COMMENTS -COMMENT ON FUNCTION vrp_vroomJobsPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +COMMENT ON FUNCTION vrp_vroomJobsPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER) IS 'vrp_vroomJobsPlain - EXPERIMENTAL - Parameters: - Jobs SQL with columns: - id, location_index [, service, delivery, pickup, skills, priority, time_windows] + id, location_id [, service, delivery, pickup, skills, priority, time_windows] - Jobs Time Windows SQL with columns: id, tw_open, tw_close - Vehicles SQL with columns: - id, start_index, end_index + id, start_id, end_id [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] - Breaks SQL with columns: id [, service] @@ -75,6 +119,9 @@ IS 'vrp_vroomJobsPlain id, tw_open, tw_close - Matrix SQL with columns: start_vid, end_vid, agg_cost +- Optional parameters + - exploration_level := 5 + - timeout := -1 - Documentation: - ${PROJECT_DOC_LINK}/vrp_vroomJobsPlain.html '; diff --git a/sql/vroom/vrp_vroomPlain.sql b/sql/vroom/vrp_vroomPlain.sql index 3d533d0c5..a452371a7 100644 --- a/sql/vroom/vrp_vroomPlain.sql +++ b/sql/vroom/vrp_vroomPlain.sql @@ -26,6 +26,59 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ +/* +signature start + +.. code-block:: none + + vrp_vroomPlain( + Jobs SQL, Jobs Time Windows SQL, + Shipments SQL, Shipments Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2 + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +signature end + +default signature start + +.. code-block:: none + + vrp_vroomPlain( + Jobs SQL, Jobs Time Windows SQL, + Shipments SQL, Shipments Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL) + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +default signature end + +optional parameters start + +===================== ============ ============================= ================================================= +Parameter Type Default Description +===================== ============ ============================= ================================================= +**exploration_level** ``INTEGER`` :math:`5` Exploration level to use while solving. + + - Ranges from ``[0, 5]`` + - A smaller exploration level gives faster result. + +**timeout** ``INTEGER`` :math:`-1` Timeout value to stop the solving process. + + - Gives the best possible solution within a time + limit. Note that some additional seconds may be + required to return back the data. + - Any negative timeout value is ignored. +===================== ============ ============================= ================================================= + +optional parameters end +*/ -- v0.2 CREATE FUNCTION vrp_vroomPlain( @@ -38,6 +91,9 @@ CREATE FUNCTION vrp_vroomPlain( TEXT, -- breaks_time_windows_sql (required) TEXT, -- matrix_sql (required) + exploration_level INTEGER DEFAULT 5, + timeout INTEGER DEFAULT -1, + OUT seq BIGINT, OUT vehicle_seq BIGINT, OUT vehicle_id BIGINT, @@ -51,31 +107,40 @@ CREATE FUNCTION vrp_vroomPlain( OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ +BEGIN + IF exploration_level < 0 OR exploration_level > 5 THEN + RAISE EXCEPTION 'Invalid value found on ''exploration_level''' + USING HINT = format('Value found: %s. It must lie in the range 0 to 5 (inclusive)', exploration_level); + END IF; + + RETURN QUERY SELECT * FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), _pgr_get_statement($4), _pgr_get_statement($5), _pgr_get_statement($6), - _pgr_get_statement($7), _pgr_get_statement($8), 0::SMALLINT, true); + _pgr_get_statement($7), _pgr_get_statement($8), exploration_level, + timeout, 0::SMALLINT, true); +END; $BODY$ -LANGUAGE SQL VOLATILE; +LANGUAGE plpgsql VOLATILE; -- COMMENTS -COMMENT ON FUNCTION vrp_vroomPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +COMMENT ON FUNCTION vrp_vroomPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER) IS 'vrp_vroomPlain - EXPERIMENTAL - Parameters: - Jobs SQL with columns: - id, location_index [, service, delivery, pickup, skills, priority, time_windows] + id, location_id [, service, delivery, pickup, skills, priority, time_windows] - Jobs Time Windows SQL with columns: id, tw_open, tw_close - Shipments SQL with columns: - p_id, p_location_index [, p_service, p_time_windows], - d_id, d_location_index [, d_service, d_time_windows] [, amount, skills, priority] + p_id, p_location_id [, p_service, p_time_windows], + d_id, d_location_id [, d_service, d_time_windows] [, amount, skills, priority] - Shipments Time Windows SQL with columns: id, kind, tw_open, tw_close - Vehicles SQL with columns: - id, start_index, end_index + id, start_id, end_id [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] - Breaks SQL with columns: id [, service] @@ -83,6 +148,9 @@ IS 'vrp_vroomPlain id, tw_open, tw_close - Matrix SQL with columns: start_vid, end_vid, agg_cost +- Optional parameters + - exploration_level := 5 + - timeout := -1 - Documentation: - ${PROJECT_DOC_LINK}/vrp_vroomPlain.html '; diff --git a/sql/vroom/vrp_vroomShipments.sql b/sql/vroom/vrp_vroomShipments.sql index 6bde8157c..dd75a0b80 100644 --- a/sql/vroom/vrp_vroomShipments.sql +++ b/sql/vroom/vrp_vroomShipments.sql @@ -34,7 +34,7 @@ signature start vrp_vroomShipments( Shipments SQL, Shipments Time Windows SQL, Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, - Matrix SQL) -- Experimental on v0.2 + Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2 RETURNS SET OF (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, @@ -42,6 +42,21 @@ signature start signature end +default signature start + +.. code-block:: none + + vrp_vroomShipments( + Shipments SQL, Shipments Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL) + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +default signature end + parameters start ============================== =========== ========================================================= @@ -72,6 +87,9 @@ CREATE FUNCTION vrp_vroomShipments( TEXT, -- breaks_time_windows_sql (required) TEXT, -- matrix_sql (required) + exploration_level INTEGER DEFAULT 5, + timeout INTERVAL DEFAULT '-00:00:01'::INTERVAL, + OUT seq BIGINT, OUT vehicle_seq BIGINT, OUT vehicle_id BIGINT, @@ -85,39 +103,48 @@ CREATE FUNCTION vrp_vroomShipments( OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ +BEGIN + IF exploration_level < 0 OR exploration_level > 5 THEN + RAISE EXCEPTION 'Invalid value found on ''exploration_level''' + USING HINT = format('Value found: %s. It must lie in the range 0 to 5 (inclusive)', exploration_level); + END IF; + + RETURN QUERY SELECT - seq, - vehicle_seq, - vehicle_id, - step_seq, - step_type, - task_id, - (to_timestamp(arrival) at time zone 'UTC')::TIMESTAMP, - make_interval(secs => travel_time), - make_interval(secs => service_time), - make_interval(secs => waiting_time), - load + A.seq, + A.vehicle_seq, + A.vehicle_id, + A.step_seq, + A.step_type, + A.task_id, + (to_timestamp(A.arrival) at time zone 'UTC')::TIMESTAMP, + make_interval(secs => A.travel_time), + make_interval(secs => A.service_time), + make_interval(secs => A.waiting_time), + A.load FROM _vrp_vroom(NULL, NULL, _pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), _pgr_get_statement($4), _pgr_get_statement($5), - _pgr_get_statement($6), 2::SMALLINT, false); + _pgr_get_statement($6), exploration_level, + EXTRACT(epoch FROM timeout)::INTEGER, 2::SMALLINT, false) A; +END; $BODY$ -LANGUAGE SQL VOLATILE; +LANGUAGE plpgsql VOLATILE; -- COMMENTS -COMMENT ON FUNCTION vrp_vroomShipments(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +COMMENT ON FUNCTION vrp_vroomShipments(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTERVAL) IS 'vrp_vroomShipments - EXPERIMENTAL - Parameters: - Shipments SQL with columns: - p_id, p_location_index [, p_service, p_time_windows], - d_id, d_location_index [, d_service, d_time_windows] [, amount, skills, priority] + p_id, p_location_id [, p_service, p_time_windows], + d_id, d_location_id [, d_service, d_time_windows] [, amount, skills, priority] - Shipments Time Windows SQL with columns: id, kind, tw_open, tw_close - Vehicles SQL with columns: - id, start_index, end_index + id, start_id, end_id [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] - Breaks SQL with columns: id [, service] @@ -125,6 +152,9 @@ IS 'vrp_vroomShipments id, tw_open, tw_close - Matrix SQL with columns: start_vid, end_vid, agg_cost +- Optional parameters + - exploration_level := 5 + - timeout := ''-00:00:01''::INTERVAL - Documentation: - ${PROJECT_DOC_LINK}/vrp_vroomShipments.html '; diff --git a/sql/vroom/vrp_vroomShipmentsPlain.sql b/sql/vroom/vrp_vroomShipmentsPlain.sql index de9bca901..1fd813bbf 100644 --- a/sql/vroom/vrp_vroomShipmentsPlain.sql +++ b/sql/vroom/vrp_vroomShipmentsPlain.sql @@ -26,6 +26,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ +/* +signature start + +.. code-block:: none + + vrp_vroomShipmentsPlain( + Shipments SQL, Shipments Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2 + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +signature end + +default signature start + +.. code-block:: none + + vrp_vroomShipmentsPlain( + Shipments SQL, Shipments Time Windows SQL, + Vehicles SQL, Breaks SQL, Breaks Time Windows SQL, + Matrix SQL) + + RETURNS SET OF + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +default signature end +*/ -- v0.2 CREATE FUNCTION vrp_vroomShipmentsPlain( @@ -36,6 +67,9 @@ CREATE FUNCTION vrp_vroomShipmentsPlain( TEXT, -- breaks_time_windows_sql (required) TEXT, -- matrix_sql (required) + exploration_level INTEGER DEFAULT 5, + timeout INTEGER DEFAULT -1, + OUT seq BIGINT, OUT vehicle_seq BIGINT, OUT vehicle_id BIGINT, @@ -49,28 +83,37 @@ CREATE FUNCTION vrp_vroomShipmentsPlain( OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ +BEGIN + IF exploration_level < 0 OR exploration_level > 5 THEN + RAISE EXCEPTION 'Invalid value found on ''exploration_level''' + USING HINT = format('Value found: %s. It must lie in the range 0 to 5 (inclusive)', exploration_level); + END IF; + + RETURN QUERY SELECT * FROM _vrp_vroom(NULL, NULL, _pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), _pgr_get_statement($4), _pgr_get_statement($5), - _pgr_get_statement($6), 2::SMALLINT, true); + _pgr_get_statement($6), exploration_level, + timeout, 2::SMALLINT, true); +END; $BODY$ -LANGUAGE SQL VOLATILE; +LANGUAGE plpgsql VOLATILE; -- COMMENTS -COMMENT ON FUNCTION vrp_vroomShipmentsPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +COMMENT ON FUNCTION vrp_vroomShipmentsPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER) IS 'vrp_vroomShipmentsPlain - EXPERIMENTAL - Parameters: - Shipments SQL with columns: - p_id, p_location_index [, p_service, p_time_windows], - d_id, d_location_index [, d_service, d_time_windows] [, amount, skills, priority] + p_id, p_location_id [, p_service, p_time_windows], + d_id, d_location_id [, d_service, d_time_windows] [, amount, skills, priority] - Shipments Time Windows SQL with columns: id, kind, tw_open, tw_close - Vehicles SQL with columns: - id, start_index, end_index + id, start_id, end_id [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] - Breaks SQL with columns: id [, service] @@ -78,6 +121,9 @@ IS 'vrp_vroomShipmentsPlain id, tw_open, tw_close - Matrix SQL with columns: start_vid, end_vid, agg_cost +- Optional parameters + - exploration_level := 5 + - timeout := -1 - Documentation: - ${PROJECT_DOC_LINK}/vrp_vroomShipmentsPlain.html '; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 010783ab9..268e4c29c 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -17,4 +17,5 @@ ADD_LIBRARY(common OBJECT vroom/jobs_input.c vroom/shipments_input.c vroom/vehicles_input.c + vroom/matrix_input.c ) diff --git a/src/common/get_check_data.c b/src/common/get_check_data.c index cacbea651..e984131c2 100644 --- a/src/common/get_check_data.c +++ b/src/common/get_check_data.c @@ -308,6 +308,22 @@ spi_getChar( return value; } +int32_t +spi_getMaxTasks( + HeapTuple *tuple, + TupleDesc *tupdesc, + Column_info_t info) { + int32_t value = spi_getInt(tuple, tupdesc, info); + if (value < 0) { + ereport( + ERROR, + (errmsg("Invalid max_tasks value %d", value), + errhint( + "Maximum number of tasks must be greater than or equal to 0"))); + } + return value; +} + int64_t* spi_getBigIntArr( HeapTuple *tuple, @@ -663,6 +679,30 @@ get_Duration(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Duration return opt_value; } + +/** + * @params [in] tuple + * @params [in] tupdesc + * @params [in] info about the column been fetched + * @params [in] opt_value default value when the column does not exist + * + * @returns The value found + * @returns opt_value when the column does not exist + * + * exceptions when the value is negative + * @pre for non-negative values only + */ +TravelCost +get_Cost(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TravelCost opt_value) { + if (column_found(info.colNumber)) { + int32_t value = spi_getInt(tuple, tupdesc, info); + if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); + return (TravelCost)value; + } + return opt_value; +} + + /** * @params [in] tuple * @params [in] tupdesc diff --git a/src/common/matrixRows_input.c b/src/common/matrixRows_input.c index 5e9fe8f86..eeddb91f9 100644 --- a/src/common/matrixRows_input.c +++ b/src/common/matrixRows_input.c @@ -56,24 +56,6 @@ Column Type Description .. pgr_pickDeliver end -.. vrp_vroom start - -A ``SELECT`` statement that returns the following columns: - -:: - - start_vid, end_vid, agg_cost - -=============== ================= ================================================== -Column Type Description -=============== ================= ================================================== -**start_vid** ``ANY-INTEGER`` Identifier of the start node. -**end_vid** ``ANY-INTEGER`` Identifier of the end node. -**agg_cost** ``INTEGER`` Time to travel from ``start_vid`` to ``end_vid`` -=============== ================= ================================================== - -.. vrp_vroom end - */ static @@ -238,26 +220,3 @@ get_matrixRows_plain( info[2].eType = ANY_NUMERICAL; get_matrixRows_general(sql, info, 1, rows, total_rows); } - -/** - * @param [in] sql SQL query that has the following columns: start_vid, end_vid, agg_cost - * @param [out] rows C Container that holds all the matrix rows - * @param [out] total_rows Total rows recieved - */ -void get_matrixRows_vroom_plain(char *sql, Matrix_cell_t **rows, size_t *total_rows) { - Column_info_t info[3]; - - int i; - for (i = 0; i < 3; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "start_vid"; - info[1].name = "end_vid"; - info[2].name = "agg_cost"; - - info[2].eType = INTEGER; - get_matrixRows_general(sql, info, 1, rows, total_rows); -} diff --git a/src/common/vroom/breaks_input.c b/src/common/vroom/breaks_input.c index 14dbfd351..7e7c61acb 100644 --- a/src/common/vroom/breaks_input.c +++ b/src/common/vroom/breaks_input.c @@ -38,16 +38,14 @@ A ``SELECT`` statement that returns the following columns: id, vehicle_id [, service] ==================== ========================= =========== ================================================ -Column Type Default Description +Column Type Default Description ==================== ========================= =========== ================================================ **id** ``ANY-INTEGER`` Non-negative unique identifier of the break. (unique for the same vehicle). **vehicle_id** ``ANY-INTEGER`` Non-negative unique identifier of the vehicle. -**service** ``INTERVAL`` 0 The break duration, in seconds. - - - ``INTEGER`` for plain VROOM functions. +**service** |interval| |interval0| The break duration. ==================== ========================= =========== ================================================ .. vrp_vroom end diff --git a/src/common/vroom/jobs_input.c b/src/common/vroom/jobs_input.c index 1516ef9f4..00ca57a49 100644 --- a/src/common/vroom/jobs_input.c +++ b/src/common/vroom/jobs_input.c @@ -35,8 +35,8 @@ A ``SELECT`` statement that returns the following columns: :: - id, location_index - [, service, delivery, pickup, skills, priority] + id, location_id + [, setup, service, delivery, pickup, skills, priority] ==================== ========================= =========== ================================================ @@ -44,27 +44,27 @@ Column Type Default Description ==================== ========================= =========== ================================================ **id** ``ANY-INTEGER`` Non-negative unique identifier of the job. -**location_index** ``ANY-INTEGER`` Non-negative identifier of the job location. +**location_id** ``ANY-INTEGER`` Non-negative identifier of the job location. -**service** ``INTERVAL`` 0 Job service duration, in seconds +**setup** |interval| |interval0| Job setup duration. - - ``INTEGER`` for plain VROOM functions. +**service** |interval| |interval0| Job service duration. -**delivery** ``ARRAY[ANY-INTEGER]`` Array of non-negative integers describing +**delivery** ``ARRAY[ANY-INTEGER]`` Empty Array Array of non-negative integers describing multidimensional quantities for delivery such as number of items, weight, volume etc. - All jobs must have the same value of :code:`array_length(delivery, 1)` -**pickup** ``ARRAY[ANY-INTEGER]`` Array of non-negative integers describing +**pickup** ``ARRAY[ANY-INTEGER]`` Empty Array Array of non-negative integers describing multidimensional quantities for pickup such as number of items, weight, volume etc. - All jobs must have the same value of :code:`array_length(pickup, 1)` -**skills** ``ARRAY[INTEGER]`` Array of non-negative integers defining +**skills** ``ARRAY[INTEGER]`` Empty Array Array of non-negative integers defining mandatory skills. **priority** ``INTEGER`` 0 Priority level of the job @@ -87,36 +87,38 @@ void fetch_jobs( Vroom_job_t *job, bool is_plain) { job->id = get_Idx(tuple, tupdesc, info[0], 0); - job->location_index = get_MatrixIndex(tuple, tupdesc, info[1], 0); + job->location_id = get_MatrixIndex(tuple, tupdesc, info[1], 0); if (is_plain) { - job->service = get_Duration(tuple, tupdesc, info[2], 0); + job->setup = get_Duration(tuple, tupdesc, info[2], 0); + job->service = get_Duration(tuple, tupdesc, info[3], 0); } else { - job->service = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + job->setup = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + job->service = (Duration)get_PositiveTInterval(tuple, tupdesc, info[3], 0); } /* * The deliveries */ job->delivery_size = 0; - job->delivery = column_found(info[3].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[3], &job->delivery_size) + job->delivery = column_found(info[4].colNumber) ? + spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[4], &job->delivery_size) : NULL; /* * The pickups */ job->pickup_size = 0; - job->pickup = column_found(info[4].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[4], &job->pickup_size) + job->pickup = column_found(info[5].colNumber) ? + spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[5], &job->pickup_size) : NULL; job->skills_size = 0; - job->skills = column_found(info[5].colNumber) ? - spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[5], &job->skills_size) + job->skills = column_found(info[6].colNumber) ? + spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[6], &job->skills_size) : NULL; - job->priority = get_Priority(tuple, tupdesc, info[6], 0); + job->priority = get_Priority(tuple, tupdesc, info[7], 0); } @@ -207,7 +209,7 @@ get_vroom_jobs( Vroom_job_t **rows, size_t *total_rows, bool is_plain) { - int kColumnCount = 7; + int kColumnCount = 8; Column_info_t info[kColumnCount]; for (int i = 0; i < kColumnCount; ++i) { @@ -218,24 +220,27 @@ get_vroom_jobs( } info[0].name = "id"; - info[1].name = "location_index"; - info[2].name = "service"; - info[3].name = "delivery"; - info[4].name = "pickup"; - info[5].name = "skills"; - info[6].name = "priority"; - - info[2].eType = INTEGER; // service - info[3].eType = ANY_INTEGER_ARRAY; // delivery - info[4].eType = ANY_INTEGER_ARRAY; // pickup - info[5].eType = INTEGER_ARRAY; // skills - info[6].eType = INTEGER; // priority + info[1].name = "location_id"; + info[2].name = "setup"; + info[3].name = "service"; + info[4].name = "delivery"; + info[5].name = "pickup"; + info[6].name = "skills"; + info[7].name = "priority"; + + info[2].eType = INTEGER; // setup + info[3].eType = INTEGER; // service + info[4].eType = ANY_INTEGER_ARRAY; // delivery + info[5].eType = ANY_INTEGER_ARRAY; // pickup + info[6].eType = INTEGER_ARRAY; // skills + info[7].eType = INTEGER; // priority if (!is_plain) { - info[2].eType = INTERVAL; // service + info[2].eType = INTERVAL; // setup + info[3].eType = INTERVAL; // service } - /* Only id and location_index are mandatory */ + /* Only id and location_id are mandatory */ info[0].strict = true; info[1].strict = true; diff --git a/src/common/vroom/matrix_input.c b/src/common/vroom/matrix_input.c new file mode 100644 index 000000000..b190c3e39 --- /dev/null +++ b/src/common/vroom/matrix_input.c @@ -0,0 +1,191 @@ +/*PGR-GNU***************************************************************** +File: matrix_input.c + +Copyright (c) 2021 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2021 Ashish Kumar +Mail: ashishkr23438@gmail.com + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +#include "c_common/vroom/matrix_input.h" + +/* +.. vrp_vroom start + +A ``SELECT`` statement that returns the following columns: + +:: + + start_id, end_id, duration [, cost] + +=============== ================= ============== ================================================== +Column Type Default Description +=============== ================= ============== ================================================== +**start_id** ``ANY-INTEGER`` Identifier of the start node. + +**end_id** ``ANY-INTEGER`` Identifier of the end node. + +**duration** |interval| Time to travel from ``start_id`` to ``end_id`` + +**cost** ``INTEGER`` *duration* Cost to travel from ``start_id`` to ``end_id`` +=============== ================= ============== ================================================== + +.. vrp_vroom end +*/ + +static +void fetch_matrix( + HeapTuple *tuple, + TupleDesc *tupdesc, + Column_info_t *info, + Vroom_matrix_t *matrix, + bool is_plain) { + matrix->start_id = get_MatrixIndex(tuple, tupdesc, info[0], -1); + matrix->end_id = get_MatrixIndex(tuple, tupdesc, info[1], -1); + + if (is_plain) { + matrix->duration = get_Duration(tuple, tupdesc, info[2], 0); + } else { + matrix->duration = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + } + + // If unspecified, cost is same as the duration + matrix->cost = get_Cost(tuple, tupdesc, info[3], matrix->duration); +} + + +static +void db_get_matrix( + char *matrix_sql, + Vroom_matrix_t **matrix, + size_t *total_matrix_rows, + + Column_info_t *info, + const int column_count, + bool is_plain) { +#ifdef PROFILE + clock_t start_t = clock(); + PGR_DBG("%s", matrix_sql); +#endif + + const int tuple_limit = 1000000; + + size_t total_tuples; + + void *SPIplan; + SPIplan = pgr_SPI_prepare(matrix_sql); + Portal SPIportal; + SPIportal = pgr_SPI_cursor_open(SPIplan); + + bool moredata = true; + (*total_matrix_rows) = total_tuples = 0; + + /* on the first tuple get the column numbers */ + + while (moredata == true) { + SPI_cursor_fetch(SPIportal, true, tuple_limit); + if (total_tuples == 0) { + pgr_fetch_column_info(info, column_count); + } + size_t ntuples = SPI_processed; + total_tuples += ntuples; + if (ntuples > 0) { + if ((*matrix) == NULL) + (*matrix) = (Vroom_matrix_t *)palloc0( + total_tuples * sizeof(Vroom_matrix_t)); + else + (*matrix) = (Vroom_matrix_t *)repalloc( + (*matrix), + total_tuples * sizeof(Vroom_matrix_t)); + + if ((*matrix) == NULL) { + elog(ERROR, "Out of memory"); + } + + size_t t; + SPITupleTable *tuptable = SPI_tuptable; + TupleDesc tupdesc = SPI_tuptable->tupdesc; + for (t = 0; t < ntuples; t++) { + HeapTuple tuple = tuptable->vals[t]; + fetch_matrix(&tuple, &tupdesc, info, + &(*matrix)[total_tuples - ntuples + t], is_plain); + } + SPI_freetuptable(tuptable); + } else { + moredata = false; + } + } + + SPI_cursor_close(SPIportal); + + if (total_tuples == 0) { + (*total_matrix_rows) = 0; + return; + } + + (*total_matrix_rows) = total_tuples; +#ifdef PROFILE + time_msg("reading matrix", start_t, clock()); +#endif +} + + +/** + * @param [in] sql SQL query that has the following columns: start_id, end_id, duration, cost + * @param[in] is_plain Whether the plain or timestamp function is used + * @param [out] rows C Container that holds all the matrix rows + * @param [out] total_rows Total rows recieved + */ +void +get_vroom_matrix( + char *sql, + Vroom_matrix_t **rows, + size_t *total_rows, + bool is_plain) { + int kColumnCount = 4; + Column_info_t info[kColumnCount]; + + for (int i = 0; i < kColumnCount; ++i) { + info[i].colNumber = -1; + info[i].type = 0; + info[i].strict = true; + info[i].eType = ANY_INTEGER; + } + info[0].name = "start_id"; + info[1].name = "end_id"; + info[2].name = "duration"; + info[3].name = "cost"; + + info[2].eType = INTEGER; // duration + info[3].eType = INTEGER; // cost + + if (!is_plain) { + info[2].eType = INTERVAL; // duration + } + + /** + * cost is not mandatory + */ + info[3].strict = false; + + db_get_matrix(sql, rows, total_rows, info, kColumnCount, is_plain); +} diff --git a/src/common/vroom/shipments_input.c b/src/common/vroom/shipments_input.c index 40ede8f6d..d050fce4b 100644 --- a/src/common/vroom/shipments_input.c +++ b/src/common/vroom/shipments_input.c @@ -35,7 +35,7 @@ A ``SELECT`` statement that returns the following columns: :: - id, p_location_index [, p_service], d_location_index [, d_service] + id, p_location_id [, p_service], d_location_id [, d_service] [, amount, skills, priority] @@ -44,26 +44,26 @@ Column Type Default Description ====================== ========================= =========== ================================================ **id** ``ANY-INTEGER`` Non-negative unique identifier of the shipment. -**p_location_index** ``ANY-INTEGER`` Non-negative identifier of the pickup location. +**p_location_id** ``ANY-INTEGER`` Non-negative identifier of the pickup location. -**p_service** ``INTERVAL`` 0 Pickup service duration, in seconds +**p_setup** |interval| |interval0| Pickup setup duration. - - ``INTEGER`` for plain VROOM functions. +**p_service** |interval| |interval0| Pickup service duration. -**d_location_index** ``ANY-INTEGER`` Non-negative identifier of the delivery location. +**d_location_id** ``ANY-INTEGER`` Non-negative identifier of the delivery location. -**d_service** ``INTERVAL`` 0 Delivery service duration, in seconds +**d_setup** |interval| |interval0| Delivery setup duration. - - ``INTEGER`` for plain VROOM functions. +**d_service** |interval| |interval0| Delivery service duration. -**amount** ``ARRAY[ANY-INTEGER]`` Array of non-negative integers describing +**amount** ``ARRAY[ANY-INTEGER]`` Empty Array Array of non-negative integers describing multidimensional quantities such as number of items, weight, volume etc. - All shipments must have the same value of :code:`array_length(amount, 1)` -**skills** ``ARRAY[INTEGER]`` Array of non-negative integers defining +**skills** ``ARRAY[INTEGER]`` Empty Array Array of non-negative integers defining mandatory skills. **priority** ``INTEGER`` 0 Priority level of the shipment. @@ -88,30 +88,36 @@ void fetch_shipments( bool is_plain) { shipment->id = get_Idx(tuple, tupdesc, info[0], 0); - shipment->p_location_index = get_MatrixIndex(tuple, tupdesc, info[1], 0); - shipment->d_location_index = get_MatrixIndex(tuple, tupdesc, info[3], 0); + shipment->p_location_id = get_MatrixIndex(tuple, tupdesc, info[1], 0); + shipment->d_location_id = get_MatrixIndex(tuple, tupdesc, info[4], 0); if (is_plain) { - shipment->p_service = get_Duration(tuple, tupdesc, info[2], 0); - shipment->d_service = get_Duration(tuple, tupdesc, info[4], 0); + shipment->p_setup = get_Duration(tuple, tupdesc, info[2], 0); + shipment->p_service = get_Duration(tuple, tupdesc, info[3], 0); + shipment->d_setup = get_Duration(tuple, tupdesc, info[5], 0); + shipment->d_service = get_Duration(tuple, tupdesc, info[6], 0); } else { - shipment->p_service = + shipment->p_setup = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + shipment->p_service = + (Duration)get_PositiveTInterval(tuple, tupdesc, info[3], 0); + shipment->d_setup = + (Duration)get_PositiveTInterval(tuple, tupdesc, info[5], 0); shipment->d_service = - (Duration)get_PositiveTInterval(tuple, tupdesc, info[4], 0); + (Duration)get_PositiveTInterval(tuple, tupdesc, info[6], 0); } shipment->amount_size = 0; - shipment->amount = column_found(info[5].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[5], &shipment->amount_size) + shipment->amount = column_found(info[7].colNumber) ? + spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[7], &shipment->amount_size) : NULL; shipment->skills_size = 0; - shipment->skills = column_found(info[6].colNumber) ? - spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[6], &shipment->skills_size) + shipment->skills = column_found(info[8].colNumber) ? + spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[8], &shipment->skills_size) : NULL; - shipment->priority = get_Priority(tuple, tupdesc, info[7], 0); + shipment->priority = get_Priority(tuple, tupdesc, info[9], 0); } @@ -202,7 +208,7 @@ get_vroom_shipments( Vroom_shipment_t **rows, size_t *total_rows, bool is_plain) { - int kColumnCount = 8; + int kColumnCount = 10; Column_info_t info[kColumnCount]; for (int i = 0; i < kColumnCount; ++i) { @@ -215,32 +221,38 @@ get_vroom_shipments( info[0].name = "id"; /* pickup shipments */ - info[1].name = "p_location_index"; - info[2].name = "p_service"; + info[1].name = "p_location_id"; + info[2].name = "p_setup"; + info[3].name = "p_service"; /* delivery shipments */ - info[3].name = "d_location_index"; - info[4].name = "d_service"; - - info[5].name = "amount"; - info[6].name = "skills"; - info[7].name = "priority"; - - info[2].eType = INTEGER; // p_service - info[4].eType = INTEGER; // d_service - info[5].eType = ANY_INTEGER_ARRAY; // amount - info[6].eType = INTEGER_ARRAY; // skills - info[7].eType = INTEGER; // priority + info[4].name = "d_location_id"; + info[5].name = "d_setup"; + info[6].name = "d_service"; + + info[7].name = "amount"; + info[8].name = "skills"; + info[9].name = "priority"; + + info[2].eType = INTEGER; // p_setup + info[3].eType = INTEGER; // p_service + info[5].eType = INTEGER; // d_setup + info[6].eType = INTEGER; // d_service + info[7].eType = ANY_INTEGER_ARRAY; // amount + info[8].eType = INTEGER_ARRAY; // skills + info[9].eType = INTEGER; // priority if (!is_plain) { - info[2].eType = INTERVAL; // p_service - info[4].eType = INTERVAL; // d_service + info[2].eType = INTERVAL; // p_setup + info[3].eType = INTERVAL; // p_service + info[5].eType = INTERVAL; // d_setup + info[6].eType = INTERVAL; // d_service } - /* id and location_index of pickup and delivery are mandatory */ + /* id and location_id of pickup and delivery are mandatory */ info[0].strict = true; info[1].strict = true; - info[3].strict = true; + info[4].strict = true; db_get_shipments(sql, rows, total_rows, info, kColumnCount, is_plain); } diff --git a/src/common/vroom/time_windows_input.c b/src/common/vroom/time_windows_input.c index 86311d16d..50cf8a7e2 100644 --- a/src/common/vroom/time_windows_input.c +++ b/src/common/vroom/time_windows_input.c @@ -43,24 +43,21 @@ Column Type Description **id** ``ANY-INTEGER`` Non-negative unique identifier of the job, pickup/delivery shipment, or break. -**kind** ``CHAR`` **Only required for shipments**. Value in ['p', 'd'] - indicating whether the time window is for: +**kind** ``CHAR`` **Only required for shipments time windows**. + Value in ['p', 'd'] indicating whether + the time window is for: - Pickup shipment, or - Delivery shipment. -**tw_open** ``TIMESTAMP`` Time window opening time. +**tw_open** |timestamp| Time window opening time. - - ``INTEGER`` for plain VROOM functions. - -**tw_close** ``TIMESTAMP`` Time window closing time. - - - ``INTEGER`` for plain VROOM functions. +**tw_close** |timestamp| Time window closing time. ==================== ====================================== ===================================================== **Note**: -- All timing are in seconds. +- All timings are in **seconds** when represented as an ``INTEGER``. - Every row must satisfy the condition: :code:`tw_open ≤ tw_close`. - It is up to users to decide how to describe time windows: @@ -89,33 +86,33 @@ void fetch_time_windows( } time_window->kind = kind; if (is_plain) { - time_window->start_time = get_Duration(tuple, tupdesc, info[2], 0); - time_window->end_time = get_Duration(tuple, tupdesc, info[3], 0); + time_window->tw_open = get_Duration(tuple, tupdesc, info[2], 0); + time_window->tw_close = get_Duration(tuple, tupdesc, info[3], 0); } else { - time_window->start_time = + time_window->tw_open = (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[2], 0); - time_window->end_time = + time_window->tw_close = (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[3], 0); } } else { if (is_plain) { - time_window->start_time = get_Duration(tuple, tupdesc, info[1], 0); - time_window->end_time = get_Duration(tuple, tupdesc, info[2], 0); + time_window->tw_open = get_Duration(tuple, tupdesc, info[1], 0); + time_window->tw_close = get_Duration(tuple, tupdesc, info[2], 0); } else { - time_window->start_time = + time_window->tw_open = (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[1], 0); - time_window->end_time = + time_window->tw_close = (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[2], 0); } } - if (time_window->start_time > time_window->end_time) { + if (time_window->tw_open > time_window->tw_close) { ereport(ERROR, (errmsg("Invalid time window (%d, %d)", - time_window->start_time, time_window->end_time), + time_window->tw_open, time_window->tw_close), errhint("Time window start time %d must be " "less than or equal to time window end time %d", - time_window->start_time, time_window->end_time))); + time_window->tw_open, time_window->tw_close))); } } diff --git a/src/common/vroom/vehicles_input.c b/src/common/vroom/vehicles_input.c index c63f1a6d7..cf267b5e4 100644 --- a/src/common/vroom/vehicles_input.c +++ b/src/common/vroom/vehicles_input.c @@ -35,46 +35,49 @@ A ``SELECT`` statement that returns the following columns: :: - id, start_index, end_index - [, capacity, skills, tw_open, tw_close, speed_factor] + id, start_id, end_id + [, capacity, skills, tw_open, tw_close, speed_factor, max_tasks] -====================== ================================= ================================================ -Column Type Description -====================== ================================= ================================================ -**id** ``ANY-INTEGER`` Non-negative unique identifier of the job. +====================== ======================== =================== ================================================ +Column Type Default Description +====================== ======================== =================== ================================================ +**id** ``ANY-INTEGER`` Non-negative unique identifier of the vehicle. -**start_index** ``ANY-INTEGER`` Non-negative identifier of the vehicle start location. +**start_id** ``ANY-INTEGER`` Non-negative identifier of the vehicle start location. -**end_index** ``ANY-INTEGER`` Non-negative identifier of the vehicle end location. +**end_id** ``ANY-INTEGER`` Non-negative identifier of the vehicle end location. -**capacity** ``ARRAY[ANY-INTEGER]`` Array of non-negative integers describing - multidimensional quantities such as - number of items, weight, volume etc. +**capacity** ``ARRAY[ANY-INTEGER]`` Empty Array Array of non-negative integers describing + multidimensional quantities such as + number of items, weight, volume etc. - - All vehicles must have the same value of - :code:`array_length(capacity, 1)` + - All vehicles must have the same value of + :code:`array_length(capacity, 1)` -**skills** ``ARRAY[INTEGER]`` Array of non-negative integers defining - mandatory skills. +**skills** ``ARRAY[INTEGER]`` Empty Array Array of non-negative integers defining + mandatory skills. -**tw_open** ``TIMESTAMP`` Time window opening time. +**tw_open** |timestamp| |tw_open_default| Time window opening time. - - ``INTEGER`` for plain VROOM functions. +**tw_close** |timestamp| |tw_close_default| Time window closing time. -**tw_close** ``TIMESTAMP`` Time window closing time. +**speed_factor** ``ANY-NUMERICAL`` :math:`1.0` Vehicle travel time multiplier. - - ``INTEGER`` for plain VROOM functions. + - Max value of speed factor for a vehicle shall not be + greater than 5 times the speed factor of any other vehicle. -**speed_factor** ``ANY-NUMERICAL`` Vehicle travel time multiplier. -====================== ================================= ================================================ +**max_tasks** ``INTEGER`` :math:`2147483647` Maximum number of tasks in a route for the vehicle. + + - A job, pickup, or delivery is counted as a single task. +====================== ======================== =================== ================================================ **Note**: -- At least one of the ``start_index`` or ``end_index`` shall be present. -- If ``end_index`` is omitted, the resulting route will stop at the last visited task, whose choice is determined by the optimization process. -- If ``start_index`` is omitted, the resulting route will start at the first visited task, whose choice is determined by the optimization process. -- To request a round trip, specify both ``start_index`` and ``end_index`` as the same index. +- At least one of the ``start_id`` or ``end_id`` shall be present. +- If ``end_id`` is omitted, the resulting route will stop at the last visited task, whose choice is determined by the optimization process. +- If ``start_id`` is omitted, the resulting route will start at the first visited task, whose choice is determined by the optimization process. +- To request a round trip, specify both ``start_id`` and ``end_id`` as the same index. - A vehicle is only allowed to serve a set of tasks if the resulting load at each route step is lower than the matching value in capacity for each metric. When using multiple components for amounts, it is recommended to put the most important/limiting metrics first. - It is assumed that all delivery-related amounts for jobs are loaded at vehicle start, while all pickup-related amounts for jobs are brought back at vehicle end. - :code:`tw_open ≤ tw_close` @@ -90,8 +93,8 @@ void fetch_vehicles( Vroom_vehicle_t *vehicle, bool is_plain) { vehicle->id = get_Idx(tuple, tupdesc, info[0], 0); - vehicle->start_index = get_MatrixIndex(tuple, tupdesc, info[1], -1); - vehicle->end_index = get_MatrixIndex(tuple, tupdesc, info[2], -1); + vehicle->start_id = get_MatrixIndex(tuple, tupdesc, info[1], -1); + vehicle->end_id = get_MatrixIndex(tuple, tupdesc, info[2], -1); vehicle->capacity_size = 0; vehicle->capacity = column_found(info[3].colNumber) ? @@ -104,27 +107,36 @@ void fetch_vehicles( : NULL; if (is_plain) { - vehicle->time_window_start = get_Duration(tuple, tupdesc, info[5], 0); - vehicle->time_window_end = get_Duration(tuple, tupdesc, info[6], UINT_MAX); + vehicle->tw_open = get_Duration(tuple, tupdesc, info[5], 0); + vehicle->tw_close = get_Duration(tuple, tupdesc, info[6], UINT_MAX); } else { - vehicle->time_window_start = + vehicle->tw_open = (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[5], 0); - vehicle->time_window_end = + vehicle->tw_close = (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[6], UINT_MAX); } - if (vehicle->time_window_start > vehicle->time_window_end) { + if (vehicle->tw_open > vehicle->tw_close) { ereport(ERROR, (errmsg("Invalid time window (%d, %d)", - vehicle->time_window_start, vehicle->time_window_end), + vehicle->tw_open, vehicle->tw_close), errhint("Time window start time %d must be " "less than or equal to time window end time %d", - vehicle->time_window_start, vehicle->time_window_end))); + vehicle->tw_open, vehicle->tw_close))); } vehicle->speed_factor = column_found(info[7].colNumber) ? spi_getFloat8(tuple, tupdesc, info[7]) : 1.0; + + if (vehicle->speed_factor <= 0.0) { + ereport(ERROR, (errmsg("Invalid speed_factor %lf", vehicle->speed_factor), + errhint("Speed factor must be greater than 0"))); + } + + vehicle->max_tasks = column_found(info[8].colNumber) + ? spi_getMaxTasks(tuple, tupdesc, info[8]) + : INT_MAX; // 2147483647 } @@ -159,11 +171,11 @@ void db_get_vehicles( while (moredata == true) { SPI_cursor_fetch(SPIportal, true, tuple_limit); if (total_tuples == 0) { - /* Atleast one out of start_index or end_index must be present */ - info[1].colNumber = SPI_fnumber(SPI_tuptable->tupdesc, "start_index"); - info[2].colNumber = SPI_fnumber(SPI_tuptable->tupdesc, "end_index"); + /* Atleast one out of start_id or end_id must be present */ + info[1].colNumber = SPI_fnumber(SPI_tuptable->tupdesc, "start_id"); + info[2].colNumber = SPI_fnumber(SPI_tuptable->tupdesc, "end_id"); if (!column_found(info[1].colNumber) && !column_found(info[2].colNumber)) { - elog(ERROR, "At least one out of start_index or end_index must be present"); + elog(ERROR, "At least one out of start_id or end_id must be present"); } pgr_fetch_column_info(info, column_count); } @@ -221,7 +233,7 @@ get_vroom_vehicles( Vroom_vehicle_t **rows, size_t *total_rows, bool is_plain) { - int kColumnCount = 8; + int kColumnCount = 9; Column_info_t info[kColumnCount]; for (int i = 0; i < kColumnCount; ++i) { @@ -232,19 +244,21 @@ get_vroom_vehicles( } info[0].name = "id"; - info[1].name = "start_index"; - info[2].name = "end_index"; + info[1].name = "start_id"; + info[2].name = "end_id"; info[3].name = "capacity"; info[4].name = "skills"; info[5].name = "tw_open"; info[6].name = "tw_close"; info[7].name = "speed_factor"; + info[8].name = "max_tasks"; info[3].eType = ANY_INTEGER_ARRAY; // capacity info[4].eType = INTEGER_ARRAY; // skills info[5].eType = INTEGER; // tw_open info[6].eType = INTEGER; // tw_close info[7].eType = ANY_NUMERICAL; // speed_factor + info[8].eType = INTEGER; // max_tasks if (!is_plain) { info[5].eType = TIMESTAMP; // tw_open @@ -253,7 +267,7 @@ get_vroom_vehicles( /** * id is mandatory. - * At least one out of start_index or end_index must be present, but that is checked later. + * At least one out of start_id or end_id must be present, but that is checked later. */ info[0].strict = true; diff --git a/src/cpp_common/base_matrix.cpp b/src/cpp_common/base_matrix.cpp index fd2ae1d70..a9fe367cd 100644 --- a/src/cpp_common/base_matrix.cpp +++ b/src/cpp_common/base_matrix.cpp @@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/identifiers.hpp" #include "cpp_common/pgr_assert.h" #include "c_types/matrix_cell_t.h" +#include "c_types/vroom/vroom_matrix_t.h" namespace vrprouting { @@ -260,8 +261,8 @@ Base_Matrix::Base_Matrix( * @post costs[from_vid, to_vid] = 0 when from_vid = to_vid * */ -Base_Matrix::Base_Matrix(Matrix_cell_t *data_costs, size_t size_matrix, - const Identifiers &location_ids) { +Base_Matrix::Base_Matrix(Vroom_matrix_t *matrix_rows, size_t total_matrix_rows, + const Identifiers &location_ids, double scaling_factor) { /* * Sets the selected nodes identifiers */ @@ -277,31 +278,41 @@ Base_Matrix::Base_Matrix(Matrix_cell_t *data_costs, size_t size_matrix, * Set initial values to infinity */ (std::numeric_limits::max)())); + m_cost_matrix.resize( + m_ids.size(), + std::vector(m_ids.size(), (std::numeric_limits::max)())); Identifiers inserted; /* * Cycle the matrix data */ - for (size_t i = 0; i < size_matrix; ++i) { - auto data = data_costs[i]; + for (size_t i = 0; i < total_matrix_rows; ++i) { + auto cell = matrix_rows[i]; /* * skip if row is not from selected nodes */ - if (!(has_id(data.from_vid) && has_id(data.to_vid))) continue; + if (!(has_id(cell.start_id) && has_id(cell.end_id))) continue; /* - * Save the information + * Save the information. Scale the time matrix according to scaling_factor */ - m_time_matrix[get_index(data.from_vid)][get_index(data.to_vid)] = - static_cast(data.cost); + m_time_matrix[get_index(cell.start_id)][get_index(cell.end_id)] = + static_cast(std::round(cell.duration / scaling_factor)); + m_cost_matrix[get_index(cell.start_id)][get_index(cell.end_id)] = + static_cast(cell.cost); /* * If the opposite direction is infinity insert the same cost */ - if (m_time_matrix[get_index(data.to_vid)][get_index(data.from_vid)] == + if (m_time_matrix[get_index(cell.end_id)][get_index(cell.start_id)] == (std::numeric_limits::max)()) { - m_time_matrix[get_index(data.to_vid)][get_index(data.from_vid)] = - m_time_matrix[get_index(data.from_vid)][get_index(data.to_vid)]; + m_time_matrix[get_index(cell.end_id)][get_index(cell.start_id)] = + m_time_matrix[get_index(cell.start_id)][get_index(cell.end_id)]; + } + if (m_cost_matrix[get_index(cell.end_id)][get_index(cell.start_id)] == + (std::numeric_limits::max)()) { + m_cost_matrix[get_index(cell.end_id)][get_index(cell.start_id)] = + m_cost_matrix[get_index(cell.start_id)][get_index(cell.end_id)]; } } @@ -310,6 +321,7 @@ Base_Matrix::Base_Matrix(Matrix_cell_t *data_costs, size_t size_matrix, */ for (size_t i = 0; i < m_time_matrix.size(); ++i) { m_time_matrix[i][i] = 0; + m_cost_matrix[i][i] = 0; } } @@ -343,17 +355,34 @@ Base_Matrix::Base_Matrix(const std::map, Id> & } /** - * @brief Get VROOM matrix from vrprouting Base Matrix + * @brief Get VROOM duration matrix from vrprouting Base Matrix + * + * @return vroom::Matrix The vroom cost matrix + */ +vroom::Matrix +Base_Matrix::get_vroom_duration_matrix() const { + size_t matrix_size = m_ids.size(); + vroom::Matrix vroom_matrix(matrix_size); + for (size_t i = 0; i < matrix_size; i++) { + for (size_t j = 0; j < matrix_size; j++) { + vroom_matrix[i][j] = static_cast(m_time_matrix[i][j]); + } + } + return vroom_matrix; +} + +/** + * @brief Get VROOM cost matrix from vrprouting Base Matrix * * @return vroom::Matrix The vroom cost matrix */ vroom::Matrix -Base_Matrix::get_vroom_matrix() const { +Base_Matrix::get_vroom_cost_matrix() const { size_t matrix_size = m_ids.size(); vroom::Matrix vroom_matrix(matrix_size); for (size_t i = 0; i < matrix_size; i++) { for (size_t j = 0; j < matrix_size; j++) { - vroom_matrix[i][j] = static_cast(m_time_matrix[i][j]); + vroom_matrix[i][j] = static_cast(m_cost_matrix[i][j]); } } return vroom_matrix; diff --git a/src/vroom/vroom.c b/src/vroom/vroom.c index 0d2723609..a1adef61c 100644 --- a/src/vroom/vroom.c +++ b/src/vroom/vroom.c @@ -51,13 +51,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/vroom/vroom_job_t.h" #include "c_types/vroom/vroom_shipment_t.h" #include "c_types/vroom/vroom_vehicle_t.h" +#include "c_types/vroom/vroom_matrix_t.h" #include "c_common/vroom/jobs_input.h" #include "c_common/vroom/breaks_input.h" #include "c_common/vroom/time_windows_input.h" #include "c_common/vroom/shipments_input.h" #include "c_common/vroom/vehicles_input.h" -#include "c_common/matrixRows_input.h" +#include "c_common/vroom/matrix_input.h" #include "drivers/vroom/vroom_driver.h" @@ -80,6 +81,8 @@ PG_FUNCTION_INFO_V1(_vrp_vroom); * @param breaks_sql SQL query describing the driver breaks. * @param breaks_tws_sql SQL query describing the time windows for break start. * @param matrix_sql SQL query describing the cells of the cost matrix + * @param exploration_level Exploration level to use while solving. + * @param timeout Timeout value to stop the solving process. * @param fn Value denoting the function used. * @param is_plain Value denoting whether the plain/timestamp function is used. * @param result_tuples the rows in the result @@ -98,11 +101,15 @@ process( char *breaks_sql, char *breaks_tws_sql, char *matrix_sql, + + int32_t exploration_level, + int32_t timeout, int16_t fn, bool is_plain, Vroom_rt **result_tuples, size_t *result_count) { + clock_t start_loading = clock(); pgr_SPI_connect(); (*result_tuples) = NULL; @@ -177,11 +184,11 @@ process( is_plain); } - Matrix_cell_t *matrix_cells_arr = NULL; - size_t total_cells = 0; - get_matrixRows_vroom_plain(matrix_sql, &matrix_cells_arr, &total_cells); + Vroom_matrix_t *matrix_rows = NULL; + size_t total_matrix_rows = 0; + get_vroom_matrix(matrix_sql, &matrix_rows, &total_matrix_rows, is_plain); - if (total_cells == 0) { + if (total_matrix_rows == 0) { ereport(WARNING, (errmsg("Insufficient data found on Matrix SQL query."), errhint("%s", matrix_sql))); (*result_count) = 0; @@ -195,6 +202,8 @@ process( char *notice_msg = NULL; char *err_msg = NULL; + int32_t loading_time = (int)((clock() - start_loading) / CLOCKS_PER_SEC) * 1000; + do_vrp_vroom( jobs, total_jobs, jobs_tws, total_jobs_tws, @@ -203,7 +212,11 @@ process( vehicles, total_vehicles, breaks, total_breaks, breaks_tws, total_breaks_tws, - matrix_cells_arr, total_cells, + matrix_rows, total_matrix_rows, + + exploration_level, + timeout, + loading_time, result_tuples, result_count, @@ -229,7 +242,7 @@ process( if (jobs) pfree(jobs); if (shipments) pfree(shipments); if (vehicles) pfree(vehicles); - if (matrix_cells_arr) pfree(matrix_cells_arr); + if (matrix_rows) pfree(matrix_rows); pgr_SPI_finish(); } @@ -264,7 +277,10 @@ PGDLLEXPORT Datum _vrp_vroom(PG_FUNCTION_ARGS) { * breaks_sql TEXT, * breaks_time_windows_sql TEXT, * matrix_sql TEXT, - * fn SMALLINT + * exploration_level INTEGER default 5, + * timeout INTEGER default -1, + * fn SMALLINT, + * is_plain BOOLEAN * ); * **********************************************************************/ @@ -278,8 +294,10 @@ PGDLLEXPORT Datum _vrp_vroom(PG_FUNCTION_ARGS) { } } - int16_t fn = PG_GETARG_INT16(8); - bool is_plain = PG_GETARG_BOOL(9); + int32_t exploration_level = PG_GETARG_INT32(8); + int32_t timeout = PG_GETARG_INT32(9); + int16_t fn = PG_GETARG_INT16(10); + bool is_plain = PG_GETARG_BOOL(11); // Verify that both jobs_sql and shipments_sql are not NULL if (args[0] == NULL && args[2] == NULL) { @@ -309,6 +327,8 @@ PGDLLEXPORT Datum _vrp_vroom(PG_FUNCTION_ARGS) { args[5], args[6], args[7], + exploration_level, + timeout, fn, is_plain, &result_tuples, diff --git a/src/vroom/vroom_driver.cpp b/src/vroom/vroom_driver.cpp index de43d1a3d..a44e9739e 100644 --- a/src/vroom/vroom_driver.cpp +++ b/src/vroom/vroom_driver.cpp @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include #include "c_common/pgr_alloc.hpp" #include "cpp_common/pgr_assert.h" @@ -54,19 +55,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * function `vrp_vroom` which calls the main function defined in the * C++ Header file. It also does exception handling. * - * @param jobs_sql SQL query describing the jobs - * @param jobs_tw_sql SQL query describing the time window for jobs - * @param shipments_sql SQL query describing the shipments - * @param shipments_tw_sql SQL query describing the time windows for shipment - * @param vehicles_sql SQL query describing the vehicles - * @param breaks_sql SQL query describing the driver breaks. - * @param breaks_tws_sql SQL query describing the time windows for break start. - * @param matrix_sql SQL query describing the cells of the cost matrix - * @param result_tuples the rows in the result - * @param result_count the count of rows in the result - * @param log_msg stores the log message - * @param notice_msg stores the notice message - * @param err_msg stores the error message + * @param jobs Pointer to the array of jobs + * @param total_jobs The total number of jobs + * @param jobs_tws Pointer to the array of jobs time windows + * @param total_jobs_tws The total number of jobs time windows + * @param shipments Pointer to the array of shipments + * @param total_shipments The total number of shipments + * @param shipments_tws Pointer to the array of shipments time windows + * @param total_shipments_tws The total number of shipments time windows + * @param vehicles Pointer to the array of vehicles + * @param total_vehicles The total number of total vehicles + * @param breaks Pointer to the array of breaks + * @param total_breaks The total number of total breaks + * @param matrix_rows Pointer to the array of matrix rows + * @param total_matrix_rows The total number of matrix rows + * @param exploration_level Exploration level to use while solving. + * @param timeout Timeout value to stop the solving process (seconds). + * @param loading_timeout Additional time spent in loading the data from SQL Query (seconds). + * @param result_tuples The rows in the result + * @param result_count The count of rows in the result + * @param log_msg Stores the log message + * @param notice_msg Stores the notice message + * @param err_msg Stores the error message * * @returns void */ @@ -79,7 +89,11 @@ do_vrp_vroom( Vroom_vehicle_t *vehicles, size_t total_vehicles, Vroom_break_t *breaks, size_t total_breaks, Vroom_time_window_t *breaks_tws, size_t total_breaks_tws, - Matrix_cell_t *matrix_cells_arr, size_t total_cells, + Vroom_matrix_t *matrix_rows, size_t total_matrix_rows, + + int32_t exploration_level, + int32_t timeout, + int32_t loading_time, Vroom_rt **return_tuples, size_t *return_count, @@ -98,37 +112,68 @@ do_vrp_vroom( pgassert(!(*return_count)); pgassert(jobs || shipments); pgassert(vehicles); - pgassert(matrix_cells_arr); + pgassert(matrix_rows); pgassert(total_jobs || total_shipments); pgassert(total_vehicles); - pgassert(total_cells); + pgassert(total_matrix_rows); + + auto start_time = std::chrono::high_resolution_clock::now(); Identifiers location_ids; for (size_t i = 0; i < total_jobs; ++i) { - location_ids += jobs[i].location_index; + location_ids += jobs[i].location_id; } for (size_t i = 0; i < total_shipments; ++i) { - location_ids += shipments[i].p_location_index; - location_ids += shipments[i].d_location_index; + location_ids += shipments[i].p_location_id; + location_ids += shipments[i].d_location_id; } + double min_speed_factor, max_speed_factor; + min_speed_factor = max_speed_factor = vehicles[0].speed_factor; + for (size_t i = 0; i < total_vehicles; ++i) { - if (vehicles[i].start_index != -1) { - location_ids += vehicles[i].start_index; + min_speed_factor = std::min(min_speed_factor, vehicles[i].speed_factor); + max_speed_factor = std::max(min_speed_factor, vehicles[i].speed_factor); + if (vehicles[i].start_id != -1) { + location_ids += vehicles[i].start_id; } - if (vehicles[i].end_index != -1) { - location_ids += vehicles[i].end_index; + if (vehicles[i].end_id != -1) { + location_ids += vehicles[i].end_id; } } - vrprouting::base::Base_Matrix time_matrix(matrix_cells_arr, total_cells, location_ids); + /* + * Verify that max value of speed factor is not greater + * than 5 times the speed factor of any other vehicle. + */ + if (max_speed_factor > 5 * min_speed_factor) { + (*return_tuples) = NULL; + (*return_count) = 0; + err << "The speed_factor " << max_speed_factor << " is more than five times " + "the speed factor " << min_speed_factor; + *err_msg = pgr_msg(err.str()); + return; + } + + /* + * Scale the vehicles speed factors according to the minimum speed factor + */ + for (size_t i = 0; i < total_vehicles; ++i) { + vehicles[i].speed_factor = std::round(vehicles[i].speed_factor / min_speed_factor); + } + + /* + * Create the matrix. Also, scale the time matrix according to min_speed_factor + */ + vrprouting::base::Base_Matrix matrix(matrix_rows, total_matrix_rows, + location_ids, min_speed_factor); /* * Verify matrix cells preconditions */ - if (!time_matrix.has_no_infinity()) { + if (!matrix.has_no_infinity()) { (*return_tuples) = NULL; (*return_count) = 0; err << "An Infinity value was found on the Matrix. Might be missing information of a node"; @@ -139,7 +184,7 @@ do_vrp_vroom( /* * Verify size of matrix cell lies in the limit */ - if (time_matrix.size() > (std::numeric_limits::max)()) { + if (matrix.size() > (std::numeric_limits::max)()) { (*return_tuples) = NULL; (*return_count) = 0; err << "The size of time matrix exceeds the limit"; @@ -148,7 +193,7 @@ do_vrp_vroom( } vrprouting::Vrp_vroom_problem problem; - problem.add_matrix(time_matrix); + problem.add_matrix(matrix); problem.add_vehicles(vehicles, total_vehicles, breaks, total_breaks, breaks_tws, total_breaks_tws); @@ -157,7 +202,12 @@ do_vrp_vroom( problem.add_shipments(shipments, total_shipments, shipments_tws, total_shipments_tws); - std::vector < Vroom_rt > results = problem.solve(); + auto end_time = std::chrono::high_resolution_clock::now(); + loading_time += static_cast( + std::chrono::duration_cast(end_time - start_time) + .count()); + + std::vector < Vroom_rt > results = problem.solve(exploration_level, timeout, loading_time); auto count = results.size(); if (count == 0) { diff --git a/tools/scripts/test_signatures.sh b/tools/scripts/test_signatures.sh index 25f02a635..e5d0981a8 100755 --- a/tools/scripts/test_signatures.sh +++ b/tools/scripts/test_signatures.sh @@ -20,6 +20,9 @@ do # comparing within same mayors only if [ "$mayor1" != "$mayor2" ]; then continue; fi + # ignoring any signature changes made on v0 + if [ "$mayor1" == 0 ]; then continue; fi + missing+=$(diff "vrprouting--$s1.sig" "vrprouting--$s2.sig" | grep '<') done done diff --git a/tools/testers/homberger_1000_c1_10_1.data.sql b/tools/testers/homberger_1000_c1_10_1.data.sql new file mode 100644 index 000000000..7f73439af --- /dev/null +++ b/tools/testers/homberger_1000_c1_10_1.data.sql @@ -0,0 +1,1089 @@ +DROP SCHEMA IF EXISTS homberger_1000_c1_10_1 CASCADE; +CREATE SCHEMA homberger_1000_c1_10_1; + +SET search_path TO 'homberger_1000_c1_10_1', 'public'; + +CREATE OR REPLACE FUNCTION homberger_1000_c1_10_1.coord_to_id(x INTEGER, y INTEGER) +RETURNS BIGINT +AS $BODY$ +BEGIN + RETURN CONCAT(x, LPAD(y::TEXT, 4, '0'))::BIGINT; +END; +$BODY$ LANGUAGE plpgsql IMMUTABLE STRICT; + + +DROP TABLE IF EXISTS homberger_1000_c1_10_1.jobs; +CREATE TABLE homberger_1000_c1_10_1.jobs ( + id INTEGER NOT NULL PRIMARY KEY, + location_id BIGINT NOT NULL GENERATED ALWAYS AS (coord_to_id(x, y)) STORED, + x INTEGER NOT NULL, + y INTEGER NOT NULL, + delivery INTEGER NOT NULL, + service INTEGER NOT NULL, + tw_open INTEGER NOT NULL, + tw_close INTEGER NOT NULL +); + + +COPY homberger_1000_c1_10_1.jobs +(id, x, y, delivery, service, tw_open, tw_close) FROM stdin; +0 250 250 0 0 0 1824 +1 387 297 10 90 200 270 +2 5 297 10 90 955 1017 +3 355 177 20 90 194 245 +4 78 346 30 90 355 403 +5 286 159 20 90 530 597 +6 322 465 10 90 226 291 +7 393 408 30 90 630 708 +8 89 216 10 90 495 562 +9 76 345 30 90 539 586 +10 410 285 20 90 499 556 +11 472 189 30 90 385 440 +12 270 49 30 90 925 970 +13 219 325 10 90 520 563 +14 437 12 20 90 557 613 +15 418 218 20 90 974 1030 +16 20 488 10 90 754 820 +17 77 347 20 90 436 505 +18 73 346 10 90 726 772 +19 480 455 10 90 1123 1179 +20 129 292 10 90 552 610 +21 337 257 20 90 805 863 +22 237 254 20 90 629 688 +23 131 220 30 90 749 810 +24 417 417 10 90 954 1020 +25 287 143 10 90 748 793 +26 379 80 20 90 737 789 +27 87 285 30 90 709 764 +28 374 489 20 90 269 339 +29 440 247 20 90 717 779 +30 281 137 10 90 370 416 +31 379 196 20 90 665 714 +32 297 102 10 90 214 281 +33 39 76 10 90 328 399 +34 35 306 20 90 369 440 +35 435 68 10 90 259 314 +36 245 251 10 90 60 130 +37 409 88 20 90 655 715 +38 273 55 20 90 196 246 +39 163 340 30 90 468 513 +40 129 223 20 90 274 340 +41 371 200 10 90 843 916 +42 357 26 20 90 1162 1202 +43 470 473 10 90 1221 1270 +44 77 344 10 90 254 319 +45 478 461 10 90 462 529 +46 128 291 10 90 639 706 +47 111 113 10 90 632 694 +48 164 21 20 90 578 639 +49 21 485 30 90 487 540 +50 108 26 10 90 423 491 +51 424 286 10 90 517 571 +52 200 270 20 90 208 260 +53 7 300 30 90 1056 1104 +54 433 31 10 90 285 333 +55 420 295 20 90 976 1044 +56 451 367 20 90 1134 1195 +57 118 157 20 90 403 465 +58 489 101 20 90 1005 1066 +59 200 261 10 90 945 1017 +60 476 483 10 90 657 722 +61 30 302 10 90 572 632 +62 8 300 10 90 1131 1211 +63 275 45 20 90 444 515 +64 238 46 40 90 735 784 +65 152 206 10 90 910 973 +66 99 218 30 90 154 205 +67 393 410 20 90 913 982 +68 480 460 20 90 549 627 +69 337 256 20 90 154 201 +70 389 300 10 90 293 364 +71 90 237 20 90 1229 1284 +72 321 280 30 90 143 194 +73 417 218 10 90 1060 1126 +74 64 108 10 90 473 539 +75 57 432 10 90 973 1033 +76 356 24 20 90 249 323 +77 143 207 30 90 267 326 +78 221 325 10 90 594 673 +79 22 483 30 90 325 389 +80 24 65 10 90 904 976 +81 141 431 30 90 362 423 +82 202 9 10 90 1225 1281 +83 20 48 10 90 1294 1358 +84 457 163 20 90 284 346 +85 470 290 10 90 835 895 +86 268 400 20 90 869 928 +87 337 251 10 90 145 210 +88 366 20 10 90 874 927 +89 72 344 20 90 618 695 +90 149 203 10 90 553 597 +91 55 428 20 90 511 568 +92 189 7 30 90 310 372 +93 397 18 10 90 519 575 +94 481 122 30 90 607 653 +95 20 73 10 90 290 354 +96 54 430 20 90 610 652 +97 74 350 10 90 915 955 +98 202 8 10 90 1134 1190 +99 406 285 20 90 412 456 +100 460 2 20 90 655 720 +101 441 244 10 90 909 955 +102 1 293 10 90 492 554 +103 115 465 10 90 409 465 +104 422 420 20 90 490 545 +105 75 347 10 90 810 872 +106 141 428 20 90 208 266 +107 404 264 20 90 395 462 +108 398 23 10 90 270 334 +109 148 211 20 90 167 233 +110 362 22 20 90 1050 1121 +111 479 127 20 90 412 478 +112 443 246 20 90 536 593 +113 22 37 10 90 833 894 +114 65 100 10 90 763 811 +115 404 447 20 90 250 280 +116 102 264 10 90 148 215 +117 444 271 10 90 633 688 +118 325 466 40 90 670 717 +119 124 219 20 90 571 615 +120 335 243 20 90 428 495 +121 26 42 20 90 455 519 +122 113 106 20 90 198 260 +123 399 450 20 90 971 1056 +124 146 439 10 90 642 707 +125 162 336 20 90 180 247 +126 2 295 30 90 774 828 +127 122 35 10 90 305 376 +128 346 60 10 90 1027 1086 +129 93 213 30 90 409 457 +130 218 316 20 90 73 134 +131 116 156 10 90 495 557 +132 419 422 20 90 575 647 +133 467 141 10 90 574 637 +134 187 491 20 90 771 854 +135 433 25 20 90 903 970 +136 286 137 10 90 459 516 +137 370 82 40 90 450 509 +138 132 290 10 90 818 898 +139 435 11 40 90 362 422 +140 206 261 10 90 1050 1104 +141 428 291 10 90 698 764 +142 95 384 30 90 719 785 +143 205 223 20 90 491 544 +144 463 140 10 90 295 366 +145 343 47 20 90 738 805 +146 435 62 30 90 1156 1218 +147 387 488 20 90 987 1046 +148 121 157 10 90 220 279 +149 182 463 30 90 372 440 +150 92 216 10 90 777 834 +151 370 83 20 90 357 419 +152 444 242 10 90 441 501 +153 90 285 40 90 981 1042 +154 446 64 10 90 600 665 +155 312 264 20 90 131 179 +156 208 11 20 90 1316 1382 +157 442 247 10 90 623 689 +158 140 431 30 90 280 324 +159 118 153 30 90 949 1028 +160 134 428 20 90 935 992 +161 91 235 10 90 1140 1188 +162 406 257 10 90 596 637 +163 377 76 20 90 638 699 +164 474 96 30 90 271 327 +165 346 57 20 90 925 1002 +166 393 301 30 90 482 545 +167 412 214 10 90 165 215 +168 210 398 10 90 592 647 +169 346 150 20 90 948 998 +170 62 453 10 90 515 584 +171 437 61 10 90 1063 1127 +172 87 96 30 90 744 810 +173 367 83 30 90 266 324 +174 91 268 10 90 869 931 +175 459 145 40 90 233 291 +176 63 444 20 90 1084 1146 +177 433 27 20 90 628 694 +178 60 454 10 90 892 952 +179 478 99 10 90 617 675 +180 485 454 10 90 842 890 +181 6 292 10 90 316 360 +182 398 20 20 90 333 394 +183 248 251 20 90 2 63 +184 433 15 20 90 297 344 +185 64 426 10 90 1162 1223 +186 154 207 20 90 1002 1066 +187 481 456 40 90 1028 1091 +188 380 498 10 90 523 582 +189 88 286 10 90 795 859 +190 111 23 10 90 266 326 +191 199 187 20 90 433 490 +192 269 48 20 90 823 889 +193 367 178 20 90 570 620 +194 452 163 30 90 219 263 +195 431 28 20 90 724 783 +196 8 116 20 90 894 957 +197 233 47 20 90 356 415 +198 237 43 20 90 631 702 +199 320 262 10 90 585 656 +200 188 4 20 90 413 455 +201 180 6 10 90 774 839 +202 328 466 30 90 847 906 +203 393 12 10 90 617 671 +204 409 90 20 90 569 617 +205 406 87 10 90 936 999 +206 394 407 20 90 733 789 +207 358 183 20 90 932 1005 +208 186 461 20 90 220 284 +209 38 72 30 90 420 496 +210 323 471 30 90 469 546 +211 224 192 10 90 215 274 +212 278 46 20 90 205 269 +213 272 403 30 90 494 555 +214 232 42 10 90 545 599 +215 18 63 10 90 716 792 +216 58 458 10 90 702 774 +217 416 417 20 90 1057 1099 +218 205 230 30 90 203 263 +219 65 453 30 90 423 490 +220 421 294 10 90 883 953 +221 434 245 10 90 1377 1416 +222 2 116 20 90 526 586 +223 411 421 20 90 862 917 +224 315 260 10 90 223 278 +225 136 288 10 90 1023 1063 +226 173 490 20 90 406 462 +227 90 232 10 90 682 732 +228 402 265 20 90 306 365 +229 361 14 10 90 686 738 +230 348 147 10 90 845 914 +231 385 295 20 90 142 182 +232 394 23 20 90 1271 1326 +233 466 295 20 90 1033 1073 +234 71 103 20 90 1402 1472 +235 125 29 30 90 588 649 +236 25 65 10 90 1005 1057 +237 58 449 30 90 993 1042 +238 246 398 40 90 148 199 +239 423 294 10 90 790 863 +240 59 459 20 90 622 670 +241 348 145 20 90 763 813 +242 477 97 10 90 421 495 +243 307 102 40 90 602 647 +244 169 31 20 90 387 447 +245 381 495 20 90 705 769 +246 95 234 10 90 315 362 +247 22 33 10 90 735 803 +248 435 268 10 90 1100 1154 +249 135 293 30 90 360 430 +250 439 266 10 90 267 293 +251 269 402 20 90 587 648 +252 267 400 10 90 779 836 +253 473 196 10 90 564 642 +254 445 237 10 90 349 402 +255 461 284 10 90 275 340 +256 167 339 10 90 648 710 +257 26 43 10 90 365 427 +258 101 386 20 90 349 415 +259 342 54 20 90 553 616 +260 243 399 10 90 782 837 +261 288 44 20 90 636 711 +262 274 48 10 90 368 405 +263 360 184 10 90 846 906 +264 23 67 30 90 1092 1157 +265 6 296 10 90 863 926 +266 249 258 30 90 910 974 +267 421 415 30 90 297 364 +268 319 468 10 90 289 353 +269 50 438 20 90 724 779 +270 440 61 30 90 971 1032 +271 17 65 20 90 625 699 +272 323 118 20 90 304 367 +273 402 281 20 90 886 924 +274 71 153 20 90 746 816 +275 52 432 20 90 789 843 +276 378 199 10 90 761 804 +277 238 204 20 90 566 634 +278 208 184 20 90 146 192 +279 376 195 10 90 576 616 +280 473 475 10 90 1124 1181 +281 215 395 20 90 865 928 +282 123 222 30 90 376 430 +283 436 241 20 90 1271 1333 +284 70 100 10 90 1119 1191 +285 73 328 20 90 193 270 +286 241 205 30 90 669 717 +287 250 405 20 90 303 370 +288 483 14 10 90 664 732 +289 466 287 10 90 467 525 +290 467 114 10 90 1159 1223 +291 120 159 10 90 306 377 +292 408 84 10 90 745 814 +293 413 217 20 90 230 289 +294 338 142 40 90 204 256 +295 483 457 20 90 735 811 +296 479 169 20 90 774 834 +297 95 224 20 90 1057 1120 +298 122 216 10 90 461 537 +299 477 179 20 90 237 308 +300 406 99 20 90 367 438 +301 44 47 20 90 289 356 +302 487 450 10 90 929 993 +303 172 488 10 90 310 374 +304 460 374 20 90 753 831 +305 279 138 40 90 281 320 +306 338 147 10 90 135 193 +307 395 295 20 90 677 736 +308 195 185 20 90 335 399 +309 463 194 20 90 220 279 +310 30 72 10 90 1379 1434 +311 244 254 20 90 723 787 +312 317 261 20 90 398 473 +313 67 108 10 90 297 346 +314 442 310 20 90 643 698 +315 63 336 20 90 822 861 +316 109 107 20 90 357 416 +317 100 387 10 90 449 498 +318 494 94 10 90 634 692 +319 343 49 10 90 650 710 +320 40 52 40 90 546 591 +321 319 124 20 90 400 465 +322 94 97 20 90 285 334 +323 476 94 20 90 334 396 +324 283 47 10 90 373 420 +325 398 325 30 90 774 843 +326 460 13 20 90 462 532 +327 305 107 20 90 688 753 +328 188 12 30 90 245 309 +329 136 290 20 90 272 332 +330 439 268 10 90 1005 1060 +331 112 467 10 90 505 557 +332 181 469 20 90 468 536 +333 358 18 10 90 485 568 +334 459 10 10 90 566 614 +335 199 268 20 90 284 368 +336 436 237 20 90 186 264 +337 318 280 20 90 319 384 +338 64 99 10 90 853 904 +339 394 333 20 90 492 567 +340 366 93 20 90 936 989 +341 95 391 10 90 909 973 +342 391 425 20 90 842 909 +343 344 146 10 90 496 529 +344 198 12 10 90 582 631 +345 186 472 20 90 564 633 +346 390 408 30 90 450 520 +347 19 43 20 90 1203 1259 +348 307 108 10 90 777 847 +349 59 457 30 90 810 848 +350 49 451 20 90 340 409 +351 125 39 20 90 245 318 +352 61 147 40 90 383 413 +353 317 123 20 90 497 554 +354 392 426 10 90 666 722 +355 237 213 10 90 846 917 +356 71 333 10 90 252 325 +357 304 97 20 90 407 466 +358 196 462 10 90 955 1003 +359 224 191 20 90 312 359 +360 37 51 10 90 633 689 +361 491 25 10 90 957 1010 +362 270 401 20 90 217 268 +363 474 461 30 90 307 379 +364 66 448 10 90 270 345 +365 337 241 20 90 334 403 +366 269 46 20 90 733 794 +367 22 41 10 90 1110 1164 +368 198 271 20 90 380 458 +369 287 43 10 90 555 609 +370 446 63 20 90 697 750 +371 200 229 30 90 301 355 +372 48 72 30 90 711 768 +373 465 142 10 90 401 445 +374 123 155 10 90 1143 1209 +375 16 497 20 90 1038 1123 +376 220 319 30 90 971 1037 +377 484 171 10 90 680 736 +378 55 431 20 90 694 752 +379 428 24 10 90 1105 1140 +380 80 342 10 90 193 275 +381 16 68 20 90 521 617 +382 124 56 20 90 231 285 +383 95 218 20 90 873 927 +384 481 26 30 90 321 374 +385 145 434 20 90 462 514 +386 335 57 30 90 210 261 +387 26 490 10 90 1345 1394 +388 324 127 30 90 143 200 +389 109 114 10 90 829 871 +390 72 148 20 90 265 330 +391 220 392 20 90 970 1015 +392 442 243 10 90 996 1052 +393 69 336 20 90 440 507 +394 131 226 20 90 121 183 +395 150 204 20 90 639 694 +396 423 217 20 90 785 849 +397 419 459 20 90 785 838 +398 285 163 10 90 714 780 +399 203 7 20 90 1033 1108 +400 54 445 10 90 534 593 +401 109 463 30 90 959 1018 +402 355 180 30 90 279 345 +403 13 455 10 90 381 430 +404 165 337 20 90 373 422 +405 314 124 20 90 775 836 +406 9 124 20 90 271 336 +407 3 292 20 90 404 457 +408 16 462 10 90 935 986 +409 189 464 10 90 856 906 +410 288 154 10 90 442 494 +411 90 296 20 90 166 240 +412 138 438 20 90 832 893 +413 13 459 20 90 646 718 +414 461 8 20 90 756 812 +415 96 97 20 90 217 280 +416 68 99 10 90 1040 1085 +417 146 205 10 90 363 417 +418 117 152 20 90 859 935 +419 481 96 20 90 526 577 +420 338 260 20 90 622 678 +421 285 44 10 90 459 522 +422 111 464 10 90 775 837 +423 468 291 30 90 748 798 +424 148 206 20 90 458 506 +425 184 464 10 90 285 344 +426 197 11 10 90 678 719 +427 396 410 10 90 829 880 +428 133 53 20 90 668 720 +429 132 30 20 90 875 926 +430 464 13 20 90 853 906 +431 100 394 10 90 1006 1067 +432 483 22 10 90 476 543 +433 93 235 10 90 951 1012 +434 174 26 10 90 1037 1105 +435 436 264 20 90 186 248 +436 24 492 10 90 1252 1302 +437 406 94 10 90 375 430 +438 234 246 10 90 537 582 +439 315 287 30 90 693 754 +440 408 453 10 90 575 661 +441 128 225 10 90 176 253 +442 226 191 20 90 397 459 +443 391 407 10 90 549 605 +444 198 264 20 90 770 821 +445 179 7 20 90 864 930 +446 425 215 10 90 699 748 +447 483 27 20 90 1322 1384 +448 22 40 30 90 1012 1080 +449 479 176 20 90 296 367 +450 476 102 20 90 797 866 +451 386 405 20 90 206 266 +452 22 38 20 90 929 980 +453 440 241 10 90 1088 1145 +454 182 14 10 90 1062 1116 +455 266 405 20 90 680 745 +456 357 181 20 90 367 441 +457 395 332 10 90 593 648 +458 423 290 10 90 329 389 +459 104 28 20 90 716 748 +460 131 56 10 90 489 533 +461 111 110 20 90 550 590 +462 97 93 20 90 460 530 +463 90 274 20 90 411 458 +464 214 394 10 90 778 834 +465 6 114 10 90 809 855 +466 375 191 30 90 473 531 +467 356 21 20 90 414 452 +468 466 165 30 90 747 805 +469 415 223 20 90 1257 1302 +470 397 20 20 90 433 477 +471 241 403 10 90 686 744 +472 69 334 30 90 348 415 +473 152 210 20 90 105 163 +474 67 335 20 90 629 684 +475 126 30 10 90 495 558 +476 390 423 10 90 290 336 +477 285 162 30 90 625 688 +478 285 158 30 90 340 405 +479 406 96 20 90 280 342 +480 459 374 20 90 848 917 +481 67 109 20 90 388 438 +482 468 475 10 90 313 373 +483 438 31 10 90 348 413 +484 168 24 10 90 770 816 +485 267 394 10 90 962 1027 +486 406 450 20 90 405 464 +487 460 288 10 90 213 265 +488 224 203 20 90 53 90 +489 21 487 10 90 582 629 +490 21 488 10 90 667 725 +491 87 217 10 90 597 644 +492 67 452 30 90 327 402 +493 119 223 10 90 853 906 +494 398 428 10 90 561 634 +495 344 262 20 90 522 585 +496 390 301 10 90 391 450 +497 167 27 30 90 487 536 +498 236 247 20 90 443 492 +499 313 119 30 90 679 742 +500 13 51 10 90 1366 1425 +501 200 13 10 90 397 453 +502 0 120 30 90 431 492 +503 202 4 10 90 950 1004 +504 343 144 10 90 302 349 +505 94 383 10 90 636 687 +506 250 411 30 90 492 554 +507 464 134 20 90 1048 1106 +508 443 237 20 90 248 318 +509 4 114 10 90 712 769 +510 169 336 30 90 838 892 +511 200 178 20 90 240 298 +512 412 453 10 90 674 750 +513 121 151 20 90 1053 1110 +514 403 93 10 90 1131 1181 +515 399 301 30 90 584 634 +516 97 387 10 90 823 869 +517 176 8 10 90 969 1012 +518 62 326 20 90 914 969 +519 151 207 10 90 731 788 +520 299 98 30 90 320 364 +521 334 240 30 90 526 582 +522 92 270 20 90 954 1029 +523 444 269 20 90 544 593 +524 132 223 30 90 837 909 +525 428 25 20 90 1175 1251 +526 413 421 10 90 768 828 +527 382 498 10 90 619 669 +528 391 429 20 90 475 525 +529 398 97 10 90 264 344 +530 192 265 10 90 678 721 +531 438 26 10 90 453 497 +532 44 79 10 90 267 333 +533 137 290 10 90 176 245 +534 446 319 30 90 364 416 +535 175 487 20 90 248 308 +536 26 45 30 90 303 366 +537 147 435 20 90 553 607 +538 111 459 20 90 1152 1195 +539 472 132 10 90 767 826 +540 349 158 20 90 1050 1093 +541 86 268 10 90 689 735 +542 415 216 10 90 319 384 +543 121 218 20 90 191 257 +544 210 185 20 90 76 120 +545 98 215 20 90 218 278 +546 484 174 10 90 496 544 +547 328 458 10 90 944 1006 +548 313 126 10 90 873 923 +549 390 415 20 90 1042 1090 +550 459 17 20 90 1039 1094 +551 481 124 10 90 505 571 +552 386 414 10 90 1109 1162 +553 116 466 20 90 318 373 +554 468 295 10 90 934 987 +555 391 426 10 90 752 818 +556 408 279 20 90 682 747 +557 15 68 10 90 448 508 +558 392 424 10 90 926 1007 +559 88 95 20 90 658 712 +560 116 151 20 90 774 836 +561 240 250 10 90 340 405 +562 123 159 20 90 156 216 +563 89 290 20 90 225 300 +564 39 50 30 90 440 511 +565 359 179 20 90 465 529 +566 338 257 20 90 713 772 +567 92 236 20 90 1041 1104 +568 413 417 10 90 1135 1207 +569 91 101 10 90 844 902 +570 55 449 20 90 278 339 +571 57 425 20 90 260 317 +572 465 287 10 90 556 617 +573 320 280 10 90 221 298 +574 322 468 20 90 575 625 +575 483 458 10 90 656 708 +576 312 267 10 90 862 941 +577 139 291 10 90 118 187 +578 388 408 10 90 361 425 +579 110 459 30 90 1057 1109 +580 459 372 20 90 672 726 +581 204 269 30 90 49 98 +582 407 98 10 90 218 297 +583 335 256 10 90 890 962 +584 471 484 10 90 571 618 +585 339 244 30 90 251 299 +586 89 272 10 90 498 555 +587 488 96 10 90 909 973 +588 316 286 30 90 601 662 +589 235 50 30 90 813 896 +590 316 258 20 90 317 368 +591 425 288 10 90 603 669 +592 213 397 10 90 680 744 +593 113 156 10 90 577 661 +594 199 9 20 90 853 911 +595 463 167 10 90 657 709 +596 129 27 10 90 680 745 +597 248 404 30 90 214 274 +598 405 276 20 90 771 848 +599 400 288 30 90 154 232 +600 61 156 30 90 462 532 +601 393 20 20 90 1190 1222 +602 484 177 20 90 390 463 +603 108 116 30 90 911 973 +604 112 217 20 90 383 443 +605 389 404 10 90 267 331 +606 102 391 20 90 1098 1161 +607 434 26 10 90 538 601 +608 488 26 30 90 1136 1199 +609 477 120 10 90 968 1026 +610 126 220 20 90 659 711 +611 439 310 10 90 198 256 +612 212 319 30 90 227 293 +613 320 283 30 90 421 471 +614 17 459 10 90 1200 1275 +615 236 213 20 90 39 114 +616 68 108 10 90 230 324 +617 390 294 20 90 853 931 +618 275 42 30 90 537 608 +619 423 214 20 90 595 669 +620 460 367 20 90 392 450 +621 272 402 10 90 317 353 +622 478 102 10 90 704 775 +623 400 260 40 90 150 212 +624 181 6 20 90 678 753 +625 470 475 30 90 381 429 +626 245 408 10 90 585 652 +627 93 96 20 90 374 427 +628 218 318 20 90 884 939 +629 441 265 40 90 344 400 +630 21 64 20 90 818 876 +631 356 23 20 90 309 373 +632 267 44 20 90 649 693 +633 277 50 10 90 257 329 +634 182 4 10 90 586 659 +635 26 36 10 90 646 702 +636 384 491 20 90 897 948 +637 418 290 10 90 1172 1221 +638 321 277 10 90 75 140 +639 358 16 30 90 596 641 +640 389 334 20 90 316 373 +641 48 78 20 90 990 1042 +642 24 68 20 90 1282 1337 +643 206 225 10 90 405 446 +644 290 141 30 90 645 709 +645 439 15 20 90 650 706 +646 359 182 20 90 748 821 +647 413 287 10 90 1348 1417 +648 230 49 20 90 201 253 +649 407 280 10 90 595 653 +650 459 295 20 90 1209 1273 +651 468 199 20 90 669 730 +652 101 384 30 90 200 262 +653 170 26 10 90 855 918 +654 197 270 30 90 474 548 +655 415 289 20 90 169 228 +656 203 390 40 90 307 361 +657 443 272 10 90 821 869 +658 210 391 30 90 202 272 +659 363 22 20 90 964 1025 +660 352 176 20 90 126 175 +661 212 223 40 90 758 832 +662 8 120 10 90 1169 1232 +663 244 250 10 90 157 217 +664 18 484 10 90 397 444 +665 379 82 10 90 827 884 +666 84 346 20 90 1095 1157 +667 233 207 10 90 105 167 +668 344 62 10 90 1208 1274 +669 20 489 10 90 856 901 +670 361 181 20 90 662 723 +671 174 494 10 90 498 559 +672 49 76 20 90 899 950 +673 390 325 30 90 883 929 +674 7 118 20 90 988 1047 +675 107 26 10 90 517 579 +676 312 270 30 90 967 1022 +677 399 102 20 90 649 715 +678 109 108 10 90 444 510 +679 115 218 10 90 298 341 +680 88 287 30 90 878 959 +681 54 424 10 90 320 387 +682 125 32 30 90 407 462 +683 199 12 20 90 475 557 +684 457 374 10 90 945 1005 +685 391 413 10 90 1013 1069 +686 304 102 30 90 505 559 +687 391 293 20 90 768 834 +688 66 336 10 90 719 778 +689 132 291 10 90 736 797 +690 18 462 20 90 1015 1090 +691 347 62 10 90 1121 1176 +692 466 142 10 90 492 537 +693 389 17 10 90 993 1049 +694 342 254 10 90 244 301 +695 92 223 10 90 967 1023 +696 404 83 30 90 831 916 +697 290 46 20 90 832 896 +698 95 92 20 90 554 621 +699 200 265 10 90 853 922 +700 435 16 10 90 829 895 +701 25 499 10 90 1154 1206 +702 319 260 20 90 489 566 +703 116 225 20 90 752 820 +704 402 284 30 90 313 367 +705 108 105 20 90 258 329 +706 386 13 10 90 785 878 +707 472 129 10 90 312 383 +708 132 57 20 90 396 443 +709 43 71 40 90 525 581 +710 493 91 30 90 542 599 +711 12 451 20 90 311 359 +712 201 188 10 90 526 581 +713 60 428 20 90 1059 1137 +714 243 248 30 90 243 314 +715 230 197 40 90 588 645 +716 389 11 20 90 707 769 +717 401 281 20 90 968 1024 +718 459 14 20 90 372 439 +719 411 95 30 90 475 521 +720 0 297 10 90 679 737 +721 476 196 30 90 476 544 +722 458 16 20 90 313 369 +723 92 230 20 90 498 549 +724 432 24 20 90 1000 1056 +725 215 317 10 90 140 194 +726 371 192 30 90 190 259 +727 481 20 20 90 572 631 +728 152 207 20 90 824 877 +729 14 459 20 90 559 622 +730 361 17 20 90 777 832 +731 8 497 40 90 959 1006 +732 206 186 10 90 891 955 +733 421 218 10 90 880 939 +734 402 264 20 90 216 273 +735 388 325 10 90 971 1026 +736 35 304 30 90 280 345 +737 321 263 20 90 680 743 +738 444 313 20 90 462 511 +739 188 462 40 90 753 826 +740 400 103 10 90 546 636 +741 418 221 10 90 1150 1223 +742 112 219 20 90 469 541 +743 408 452 10 90 490 564 +744 30 301 10 90 660 726 +745 205 228 10 90 110 173 +746 407 88 10 90 1035 1083 +747 380 489 20 90 1084 1143 +748 395 331 20 90 690 734 +749 133 26 10 90 776 837 +750 21 68 20 90 1189 1243 +751 313 282 20 90 790 847 +752 53 440 10 90 633 684 +753 458 130 20 90 1140 1210 +754 437 15 30 90 739 801 +755 400 286 10 90 217 276 +756 346 144 10 90 661 729 +757 440 244 10 90 809 874 +758 280 162 30 90 158 210 +759 488 173 20 90 583 645 +760 326 118 10 90 213 272 +761 207 400 20 90 489 562 +762 391 18 10 90 1085 1141 +763 37 55 10 90 730 780 +764 204 15 20 90 239 301 +765 173 28 10 90 1134 1191 +766 343 148 20 90 399 441 +767 231 43 10 90 447 513 +768 445 273 20 90 725 781 +769 432 27 10 90 810 878 +770 439 305 30 90 736 797 +771 208 396 20 90 401 462 +772 249 407 10 90 403 455 +773 107 112 30 90 728 787 +774 279 159 20 90 252 301 +775 376 494 30 90 334 396 +776 403 262 30 90 493 547 +777 41 47 20 90 359 406 +778 96 213 30 90 311 369 +779 461 167 10 90 470 531 +780 391 99 20 90 206 268 +781 116 221 30 90 571 627 +782 165 343 10 90 556 613 +783 388 334 20 90 227 280 +784 130 57 40 90 289 365 +785 422 409 10 90 234 290 +786 66 156 10 90 653 718 +787 485 86 20 90 349 413 +788 389 428 20 90 380 435 +789 117 467 10 90 254 307 +790 475 477 20 90 1028 1091 +791 429 27 20 90 1272 1339 +792 339 60 20 90 274 338 +793 381 494 10 90 801 855 +794 218 321 20 90 697 759 +795 64 101 20 90 667 724 +796 343 254 20 90 334 394 +797 478 464 10 90 360 446 +798 423 286 20 90 430 477 +799 198 9 20 90 763 819 +800 225 196 10 90 128 174 +801 374 190 20 90 292 344 +802 462 14 20 90 944 1000 +803 347 54 10 90 836 904 +804 231 195 20 90 497 552 +805 72 96 20 90 1220 1278 +806 489 87 20 90 451 499 +807 443 313 30 90 554 602 +808 233 204 20 90 198 260 +809 477 483 20 90 745 817 +810 459 368 10 90 299 361 +811 95 277 20 90 1057 1121 +812 16 460 20 90 1112 1180 +813 100 266 20 90 207 275 +814 288 53 40 90 925 997 +815 211 386 20 90 141 212 +816 144 439 30 90 736 797 +817 224 314 10 90 1074 1126 +818 79 291 10 90 519 568 +819 95 235 10 90 155 227 +820 7 123 30 90 329 399 +821 91 217 10 90 692 738 +822 105 27 10 90 611 670 +823 101 385 20 90 262 320 +824 238 210 30 90 757 821 +825 439 67 10 90 322 386 +826 435 267 20 90 1188 1247 +827 443 64 30 90 779 854 +828 92 234 10 90 853 926 +829 450 265 10 90 444 498 +830 102 27 20 90 796 852 +831 492 94 10 90 724 787 +832 440 63 20 90 886 934 +833 453 367 20 90 1055 1091 +834 15 69 10 90 359 414 +835 489 17 10 90 764 826 +836 335 255 20 90 85 124 +837 419 418 10 90 394 454 +838 292 41 10 90 733 804 +839 489 27 10 90 1035 1117 +840 96 270 20 90 308 367 +841 461 369 10 90 579 633 +842 105 22 30 90 339 385 +843 479 121 10 90 692 754 +844 207 223 10 90 585 634 +845 17 458 10 90 1297 1360 +846 186 7 20 90 500 555 +847 465 168 10 90 837 902 +848 416 288 20 90 1251 1328 +849 388 418 10 90 217 283 +850 92 233 10 90 768 830 +851 179 492 10 90 678 752 +852 132 55 10 90 573 632 +853 485 24 20 90 387 445 +854 388 331 20 90 160 230 +855 217 323 20 90 424 473 +856 281 164 20 90 91 140 +857 169 340 10 90 737 806 +858 491 20 20 90 853 925 +859 279 42 40 90 262 338 +860 439 243 20 90 1191 1227 +861 391 334 20 90 402 470 +862 96 244 10 90 1332 1380 +863 441 273 20 90 903 972 +864 477 478 20 90 942 993 +865 56 434 20 90 881 940 +866 12 463 20 90 751 800 +867 458 164 20 90 374 439 +868 446 65 20 90 516 566 +869 71 156 10 90 844 904 +870 65 153 30 90 570 614 +871 8 118 20 90 1079 1138 +872 102 29 30 90 887 946 +873 315 265 10 90 774 841 +874 343 62 10 90 1300 1364 +875 384 16 20 90 892 959 +876 67 105 10 90 579 622 +877 478 118 20 90 1058 1121 +878 73 101 20 90 1313 1375 +879 200 14 10 90 311 356 +880 114 225 30 90 664 723 +881 460 293 30 90 1121 1176 +882 51 447 10 90 438 501 +883 418 295 20 90 1063 1140 +884 282 139 20 90 188 227 +885 477 122 10 90 886 924 +886 91 266 10 90 776 840 +887 16 463 20 90 836 904 +888 228 199 10 90 673 746 +889 435 20 20 90 933 980 +890 467 195 10 90 285 344 +891 469 132 10 90 856 923 +892 465 136 30 90 964 1007 +893 246 255 10 90 818 877 +894 49 75 20 90 810 857 +895 66 98 20 90 944 996 +896 166 32 10 90 296 352 +897 326 466 30 90 753 817 +898 202 186 20 90 616 676 +899 467 285 20 90 380 428 +900 290 136 20 90 549 614 +901 341 58 10 90 364 433 +902 121 219 20 90 132 203 +903 107 35 30 90 986 1041 +904 216 319 10 90 321 387 +905 134 288 20 90 923 979 +906 89 270 10 90 590 647 +907 136 52 10 90 759 817 +908 462 167 20 90 566 617 +909 340 54 10 90 461 525 +910 80 286 10 90 601 677 +911 38 301 20 90 768 814 +912 25 307 10 90 480 529 +913 470 139 10 90 668 731 +914 270 400 10 90 151 213 +915 204 187 30 90 803 857 +916 460 171 30 90 937 994 +917 399 106 20 90 925 989 +918 197 267 10 90 582 626 +919 77 350 10 90 997 1058 +920 91 231 30 90 579 652 +921 398 103 30 90 739 807 +922 35 303 20 90 221 262 +923 231 204 20 90 776 834 +924 311 266 10 90 63 126 +925 416 420 20 90 663 746 +926 231 203 20 90 291 352 +927 4 116 10 90 618 678 +928 417 217 30 90 423 465 +929 268 52 10 90 1003 1079 +930 345 144 30 90 568 640 +931 368 85 30 90 202 275 +932 441 65 10 90 422 470 +933 201 270 10 90 108 177 +934 0 293 30 90 591 637 +935 167 24 20 90 668 736 +936 186 464 10 90 662 730 +937 7 292 10 90 246 306 +938 80 290 10 90 420 484 +939 405 455 40 90 883 948 +940 439 312 30 90 257 324 +941 300 108 10 90 150 211 +942 478 121 40 90 788 840 +943 92 232 10 90 401 462 +944 111 463 20 90 875 919 +945 132 294 20 90 454 521 +946 134 285 20 90 1104 1168 +947 316 284 20 90 510 570 +948 56 428 20 90 415 482 +949 232 47 10 90 262 327 +950 466 291 10 90 656 705 +951 341 257 20 90 424 490 +952 420 213 10 90 509 568 +953 116 152 20 90 678 750 +954 163 337 10 90 277 334 +955 440 7 20 90 469 508 +956 208 222 30 90 667 734 +957 485 95 10 90 281 351 +958 97 385 30 90 537 598 +959 462 367 20 90 481 545 +960 455 365 20 90 235 306 +961 492 95 30 90 815 877 +962 405 450 20 90 311 376 +963 371 193 20 90 133 185 +964 234 202 10 90 389 440 +965 404 103 20 90 464 530 +966 24 41 10 90 557 601 +967 67 334 20 90 532 600 +968 207 227 10 90 48 112 +969 277 403 10 90 395 464 +970 15 457 20 90 462 534 +971 217 319 10 90 789 851 +972 111 467 20 90 597 647 +973 378 493 30 90 426 487 +974 112 465 10 90 685 743 +975 173 25 20 90 952 1007 +976 421 292 20 90 245 287 +977 74 146 30 90 204 259 +978 178 491 10 90 591 656 +979 204 185 20 90 707 769 +980 319 470 10 90 383 442 +981 163 331 40 90 118 179 +982 470 125 20 90 253 316 +983 315 121 10 90 590 647 +984 166 34 20 90 231 305 +985 284 140 40 90 115 172 +986 85 288 20 90 329 386 +987 376 190 30 90 382 439 +988 238 203 10 90 483 534 +989 399 104 10 90 834 896 +990 472 481 20 90 477 527 +991 46 74 20 90 612 682 +992 401 255 30 90 685 738 +993 475 480 30 90 837 911 +994 485 27 10 90 1231 1291 +995 476 174 30 90 874 924 +996 330 242 30 90 627 671 +997 332 249 30 90 82 144 +998 375 80 10 90 550 598 +999 94 235 20 90 227 266 +1000 287 144 20 90 827 895 +\. + + +DROP TABLE IF EXISTS homberger_1000_c1_10_1.vehicles; +CREATE TABLE IF NOT EXISTS homberger_1000_c1_10_1.vehicles ( + id BIGINT PRIMARY KEY, + start_id BIGINT NOT NULL, + end_id BIGINT NOT NULL, + capacity BIGINT NOT NULL, + tw_open INTEGER NOT NULL, + tw_close INTEGER NOT NULL +); + +INSERT INTO homberger_1000_c1_10_1.vehicles (id, start_id, end_id, capacity, tw_open, tw_close) +VALUES(generate_series(1, 250), 2500250, 2500250, 200, 0, 1824); + + +DROP TABLE IF EXISTS homberger_1000_c1_10_1.matrix; +CREATE TABLE IF NOT EXISTS homberger_1000_c1_10_1.matrix ( + start_id BIGINT NOT NULL, + end_id BIGINT NOT NULL, + duration INTEGER NOT NULL, + PRIMARY KEY (start_id, end_id) +); + +WITH +the_matrix_info AS ( + SELECT + A.location_id AS start_id, + B.location_id AS end_id, + ROUND(sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)))::INTEGER AS duration + FROM jobs AS A, jobs AS B WHERE A.id != B.id +) +INSERT INTO homberger_1000_c1_10_1.matrix +SELECT start_id, end_id, duration +FROM the_matrix_info; + + +/* +-- To run the query (takes around 01:05 minutes) +SELECT * FROM vrp_vroomJobsPlain( + 'SELECT id, location_id, ARRAY[delivery], service FROM jobs WHERE id > 0', + 'SELECT id, tw_open, tw_close FROM jobs WHERE id > 0', + 'SELECT id, start_id, end_id, ARRAY[capacity], tw_open, tw_close FROM vehicles', + NULL, + NULL, + 'SELECT * FROM matrix' +); +*/ + +/* +-- Modification for non-plain functions +ALTER TABLE jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE jobs ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE jobs ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE matrix ALTER COLUMN duration TYPE INTERVAL USING make_interval(secs => duration); +*/ diff --git a/tools/testers/vroomdata.sql b/tools/testers/vroomdata.sql index bad55e493..9df6238d6 100644 --- a/tools/testers/vroomdata.sql +++ b/tools/testers/vroomdata.sql @@ -14,7 +14,7 @@ DROP TABLE IF EXISTS vroom.matrix; -- JOBS TABLE start CREATE TABLE vroom.jobs ( id BIGSERIAL PRIMARY KEY, - location_index BIGINT, + location_id BIGINT, service INTEGER, delivery BIGINT[], pickup BIGINT[], @@ -23,7 +23,7 @@ CREATE TABLE vroom.jobs ( ); INSERT INTO vroom.jobs ( - id, location_index, service, delivery, pickup, skills, priority) + id, location_id, service, delivery, pickup, skills, priority) VALUES (1, 1, 250, ARRAY[20], ARRAY[20], ARRAY[0], 0), (2, 2, 250, ARRAY[30], ARRAY[30], ARRAY[0], 0), @@ -54,9 +54,9 @@ INSERT INTO vroom.jobs_time_windows ( -- SHIPMENTS TABLE start CREATE TABLE vroom.shipments ( id BIGSERIAL PRIMARY KEY, - p_location_index BIGINT, + p_location_id BIGINT, p_service INTEGER, - d_location_index BIGINT, + d_location_id BIGINT, d_service INTEGER, amount BIGINT[], skills INTEGER[], @@ -64,7 +64,7 @@ CREATE TABLE vroom.shipments ( ); INSERT INTO vroom.shipments ( - id, p_location_index, p_service, d_location_index, d_service, + id, p_location_id, p_service, d_location_id, d_service, amount, skills, priority) VALUES (1, 3, 2250, 5, 2250, ARRAY[10], ARRAY[0], 0), @@ -102,23 +102,24 @@ INSERT INTO vroom.shipments_time_windows ( -- VEHICLES TABLE start CREATE TABLE vroom.vehicles ( id BIGSERIAL PRIMARY KEY, - start_index BIGINT, - end_index BIGINT, + start_id BIGINT, + end_id BIGINT, capacity BIGINT[], skills INTEGER[], tw_open INTEGER, tw_close INTEGER, - speed_factor FLOAT + speed_factor FLOAT, + max_tasks INTEGER ); INSERT INTO vroom.vehicles ( - id, start_index, end_index, capacity, skills, - tw_open, tw_close, speed_factor) + id, start_id, end_id, capacity, skills, + tw_open, tw_close, speed_factor, max_tasks) VALUES -(1, 1, 1, ARRAY[200], ARRAY[0], 0, 30900, 1.0), -(2, 1, 3, ARRAY[200], ARRAY[0], 100, 30900, 1.0), -(3, 1, 1, ARRAY[200], ARRAY[0], 0, 30900, 1.0), -(4, 3, 3, ARRAY[200], ARRAY[0], 0, 30900, 1.0); +(1, 1, 1, ARRAY[200], ARRAY[0], 0, 30900, 1.0, 20), +(2, 1, 3, ARRAY[200], ARRAY[0], 100, 30900, 1.0, 20), +(3, 1, 1, ARRAY[200], ARRAY[0], 0, 30900, 1.0, 20), +(4, 3, 3, ARRAY[200], ARRAY[0], 0, 30900, 1.0, 20); -- VEHICLES TABLE end @@ -158,13 +159,14 @@ INSERT INTO vroom.breaks_time_windows ( -- MATRIX TABLE start CREATE TABLE vroom.matrix ( - start_vid BIGINT, - end_vid BIGINT, - agg_cost INTEGER + start_id BIGINT, + end_id BIGINT, + duration INTEGER, + cost INTEGER ); INSERT INTO vroom.matrix ( - start_vid, end_vid, agg_cost) + start_id, end_id, duration) VALUES (1, 1, 0), (1, 2, 50), (1, 3, 90), (1, 4, 75), (1, 5, 106), (1, 6, 127), (2, 1, 50), (2, 2, 0), (2, 3, 125), (2, 4, 90), (2, 5, 145), (2, 6, 127), @@ -172,4 +174,6 @@ INSERT INTO vroom.matrix ( (4, 1, 75), (4, 2, 90), (4, 3, 50), (4, 4, 0), (4, 5, 75), (4, 6, 55), (5, 1, 106), (5, 2, 145), (5, 3, 25), (5, 4, 75), (5, 5, 0), (5, 6, 111), (6, 1, 127), (6, 2, 127), (6, 3, 90), (6, 4, 55), (6, 5, 111), (6, 6, 0); + +UPDATE vroom.matrix SET cost = duration; -- MATRIX TABLE end