From 3074d5d3de7e7befe0174223fcb2a2eb14e67749 Mon Sep 17 00:00:00 2001 From: gregor Date: Tue, 28 Nov 2017 17:48:56 +0100 Subject: [PATCH 0001/1340] initial commit based on matsim-example-project pom and readme.md adjusted for this project --- .gitignore | 21 +++ .gitlab-ci.yml | 6 + .travis.yml | 1 + LICENSE | 340 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 3 + pom.xml | 101 +++++++++++++++ 6 files changed, 472 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..0615962b865 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +/.settings/ +/.project +/.classpath +/target/ +/output/ +/bin/ + +/.idea/ +*.iml \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000000..9cfa2e409c7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,6 @@ +image: maven:3-jdk-7 + +build: + script: "mvn install -B --fail-at-end -B -Dmaven.test.redirectTestOutputToFile -Dmatsim.preferLocalDtds=true" + +# see http://stackoverflow.com/questions/33430487/how-to-use-gitlab-ci-to-build-a-java-maven-project diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..dff5f3a5d02 --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: java diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000000..8cdb8451d9b --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + 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. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + diff --git a/README.md b/README.md new file mode 100644 index 00000000000..b67be721fc6 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# freight-project + +Repository to store private files. Public source code should be put into the freight contribution on github. diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000000..456e88011ab --- /dev/null +++ b/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + org.matsim.projects + freight-project + 0.0.1-SNAPSHOT + + Freight project + Freight project + + + + + matsim + https://dl.bintray.com/matsim/matsim + + + + ojo-snapshots + http://oss.jfrog.org/libs-snapshot + + + + + + + org.matsim + matsim + 0.10.0-SNAPSHOT + + + org.matsim.contrib + freight + 0.10.0-SNAPSHOT + + + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + false + false + UTF-8 + + true + 128m + 512m + + 4000 + 100 + + + + + org.apache.maven.plugins + maven-eclipse-plugin + + true + true + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + org.matsim.gui.MATSimGUI + + + + + + make-assembly + package + + single + + + + + + + From 1baa0343a39c6f946b9fd0328b65565f4160214f Mon Sep 17 00:00:00 2001 From: Gregor Leich Date: Tue, 28 Nov 2017 17:58:16 +0100 Subject: [PATCH 0002/1340] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b67be721fc6..681bcaf260e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # freight-project -Repository to store private files. Public source code should be put into the freight contribution on github. +Repository to store private files. Public source code should be put into the freight contribution on github: +https://github.com/matsim-org/matsim/tree/master/contribs/freight From ce02fb3a76dea76d039e1c88d33c13bda923af66 Mon Sep 17 00:00:00 2001 From: Gregor Leich Date: Tue, 28 Nov 2017 17:59:30 +0100 Subject: [PATCH 0003/1340] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 681bcaf260e..7a68b77ca5b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# freight-project +# freight project Repository to store private files. Public source code should be put into the freight contribution on github: https://github.com/matsim-org/matsim/tree/master/contribs/freight From b3a7946e3c7d163c6f4b5654256da5b38cba74ed Mon Sep 17 00:00:00 2001 From: Gregor Leich Date: Wed, 29 Nov 2017 10:47:23 +0100 Subject: [PATCH 0004/1340] Update pom.xml to use new artifact id freight-dfg17 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 456e88011ab..a5349d2d8aa 100644 --- a/pom.xml +++ b/pom.xml @@ -3,11 +3,11 @@ 4.0.0 org.matsim.projects - freight-project + freight-dfg17 0.0.1-SNAPSHOT - Freight project - Freight project + freight-dfg17 + freight-dfg17 internal data not to be put on public github matsim/freight-contrib repository From 8128ed5596a54bbca6d1a99ef09d01c5ae15f02a Mon Sep 17 00:00:00 2001 From: Gregor Leich Date: Wed, 29 Nov 2017 10:50:14 +0100 Subject: [PATCH 0005/1340] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a68b77ca5b..dc6422d0e14 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# freight project +# freight-dfg17 project Repository to store private files. Public source code should be put into the freight contribution on github: https://github.com/matsim-org/matsim/tree/master/contribs/freight From 619aee1e4d447b24555e9c1eaa3cc1e44188ae49 Mon Sep 17 00:00:00 2001 From: gregor Date: Wed, 29 Nov 2017 12:42:02 +0100 Subject: [PATCH 0006/1340] Pom update to use freight-dfg17-mainBranch of matsim repository --- pom.xml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a5349d2d8aa..a834e6e4486 100644 --- a/pom.xml +++ b/pom.xml @@ -20,19 +20,28 @@ ojo-snapshots http://oss.jfrog.org/libs-snapshot + + jitpack.io + https://jitpack.io + - + + + com.github.matsim-org + matsim + freight-dfg17-mainBranch-SNAPSHOT From 307a83bc7a50b7a6ef03da6f0af70f080a72a6d6 Mon Sep 17 00:00:00 2001 From: Gregor Leich Date: Wed, 29 Nov 2017 14:22:34 +0100 Subject: [PATCH 0007/1340] git-fat setup and test .png file --- .gitattributes | 3 +++ .gitfat | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitfat diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..533d55da448 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.png filter=fat -crlf +*.jpg filter=fat -crlf +*.gz filter=fat -crlf diff --git a/.gitfat b/.gitfat new file mode 100644 index 00000000000..91ea79ea052 --- /dev/null +++ b/.gitfat @@ -0,0 +1,2 @@ +[rsync] +remote = fatp22u5ibow@cnode00.vsp.tu-berlin.de:/srv/vsp-gitfat From ec0816f615cd48b7ce5220cf510436aebb95dddb Mon Sep 17 00:00:00 2001 From: matt_ti Date: Mon, 12 Feb 2018 14:10:45 +0100 Subject: [PATCH 0008/1340] First base for discussion of the LSP agent --- test/adapterTests/CollectionAdapterTest.java | 133 +++++++ .../adapterTests/DistributionAdapterTest.java | 136 +++++++ test/adapterTests/FirstReloadAdapterTest.java | 56 +++ test/adapterTests/MainRunAdapterTest.java | 137 +++++++ .../adapterTests/SecondReloadAdapterTest.java | 57 +++ test/cascadingInfoTest/AverageTimeInfo.java | 43 +++ .../AverageTimeInfoFunction.java | 25 ++ .../AverageTimeInfoFunctionValue.java | 28 ++ .../cascadingInfoTest/AverageTimeTracker.java | 56 +++ test/cascadingInfoTest/CascadingInfoTest.java | 212 +++++++++++ test/cascadingInfoTest/TimeSpanHandler.java | 56 +++ .../CollectionLSPCreationTest.java | 132 +++++++ .../CompleteLSPCreationTest.java | 270 +++++++++++++ .../CollectionLSPMobsimTest.java | 204 ++++++++++ .../lspMobsimTests/CompleteLSPMobsimTest.java | 356 ++++++++++++++++++ .../FirstReloadLSPMobsimTest.java | 237 ++++++++++++ test/lspMobsimTests/MainRunLSPMobsimTest.java | 280 ++++++++++++++ .../MainRunOnlyLSPMobsimTest.java | 220 +++++++++++ .../SecondReloadLSPMobsimTest.java | 310 +++++++++++++++ test/lspPlanTests/CollectionLSPPlanTest.java | 105 ++++++ test/lspPlanTests/CompleteLSPPlanTest.java | 236 ++++++++++++ .../CollectionLSPReplanningTest.java | 200 ++++++++++ .../GenericStrategyManagerFactoryImpl.java | 21 ++ test/lspReplanningTests/TomorrowAssigner.java | 37 ++ ...morrowShipmentAssignerStrategyFactory.java | 57 +++ .../CollectionLSPSchedulingTest.java | 233 ++++++++++++ .../CompleteLSPSchedulingTest.java | 324 ++++++++++++++++ .../FirstReloadLSPSchedulingTest.java | 215 +++++++++++ .../MainRunLSPSchedulingTest.java | 256 +++++++++++++ .../SecondReloadLSPSchedulingTest.java | 280 ++++++++++++++ .../CollectionLSPScoringTest.java | 201 ++++++++++ .../TrinkgeldEventHandler.java | 32 ++ test/lspScoringTests/TrinkgeldInfo.java | 41 ++ .../TrinkgeldInfoFunction.java | 23 ++ .../TrinkgeldInfoFunctionValue.java | 35 ++ test/lspScoringTests/TrinkgeldScorer.java | 41 ++ .../TrinkgeldSimulationTracker.java | 50 +++ .../CollectionLSPShipmentAssigmentTest.java | 174 +++++++++ .../CompleteLSPShipmentAssignerTest.java | 322 ++++++++++++++++ .../collectionShipmentBuilderTest.java | 100 +++++ .../completeShipmentBuilderTest.java | 115 ++++++ .../distributionShipmentBuilderTest.java | 103 +++++ .../CollectionElementTest.java | 103 +++++ .../DistributionElementTest.java | 104 +++++ .../FirstReloadElementTest.java | 61 +++ .../MainRunElementTest.java | 106 ++++++ .../SecondReloadElementTest.java | 60 +++ .../solutionTests/CollectionSolutionTest.java | 117 ++++++ test/solutionTests/CompleteSolutionTest.java | 265 +++++++++++++ 49 files changed, 6965 insertions(+) create mode 100644 test/adapterTests/CollectionAdapterTest.java create mode 100644 test/adapterTests/DistributionAdapterTest.java create mode 100644 test/adapterTests/FirstReloadAdapterTest.java create mode 100644 test/adapterTests/MainRunAdapterTest.java create mode 100644 test/adapterTests/SecondReloadAdapterTest.java create mode 100644 test/cascadingInfoTest/AverageTimeInfo.java create mode 100644 test/cascadingInfoTest/AverageTimeInfoFunction.java create mode 100644 test/cascadingInfoTest/AverageTimeInfoFunctionValue.java create mode 100644 test/cascadingInfoTest/AverageTimeTracker.java create mode 100644 test/cascadingInfoTest/CascadingInfoTest.java create mode 100644 test/cascadingInfoTest/TimeSpanHandler.java create mode 100644 test/lspCreationTests/CollectionLSPCreationTest.java create mode 100644 test/lspCreationTests/CompleteLSPCreationTest.java create mode 100644 test/lspMobsimTests/CollectionLSPMobsimTest.java create mode 100644 test/lspMobsimTests/CompleteLSPMobsimTest.java create mode 100644 test/lspMobsimTests/FirstReloadLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MainRunLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java create mode 100644 test/lspMobsimTests/SecondReloadLSPMobsimTest.java create mode 100644 test/lspPlanTests/CollectionLSPPlanTest.java create mode 100644 test/lspPlanTests/CompleteLSPPlanTest.java create mode 100644 test/lspReplanningTests/CollectionLSPReplanningTest.java create mode 100644 test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java create mode 100644 test/lspReplanningTests/TomorrowAssigner.java create mode 100644 test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java create mode 100644 test/lspSchedulingTests/CollectionLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/CompleteLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/MainRunLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java create mode 100644 test/lspScoringTests/CollectionLSPScoringTest.java create mode 100644 test/lspScoringTests/TrinkgeldEventHandler.java create mode 100644 test/lspScoringTests/TrinkgeldInfo.java create mode 100644 test/lspScoringTests/TrinkgeldInfoFunction.java create mode 100644 test/lspScoringTests/TrinkgeldInfoFunctionValue.java create mode 100644 test/lspScoringTests/TrinkgeldScorer.java create mode 100644 test/lspScoringTests/TrinkgeldSimulationTracker.java create mode 100644 test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java create mode 100644 test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java create mode 100644 test/lspShipmentTest/collectionShipmentBuilderTest.java create mode 100644 test/lspShipmentTest/completeShipmentBuilderTest.java create mode 100644 test/lspShipmentTest/distributionShipmentBuilderTest.java create mode 100644 test/solutionElementTests/CollectionElementTest.java create mode 100644 test/solutionElementTests/DistributionElementTest.java create mode 100644 test/solutionElementTests/FirstReloadElementTest.java create mode 100644 test/solutionElementTests/MainRunElementTest.java create mode 100644 test/solutionElementTests/SecondReloadElementTest.java create mode 100644 test/solutionTests/CollectionSolutionTest.java create mode 100644 test/solutionTests/CompleteSolutionTest.java diff --git a/test/adapterTests/CollectionAdapterTest.java b/test/adapterTests/CollectionAdapterTest.java new file mode 100644 index 00000000000..4140875628d --- /dev/null +++ b/test/adapterTests/CollectionAdapterTest.java @@ -0,0 +1,133 @@ +package adapterTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; + + + +public class CollectionAdapterTest { + + //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. + //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. + + private Network network; + private CollectionCarrierScheduler scheduler; + private CarrierVehicleType collectionType; + private CarrierVehicle collectionCarrierVehicle; + private Carrier collectionCarrier; + private CollectionCarrierAdapter collectionAdapter; + private Id collectionLinkId; + private CarrierCapabilities capabilities; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + collectionType = vehicleTypeBuilder.build(); + + collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + collectionCarrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(collectionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + capabilities = capabilitiesBuilder.build(); + collectionCarrier = CarrierImpl.newInstance(carrierId); + collectionCarrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder builder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + builder.setCollectionScheduler(scheduler); + builder.setCarrier(collectionCarrier); + builder.setLocationLinkId(collectionLinkId); + collectionAdapter = builder.build(); + } + + + @Test + public void testCollectionAdapter() { + assertTrue(collectionAdapter.getClientElements() != null); + assertTrue(collectionAdapter.getClientElements().isEmpty()); + assertTrue(CarrierResource.class.isAssignableFrom(collectionAdapter.getClass())); + if(CarrierResource.class.isAssignableFrom(collectionAdapter.getClass())) { + assertTrue(Carrier.class.isAssignableFrom(collectionAdapter.getClassOfResource())); + assertTrue(collectionAdapter.getCarrier() == collectionCarrier); + } + assertTrue(collectionAdapter.getEndLinkId() == collectionLinkId); + assertTrue(collectionAdapter.getStartLinkId() == collectionLinkId); + assertTrue(collectionAdapter.getEventHandlers() != null); + assertTrue(collectionAdapter.getEventHandlers().isEmpty()); + assertTrue(collectionAdapter.getInfos() != null); + assertTrue(collectionAdapter.getInfos().isEmpty()); + assertTrue(collectionAdapter.getStartLinkId() == collectionLinkId); + if(collectionAdapter.getCarrier() == collectionCarrier) { + assertTrue(collectionCarrier.getCarrierCapabilities() == capabilities); + assertTrue(Carrier.class.isAssignableFrom(collectionCarrier.getClass())); + assertTrue(collectionCarrier.getPlans().isEmpty()); + assertTrue(collectionCarrier.getSelectedPlan() == null); + assertTrue(collectionCarrier.getServices().isEmpty()); + assertTrue(collectionCarrier.getShipments().isEmpty()); + if(collectionCarrier.getCarrierCapabilities() == capabilities) { + assertTrue(capabilities.getFleetSize() == FleetSize.INFINITE); + assertFalse(capabilities.getVehicleTypes().isEmpty()); + ArrayList types = new ArrayList(capabilities.getVehicleTypes()); + if(types.size() ==1) { + assertTrue(types.get(0) == collectionType); + assertTrue(collectionType.getCarrierVehicleCapacity() == 10); + assertTrue(collectionType.getVehicleCostInformation().perDistanceUnit == 0.0004); + assertTrue(collectionType.getVehicleCostInformation().perTimeUnit == 0.38); + assertTrue(collectionType.getVehicleCostInformation().fix == 49); + assertTrue(collectionType.getMaximumVelocity() == (50/3.6)); + + } + ArrayList vehicles = new ArrayList(capabilities.getCarrierVehicles()); + if(vehicles.size() == 1) { + assertTrue(vehicles.get(0) == collectionCarrierVehicle); + assertTrue(collectionCarrierVehicle.getVehicleType() == collectionType); + assertTrue(collectionCarrierVehicle.getLocation() == collectionLinkId); + } + } + } + } +} diff --git a/test/adapterTests/DistributionAdapterTest.java b/test/adapterTests/DistributionAdapterTest.java new file mode 100644 index 00000000000..dd89e42d8aa --- /dev/null +++ b/test/adapterTests/DistributionAdapterTest.java @@ -0,0 +1,136 @@ +package adapterTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; + + + +public class DistributionAdapterTest { + + //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. + //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. + + private Network network; + private DistributionCarrierScheduler scheduler; + private CarrierVehicleType distributionType; + private CarrierVehicle distributionCarrierVehicle; + private CarrierCapabilities capabilities; + private Carrier distributionCarrier; + private DistributionCarrierAdapter distributionAdapter; + private Id distributionLinkId; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + scheduler = new DistributionCarrierScheduler(); + Id carrierId = Id.create("DistributionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + distributionType = vehicleTypeBuilder.build(); + + distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + capabilities = capabilitiesBuilder.build(); + distributionCarrier = CarrierImpl.newInstance(carrierId); + distributionCarrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder builder = DistributionCarrierAdapter.Builder.newInstance(adapterId, network); + builder.setDistributionScheduler(scheduler); + builder.setCarrier(distributionCarrier); + builder.setLocationLinkId(distributionLinkId); + distributionAdapter = builder.build(); + } + + + @Test + public void testCollectionAdapter() { + assertTrue(distributionAdapter.getClientElements() != null); + assertTrue(distributionAdapter.getClientElements().isEmpty()); + assertTrue(CarrierResource.class.isAssignableFrom(distributionAdapter.getClass())); + if(CarrierResource.class.isAssignableFrom(distributionAdapter.getClass())) { + assertTrue(Carrier.class.isAssignableFrom(distributionAdapter.getClassOfResource())); + assertTrue(distributionAdapter.getCarrier() == distributionCarrier); + } + assertTrue(distributionAdapter.getEndLinkId() == distributionLinkId); + assertTrue(distributionAdapter.getStartLinkId() == distributionLinkId); + assertTrue(distributionAdapter.getEventHandlers() != null); + assertTrue(distributionAdapter.getEventHandlers().isEmpty()); + assertTrue(distributionAdapter.getInfos() != null); + assertTrue(distributionAdapter.getInfos().isEmpty()); + assertTrue(distributionAdapter.getStartLinkId() == distributionLinkId); + if(distributionAdapter.getCarrier() == distributionCarrier) { + assertTrue(distributionCarrier.getCarrierCapabilities() == capabilities); + assertTrue(Carrier.class.isAssignableFrom(distributionCarrier.getClass())); + assertTrue(distributionCarrier.getPlans().isEmpty()); + assertTrue(distributionCarrier.getSelectedPlan() == null); + assertTrue(distributionCarrier.getServices().isEmpty()); + assertTrue(distributionCarrier.getShipments().isEmpty()); + if(distributionCarrier.getCarrierCapabilities() == capabilities) { + assertTrue(capabilities.getFleetSize() == FleetSize.INFINITE); + assertFalse(capabilities.getVehicleTypes().isEmpty()); + ArrayList types = new ArrayList(capabilities.getVehicleTypes()); + if(types.size() ==1) { + assertTrue(types.get(0) == distributionType); + assertTrue(distributionType.getCarrierVehicleCapacity() == 10); + assertTrue(distributionType.getVehicleCostInformation().perDistanceUnit == 0.0004); + assertTrue(distributionType.getVehicleCostInformation().perTimeUnit == 0.38); + assertTrue(distributionType.getVehicleCostInformation().fix == 49); + assertTrue(distributionType.getMaximumVelocity() == (50/3.6)); + + } + ArrayList vehicles = new ArrayList(capabilities.getCarrierVehicles()); + if(vehicles.size() == 1) { + assertTrue(vehicles.get(0) == distributionCarrierVehicle); + assertTrue(distributionCarrierVehicle.getVehicleType() == distributionType); + assertTrue(distributionCarrierVehicle.getLocation() == distributionLinkId); + } + } + } + } + + +} diff --git a/test/adapterTests/FirstReloadAdapterTest.java b/test/adapterTests/FirstReloadAdapterTest.java new file mode 100644 index 00000000000..c758fa4c29e --- /dev/null +++ b/test/adapterTests/FirstReloadAdapterTest.java @@ -0,0 +1,56 @@ +package adapterTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; + +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; + + +public class FirstReloadAdapterTest { + + private Id reloadingId; + private Id reloadingLinkId; + private ReloadingPoint reloadingPoint; + private ReloadingPointScheduler scheduler; + + @Before + public void initialize(){ + + + ReloadingPointScheduler.Builder schedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + schedulerBuilder.setCapacityNeedFixed(10); + schedulerBuilder.setCapacityNeedLinear(1); + scheduler = schedulerBuilder.build(); + + reloadingId = Id.create("ReloadingPoint1", Resource.class); + reloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder reloadingPointBuilder = ReloadingPoint.Builder.newInstance(reloadingId, reloadingLinkId); + reloadingPointBuilder.setReloadingScheduler(scheduler); + reloadingPoint = reloadingPointBuilder.build(); + } + + @Test + public void reloadingPointTest() { + assertTrue(reloadingPoint.getCapacityNeedFixed() == 10); + assertTrue(reloadingPoint.getCapacityNeedLinear() == 1); + assertFalse(CarrierResource.class.isAssignableFrom(reloadingPoint.getClass())); + assertTrue(reloadingPoint.getClassOfResource() == ReloadingPoint.class); + assertTrue(reloadingPoint.getClientElements() != null); + assertTrue(reloadingPoint.getClientElements().isEmpty()); + assertTrue(reloadingPoint.getEndLinkId() == reloadingLinkId); + assertTrue(reloadingPoint.getStartLinkId() == reloadingLinkId); + assertTrue(reloadingPoint.getEventHandlers() != null); + assertFalse(reloadingPoint.getEventHandlers().isEmpty()); + assertTrue(reloadingPoint.getEventHandlers().size() == 1); + assertTrue(reloadingPoint.getInfos() != null); + assertTrue(reloadingPoint.getInfos().isEmpty()); + } +} diff --git a/test/adapterTests/MainRunAdapterTest.java b/test/adapterTests/MainRunAdapterTest.java new file mode 100644 index 00000000000..398488e9e5d --- /dev/null +++ b/test/adapterTests/MainRunAdapterTest.java @@ -0,0 +1,137 @@ +package adapterTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; + + + +public class MainRunAdapterTest { + + private Network network; + private Id carrierId; + private Id vehicleTypeId; + private CarrierVehicleType mainRunType; + private Id fromLinkId; + private Id toLinkId; + private CarrierVehicle carrierVehicle; + private CarrierCapabilities capabilities; + private Carrier carrier; + private MainRunCarrierScheduler scheduler; + private MainRunCarrierAdapter mainRunAdapter; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + carrierId = Id.create("MainRunCarrier", Carrier.class); + vehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(30); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0008); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(120); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + mainRunType = vehicleTypeBuilder.build(); + + toLinkId = Id.createLinkId("(14 2) (14 3)"); + fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("MainRunVehicle"); + carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, fromLinkId); + carrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(mainRunType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + scheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunBuilder.setMainRunCarrierScheduler(scheduler); + mainRunBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunBuilder.setCarrier(carrier); + mainRunAdapter = mainRunBuilder.build(); + + } + + @Test + public void testMainRunAdapter() { + assertTrue(mainRunAdapter.getClientElements() != null); + assertTrue(mainRunAdapter.getClientElements().isEmpty()); + assertTrue(CarrierResource.class.isAssignableFrom(mainRunAdapter.getClass())); + if(CarrierResource.class.isAssignableFrom(mainRunAdapter.getClass())) { + assertTrue(Carrier.class.isAssignableFrom(mainRunAdapter.getClassOfResource())); + assertTrue(mainRunAdapter.getCarrier() == carrier); + } + assertTrue(mainRunAdapter.getEndLinkId() == toLinkId); + assertTrue(mainRunAdapter.getStartLinkId() == fromLinkId); + assertTrue(mainRunAdapter.getEventHandlers() != null); + assertTrue(mainRunAdapter.getEventHandlers().isEmpty()); + assertTrue(mainRunAdapter.getInfos() != null); + assertTrue(mainRunAdapter.getInfos().isEmpty()); + if(mainRunAdapter.getCarrier() == carrier) { + assertTrue(carrier.getCarrierCapabilities() == capabilities); + assertTrue(Carrier.class.isAssignableFrom(carrier.getClass())); + assertTrue(carrier.getPlans().isEmpty()); + assertTrue(carrier.getSelectedPlan() == null); + assertTrue(carrier.getServices().isEmpty()); + assertTrue(carrier.getShipments().isEmpty()); + if(carrier.getCarrierCapabilities() == capabilities) { + assertTrue(capabilities.getFleetSize() == FleetSize.INFINITE); + assertFalse(capabilities.getVehicleTypes().isEmpty()); + ArrayList types = new ArrayList(capabilities.getVehicleTypes()); + if(types.size() ==1) { + assertTrue(types.get(0) == mainRunType); + assertTrue(mainRunType.getCarrierVehicleCapacity() == 30); + assertTrue(mainRunType.getVehicleCostInformation().perDistanceUnit == 0.0008); + assertTrue(mainRunType.getVehicleCostInformation().perTimeUnit == 0.38); + assertTrue(mainRunType.getVehicleCostInformation().fix == 120); + assertTrue(mainRunType.getMaximumVelocity() == (50/3.6)); + } + ArrayList vehicles = new ArrayList(capabilities.getCarrierVehicles()); + if(vehicles.size() == 1) { + assertTrue(vehicles.get(0) == carrierVehicle); + assertTrue(carrierVehicle.getVehicleType() == mainRunType); + assertTrue(carrierVehicle.getLocation() == fromLinkId); + } + } + } + + + } +} diff --git a/test/adapterTests/SecondReloadAdapterTest.java b/test/adapterTests/SecondReloadAdapterTest.java new file mode 100644 index 00000000000..85c8ea6ffbf --- /dev/null +++ b/test/adapterTests/SecondReloadAdapterTest.java @@ -0,0 +1,57 @@ +package adapterTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; + +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; + + +public class SecondReloadAdapterTest { + + private ReloadingPointScheduler scheduler; + private ReloadingPoint reloadingPoint; + private Id reloadingLinkId; + private Id reloadingId; + + @Before + public void initialize(){ + ReloadingPointScheduler.Builder schedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + schedulerBuilder.setCapacityNeedFixed(10); + schedulerBuilder.setCapacityNeedLinear(1); + scheduler = schedulerBuilder.build(); + + reloadingId = Id.create("ReloadingPoint2", Resource.class); + reloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder reloadingPointBuilder = ReloadingPoint.Builder.newInstance(reloadingId, reloadingLinkId); + reloadingPointBuilder.setReloadingScheduler(scheduler); + reloadingPoint = reloadingPointBuilder.build(); + + } + + @Test + public void reloadingPointTest() { + assertTrue(reloadingPoint.getCapacityNeedFixed() == 10); + assertTrue(reloadingPoint.getCapacityNeedLinear() == 1); + assertFalse(CarrierResource.class.isAssignableFrom(reloadingPoint.getClass())); + assertTrue(reloadingPoint.getClassOfResource() == ReloadingPoint.class); + assertTrue(reloadingPoint.getClientElements() != null); + assertTrue(reloadingPoint.getClientElements().isEmpty()); + assertTrue(reloadingPoint.getEndLinkId() == reloadingLinkId); + assertTrue(reloadingPoint.getStartLinkId() == reloadingLinkId); + assertTrue(reloadingPoint.getEventHandlers() != null); + assertFalse(reloadingPoint.getEventHandlers().isEmpty()); + assertTrue(reloadingPoint.getEventHandlers().size() == 1); + assertTrue(reloadingPoint.getInfos() != null); + assertTrue(reloadingPoint.getInfos().isEmpty()); + } + +} diff --git a/test/cascadingInfoTest/AverageTimeInfo.java b/test/cascadingInfoTest/AverageTimeInfo.java new file mode 100644 index 00000000000..df264828ba1 --- /dev/null +++ b/test/cascadingInfoTest/AverageTimeInfo.java @@ -0,0 +1,43 @@ +package cascadingInfoTest; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; + +public class AverageTimeInfo extends Info{ + + private AverageTimeInfoFunction function; + + public AverageTimeInfo() { + function = new AverageTimeInfoFunction(); + } + + + @Override + public String getName() { + return "averageTime"; + } + + @Override + public InfoFunction getFunction() { + return function; + } + + @Override + public double getFromTime() { + return 0; + } + + @Override + public double getToTime() { + return Double.MAX_VALUE; + } + + @Override + public void update() { + Info preInfo = predecessorInfos.iterator().next(); + AverageTimeInfo avgInfo = (AverageTimeInfo)preInfo; + AverageTimeInfoFunctionValue avgVal = (AverageTimeInfoFunctionValue) avgInfo.getFunction().getValues().iterator().next(); + function.getValues().iterator().next().setValue(avgVal.getValue()); + } + +} diff --git a/test/cascadingInfoTest/AverageTimeInfoFunction.java b/test/cascadingInfoTest/AverageTimeInfoFunction.java new file mode 100644 index 00000000000..ff87b337f59 --- /dev/null +++ b/test/cascadingInfoTest/AverageTimeInfoFunction.java @@ -0,0 +1,25 @@ +package cascadingInfoTest; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; + + + +public class AverageTimeInfoFunction implements InfoFunction{ + + private Collection values; + + public AverageTimeInfoFunction() { + values = new ArrayList(); + values.add(new AverageTimeInfoFunctionValue()); + } + + @Override + public Collection getValues() { + return values; + } + +} diff --git a/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java b/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java new file mode 100644 index 00000000000..40a3d7d98ca --- /dev/null +++ b/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java @@ -0,0 +1,28 @@ +package cascadingInfoTest; + +import lsp.functions.InfoFunctionValue; + +public class AverageTimeInfoFunctionValue implements InfoFunctionValue{ + + private String value; + + @Override + public String getName() { + return "agerageTimeInSeconds"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } +} diff --git a/test/cascadingInfoTest/AverageTimeTracker.java b/test/cascadingInfoTest/AverageTimeTracker.java new file mode 100644 index 00000000000..fd4674a3d41 --- /dev/null +++ b/test/cascadingInfoTest/AverageTimeTracker.java @@ -0,0 +1,56 @@ +package cascadingInfoTest; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import tracking.SimulationTracker; + + + +public class AverageTimeTracker implements SimulationTracker { + + private Collection handlers; + private Collection infos; + private AverageTimeInfo timeInfo; + private TimeSpanHandler handler; + + public AverageTimeTracker() { + handlers = new ArrayList(); + handler = new TimeSpanHandler(); + handlers.add(handler); + infos = new ArrayList(); + timeInfo = new AverageTimeInfo(); + infos.add(timeInfo); + } + + + @Override + public Collection getEventHandlers() { + return handlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + int numberOfStops = handler.getNumberOfStops(); + double totalTransportTime = handler.getTotalTime(); + double averageTransportTime = totalTransportTime/numberOfStops; + AverageTimeInfoFunctionValue value = (AverageTimeInfoFunctionValue) timeInfo.getFunction().getValues().iterator().next(); + value.setValue(Double.toString(averageTransportTime)); + } + + + @Override + public void reset() { + // TODO Auto-generated method stub + + } +} diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java new file mode 100644 index 00000000000..e2720bcfcc8 --- /dev/null +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -0,0 +1,212 @@ +package cascadingInfoTest; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; + + + +public class CascadingInfoTest { + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private LogisticsSolution collectionSolution; + private AverageTimeInfo elementInfo; + private AverageTimeInfo solutionInfo; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + if (collectionLink == null) { + System.exit(1); + } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + collectionAdapter.addSimulationTracker(new AverageTimeTracker()); + + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + elementInfo = new AverageTimeInfo(); + elementInfo.addPredecessorInfo(collectionAdapter.getInfos().iterator().next()); + collectionElement.getInfos().add(elementInfo); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + collectionSolution = collectionSolutionBuilder.build(); + + solutionInfo = new AverageTimeInfo(); + solutionInfo.addPredecessorInfo(collectionElement.getInfos().iterator().next()); + collectionElement.getInfos().add(solutionInfo); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlan collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCascadingInfos() { + assertTrue(elementInfo.getFunction() instanceof AverageTimeInfoFunction); + AverageTimeInfoFunction averageElementFunction = (AverageTimeInfoFunction) elementInfo.getFunction(); + assertTrue(averageElementFunction.getValues().size() == 1); + assertTrue(averageElementFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); + AverageTimeInfoFunctionValue averageElementValue = (AverageTimeInfoFunctionValue) averageElementFunction.getValues().iterator().next(); + assertTrue(Double.parseDouble(averageElementValue.getValue()) > 0); + assertTrue(elementInfo.getFunction() instanceof AverageTimeInfoFunction); + AverageTimeInfoFunction averageSolutionFunction = (AverageTimeInfoFunction) solutionInfo.getFunction(); + assertTrue(averageSolutionFunction.getValues().size() == 1); + assertTrue(averageSolutionFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); + AverageTimeInfoFunctionValue averageSolutionValue = (AverageTimeInfoFunctionValue) averageSolutionFunction.getValues().iterator().next(); + assertTrue(Double.parseDouble(averageSolutionValue.getValue()) > 0); + assertTrue(averageElementValue.getValue() == averageSolutionValue.getValue()); + } + +} diff --git a/test/cascadingInfoTest/TimeSpanHandler.java b/test/cascadingInfoTest/TimeSpanHandler.java new file mode 100644 index 00000000000..07ab8e64e86 --- /dev/null +++ b/test/cascadingInfoTest/TimeSpanHandler.java @@ -0,0 +1,56 @@ +package cascadingInfoTest; + +import java.util.ArrayList; +import java.util.Collection; + +import events.ServiceBeginsEvent; +import events.ServiceBeginsEventHandler; +import events.TourStartEvent; +import events.TourStartEventHandler; + + + +public class TimeSpanHandler implements TourStartEventHandler, ServiceBeginsEventHandler{ + + private int numberOfStops; + private double totalTime; + + private Collection startEvents; + + public TimeSpanHandler() { + startEvents = new ArrayList(); + } + + @Override + public void reset(int iteration) { + totalTime = 0; + numberOfStops = 0; + } + + @Override + public void handleEvent(ServiceBeginsEvent event) { + numberOfStops++; + for(TourStartEvent startEvent : startEvents) { + if(startEvent.getDriverId() == event.getDriverId()) { + double startTime = startEvent.getTime(); + double serviceTime = event.getTime(); + totalTime = totalTime + (serviceTime - startTime); + break; + } + } + } + + @Override + public void handleEvent(TourStartEvent event) { + startEvents.add(event); + } + + public int getNumberOfStops() { + return numberOfStops; + } + + public double getTotalTime() { + return totalTime; + } + +} diff --git a/test/lspCreationTests/CollectionLSPCreationTest.java b/test/lspCreationTests/CollectionLSPCreationTest.java new file mode 100644 index 00000000000..bc252880d1d --- /dev/null +++ b/test/lspCreationTests/CollectionLSPCreationTest.java @@ -0,0 +1,132 @@ +package lspCreationTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; + + + +public class CollectionLSPCreationTest { + + private Network network; + private LogisticsSolution collectionSolution; + private ShipmentAssigner assigner; + private LSPPlan collectionPlan; + private SolutionScheduler simpleScheduler; + private LSP collectionLSP; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + collectionSolution = collectionSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + } + + @Test + public void testCollectionLSPCreation() { + assertTrue(collectionLSP.getPlans() != null); + assertFalse(collectionLSP.getPlans().isEmpty()); + assertTrue(collectionLSP.getResources() != null); + LSPPlan selectedPlan = collectionLSP.getSelectedPlan(); + assertTrue(selectedPlan.getScore() == 0); + assertTrue(selectedPlan.getLsp() == collectionLSP); + assertTrue(selectedPlan.getAssigner() == assigner); + assertTrue(selectedPlan.getSolutions().iterator().next() == collectionSolution); + assertTrue(selectedPlan.getSolutions().iterator().next().getLSP() == collectionLSP); + assertTrue(selectedPlan.getAssigner().getLSP()== collectionLSP); + } + +} diff --git a/test/lspCreationTests/CompleteLSPCreationTest.java b/test/lspCreationTests/CompleteLSPCreationTest.java new file mode 100644 index 00000000000..1c2b27d2ee4 --- /dev/null +++ b/test/lspCreationTests/CompleteLSPCreationTest.java @@ -0,0 +1,270 @@ +package lspCreationTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; + + + +public class CompleteLSPCreationTest { + private Network network; + private LSP completeLSP; + private ShipmentAssigner assigner; + private LogisticsSolution completeSolution; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FiretReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = collectionVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(collectionCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + + assigner = new DeterministicShipmentAssigner(); + LSPPlan collectionPlan = new LSPPlan(assigner); + completeSolution = completeSolutionBuilder.build(); + collectionPlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + } + + @Test + public void testCollectionLSPCreation() { + assertTrue(completeLSP.getPlans() != null); + assertFalse(completeLSP.getPlans().isEmpty()); + assertTrue(completeLSP.getResources() != null); + LSPPlan selectedPlan = completeLSP.getSelectedPlan(); + assertTrue(selectedPlan.getScore() == 0); + assertTrue(selectedPlan.getLsp() == completeLSP); + assertTrue(selectedPlan.getAssigner() == assigner); + assertTrue(selectedPlan.getSolutions().iterator().next() == completeSolution); + assertTrue(selectedPlan.getSolutions().iterator().next().getLSP() == completeLSP); + assertTrue(selectedPlan.getAssigner().getLSP()== completeLSP); + } + +} diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java new file mode 100644 index 00000000000..49cfa988a78 --- /dev/null +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -0,0 +1,204 @@ +package lspMobsimTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class CollectionLSPMobsimTest { + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + if (collectionLink == null) { + System.exit(1); + } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlan collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 2; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPMobsim() { + + + + for(LSPShipment shipment : collectionLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + + } + } + +} diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/test/lspMobsimTests/CompleteLSPMobsimTest.java new file mode 100644 index 00000000000..db22ca0fce8 --- /dev/null +++ b/test/lspMobsimTests/CompleteLSPMobsimTest.java @@ -0,0 +1,356 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class CompleteLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP completeLSP; + private Carrier carrier; + private Resource completeAdapter; + private LogisticsSolutionElement completeElement; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + collectionScheduler.setBufferTime(300); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + ReloadingPointScheduler reloadScheduler = firstReloadingSchedulerBuilder.build(); + reloadScheduler.setBufferTime(300); + firstReloadingPointBuilder.setReloadingScheduler(reloadScheduler); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + mainRunScheduler.setBufferTime(300); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + ReloadingPointScheduler secondScheduler = secondSchedulerBuilder.build(); + secondScheduler.setBufferTime(300); + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + + secondReloadingPointBuilder.setReloadingScheduler(secondScheduler); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(14 2) (14 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 2; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + completeLSP.assignShipmentToLSP(shipment); + } + completeLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(completeLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : completeLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + //assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + + } + } +} + diff --git a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java new file mode 100644 index 00000000000..b18516688b1 --- /dev/null +++ b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -0,0 +1,237 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class FirstReloadLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + @Test + public void testFirstReloadLSPMobsim() { + + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + + } + } +} diff --git a/test/lspMobsimTests/MainRunLSPMobsimTest.java b/test/lspMobsimTests/MainRunLSPMobsimTest.java new file mode 100644 index 00000000000..c50d8fc3d37 --- /dev/null +++ b/test/lspMobsimTests/MainRunLSPMobsimTest.java @@ -0,0 +1,280 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class MainRunLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + + } + } +} diff --git a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java new file mode 100644 index 00000000000..a2dabba34c9 --- /dev/null +++ b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -0,0 +1,220 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class MainRunOnlyLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + + resourcesList.add(mainRunAdapter); + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + + } + } +} diff --git a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java new file mode 100644 index 00000000000..255f3b05e36 --- /dev/null +++ b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java @@ -0,0 +1,310 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScoringModuleImpl; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; + + + +public class SecondReloadLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + + } + } + +} diff --git a/test/lspPlanTests/CollectionLSPPlanTest.java b/test/lspPlanTests/CollectionLSPPlanTest.java new file mode 100644 index 00000000000..2357da3bc75 --- /dev/null +++ b/test/lspPlanTests/CollectionLSPPlanTest.java @@ -0,0 +1,105 @@ +package lspPlanTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.resources.Resource; + +public class CollectionLSPPlanTest { + + private Network network; + private LogisticsSolution collectionSolution; + private ShipmentAssigner assigner; + private LSPPlan collectionPlan; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(adapterBuilder.build()); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + collectionSolution = collectionSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + } + + @Test + public void collectionLSPPlanTest() { + assertTrue(collectionPlan.getAssigner() == assigner); + assertTrue(collectionPlan.getScore() == 0); + assertTrue(collectionPlan.getLsp() == null); + assertTrue(collectionPlan.getSolutions().size() == 1); + } + +} diff --git a/test/lspPlanTests/CompleteLSPPlanTest.java b/test/lspPlanTests/CompleteLSPPlanTest.java new file mode 100644 index 00000000000..00b17895aa9 --- /dev/null +++ b/test/lspPlanTests/CompleteLSPPlanTest.java @@ -0,0 +1,236 @@ +package lspPlanTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.resources.Resource; + +public class CompleteLSPPlanTest { + + private Network network; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private LogisticsSolution completeSolution; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapterBuilder.build()); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + + + Id firstReloadingElementId = Id.create("FiretReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointBuilder.build()); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = collectionVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(collectionCarrier); + + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource( mainRunAdapterBuilder.build()); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointBuilder.build()); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapterBuilder.build()); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + } + + @Test + public void testCompleteLSPPlan() { + assertTrue(completePlan.getAssigner() == assigner); + assertTrue(completePlan.getLsp() == null); + assertTrue(completePlan.getScore() == 0); + assertTrue(completePlan.getSolutions().size() ==1); + } + +} diff --git a/test/lspReplanningTests/CollectionLSPReplanningTest.java b/test/lspReplanningTests/CollectionLSPReplanningTest.java new file mode 100644 index 00000000000..282e682ad73 --- /dev/null +++ b/test/lspReplanningTests/CollectionLSPReplanningTest.java @@ -0,0 +1,200 @@ +package lspReplanningTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.replanning.GenericStrategyManager; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplannerImpl; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScorer; +import scoring.LSPScoringModuleImpl; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; +import lspScoringTests.TrinkgeldEventHandler; +import lspScoringTests.TrinkgeldInfo; +import lspScoringTests.TrinkgeldInfoFunction; +import lspScoringTests.TrinkgeldInfoFunctionValue; +import lspScoringTests.TrinkgeldScorer; +import lspScoringTests.TrinkgeldSimulationTracker; + +public class CollectionLSPReplanningTest { + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + if (collectionLink == null) { + System.exit(1); + } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlan collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 21; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + GenericStrategyManagerFactoryImpl factory = new GenericStrategyManagerFactoryImpl(); + GenericStrategyManager manager = factory.createStrategyManager(collectionLSP); + LSPReplannerImpl replanner = new LSPReplannerImpl(collectionLSP); + replanner.setStrategyManager(manager); + collectionLSP.setReplanner(replanner); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPReplanning(){ + assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() < 20); + } + +} diff --git a/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java b/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java new file mode 100644 index 00000000000..a9d50ac6612 --- /dev/null +++ b/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java @@ -0,0 +1,21 @@ +package lspReplanningTests; + +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.LSP; +import lsp.LSPPlan; +import lsp.ShipmentAssigner; +import replanning.LSPPlanStrategyManagerFactory; + +public class GenericStrategyManagerFactoryImpl implements LSPPlanStrategyManagerFactory { + + @Override + public GenericStrategyManager createStrategyManager(LSP lsp) { + GenericStrategyManager strategyManager = new GenericStrategyManager(); + ShipmentAssigner tomorrowAssigner = new TomorrowAssigner(); + tomorrowAssigner.setLSP(lsp); + strategyManager.addStrategy(new TomorrowShipmentAssignerStrategyFactory(tomorrowAssigner).createStrategy(), null, 1); + return strategyManager; + } + +} diff --git a/test/lspReplanningTests/TomorrowAssigner.java b/test/lspReplanningTests/TomorrowAssigner.java new file mode 100644 index 00000000000..c2acf9971ad --- /dev/null +++ b/test/lspReplanningTests/TomorrowAssigner.java @@ -0,0 +1,37 @@ +package lspReplanningTests; + +import java.util.Random; + +import lsp.LSP; +import lsp.ShipmentAssigner; +import shipment.LSPShipment; + +public class TomorrowAssigner implements ShipmentAssigner{ + + private LSP lsp; + private Random random; + + public TomorrowAssigner() { + this.random = new Random(1); + } + + @Override + public void assignShipment(LSPShipment shipment) { + boolean assignToday = random.nextBoolean(); + if(assignToday) { + lsp.getSelectedPlan().getSolutions().iterator().next().assignShipment(shipment); + } + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + + } + + @Override + public LSP getLSP() { + return lsp; + } + +} diff --git a/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java b/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java new file mode 100644 index 00000000000..9cf07f6ad54 --- /dev/null +++ b/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java @@ -0,0 +1,57 @@ +package lspReplanningTests; + +import java.util.Collection; + +import org.matsim.core.replanning.GenericPlanStrategy; +import org.matsim.core.replanning.GenericPlanStrategyImpl; +import org.matsim.core.replanning.ReplanningContext; +import org.matsim.core.replanning.modules.GenericPlanStrategyModule; +import org.matsim.core.replanning.selectors.BestPlanSelector; + +import lsp.LSP; +import lsp.LSPPlan; +import lsp.ShipmentAssigner; +import shipment.LSPShipment; + +public class TomorrowShipmentAssignerStrategyFactory { + + private ShipmentAssigner assigner; + + public TomorrowShipmentAssignerStrategyFactory(ShipmentAssigner assigner) { + this.assigner = assigner; + } + + public GenericPlanStrategy createStrategy(){ + GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl( new BestPlanSelector()); + + GenericPlanStrategyModule tomorrowModule = new GenericPlanStrategyModule() { + + @Override + public void prepareReplanning(ReplanningContext replanningContext) { + // TODO Auto-generated method stub + + } + + @Override + public void handlePlan(LSPPlan plan) { + plan.setAssigner(assigner); + LSP lsp = assigner.getLSP(); + Collection shipments = lsp.getShipments(); + for(LSPShipment shipment : shipments) { + assigner.assignShipment(shipment); + } + } + + @Override + public void finishReplanning() { + // TODO Auto-generated method stub + + } + + }; + + strategy.addStrategyModule(tomorrowModule); + return strategy; + } + +} diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java new file mode 100644 index 00000000000..b2b02fb0b07 --- /dev/null +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -0,0 +1,233 @@ +package lspSchedulingTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierPlanXmlWriterV2; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.Carriers; +import org.matsim.contrib.freight.carrier.ScheduledTour; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.Tour.Leg; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.CollectionServiceEventHandler; +import usecase.CollectionTourEndEventHandler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class CollectionLSPSchedulingTest { + + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlan collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + + } + + @Test + public void testCollectionLSPScheduling() { + + for(LSPShipment shipment : collectionLSP.getShipments()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + } + + for(LSPShipment shipment : collectionLSP.getShipments()) { + assertTrue(shipment.getSchedule().getPlanElements().size() == 3); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + + assertTrue(shipment.getEventHandlers().size() == 2); + ArrayList eventHandlers = new ArrayList(shipment.getEventHandlers()); + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + } + + } + +} diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java new file mode 100644 index 00000000000..7335aaf4e0f --- /dev/null +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -0,0 +1,324 @@ +package lspSchedulingTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class CompleteLSPSchedulingTest { + + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP completeLSP; + private Carrier carrier; + private Resource completeAdapter; + private LogisticsSolutionElement completeElement; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FiretReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Random rand = new Random(1); + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = rand.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + completeLSP.assignShipmentToLSP(shipment); + } + completeLSP.scheduleSoultions(); + + } + + @Test + public void testCompletedLSPScheduling() { + + for(LSPShipment shipment : completeLSP.getShipments()) { + ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(AbstractShipmentPlanElement element : elementList) { + System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); + } + System.out.println(); + } + + } + +} diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java new file mode 100644 index 00000000000..a850cafeb1d --- /dev/null +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -0,0 +1,215 @@ +package lspSchedulingTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class FirstReloadLSPSchedulingTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + + @Test + public void testFirstReloadLSPScheduling() { + + for(LSPShipment shipment : lsp.getShipments()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + } + } +} diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java new file mode 100644 index 00000000000..5816cabe221 --- /dev/null +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -0,0 +1,256 @@ +package lspSchedulingTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class MainRunLSPSchedulingTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 4; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + @Test + public void testMainRunLSPScheduling() { + + for(LSPShipment shipment : lsp.getShipments()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + } + } +} diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java new file mode 100644 index 00000000000..9acba522ad8 --- /dev/null +++ b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java @@ -0,0 +1,280 @@ +package lspSchedulingTests; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.AbstractShipmentPlanElement; +import shipment.AbstractShipmentPlanElementComparator; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class SecondReloadLSPSchedulingTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + + @Test + public void testSecondReloadLSPScheduling() { + + for(LSPShipment shipment : lsp.getShipments()) { + ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(AbstractShipmentPlanElement element : elementList) { + System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); + } + System.out.println(); + } + + } +} diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java new file mode 100644 index 00000000000..afb0612e622 --- /dev/null +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -0,0 +1,201 @@ +package lspScoringTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; +import controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import replanning.LSPReplanningModuleImpl; +import scoring.LSPScorer; +import scoring.LSPScoringModuleImpl; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + + +public class CollectionLSPScoringTest { + + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private LSPScorer trinkgeldScorer; + private TrinkgeldSimulationTracker trinkgeldTracker; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + if (collectionLink == null) { + System.exit(1); + } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlan collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + TrinkgeldEventHandler handler = new TrinkgeldEventHandler(); + TrinkgeldInfoFunctionValue value = new TrinkgeldInfoFunctionValue(); + TrinkgeldInfoFunction function = new TrinkgeldInfoFunction(); + function.getValues().add(value); + TrinkgeldInfo info = new TrinkgeldInfo(function); + trinkgeldTracker = new TrinkgeldSimulationTracker(handler,info); + collectionAdapter.addSimulationTracker(trinkgeldTracker); + trinkgeldScorer = new TrinkgeldScorer(collectionLSP, trinkgeldTracker); + collectionLSP.setScorer(trinkgeldScorer); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 3; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPScoring() { + System.out.println(collectionLSP.getSelectedPlan().getScore()); + assertTrue(collectionLSP.getSelectedPlan().getScore() >=0); + assertTrue(collectionLSP.getSelectedPlan().getScore() <=10); + } + +} diff --git a/test/lspScoringTests/TrinkgeldEventHandler.java b/test/lspScoringTests/TrinkgeldEventHandler.java new file mode 100644 index 00000000000..7832b0b2f95 --- /dev/null +++ b/test/lspScoringTests/TrinkgeldEventHandler.java @@ -0,0 +1,32 @@ +package lspScoringTests; + +import java.util.Random; + +import events.ServiceCompletedEvent; +import events.ServiceCompletedEventHandler; + +public class TrinkgeldEventHandler implements ServiceCompletedEventHandler{ + + private double trinkgeldSum; + private Random trinkgeldRandom; + + public TrinkgeldEventHandler() { + trinkgeldRandom = new Random(1); + trinkgeldSum = 0; + } + + @Override + public void reset(int iteration) { + trinkgeldSum = 0; + } + + @Override + public void handleEvent(ServiceCompletedEvent event) { + double trinkgeld = trinkgeldRandom.nextDouble() * 5; + trinkgeldSum += trinkgeld; + } + + public double getTrinkgeld() { + return trinkgeldSum; + } +} diff --git a/test/lspScoringTests/TrinkgeldInfo.java b/test/lspScoringTests/TrinkgeldInfo.java new file mode 100644 index 00000000000..a51c01ac01e --- /dev/null +++ b/test/lspScoringTests/TrinkgeldInfo.java @@ -0,0 +1,41 @@ +package lspScoringTests; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; + +public class TrinkgeldInfo extends Info{ + + private TrinkgeldInfoFunction function; + private String name = "TRINKGELDINFO"; + + public TrinkgeldInfo (TrinkgeldInfoFunction function) { + this.function = function; + } + + @Override + public String getName() { + return name; + } + + @Override + public InfoFunction getFunction() { + return function; + } + + @Override + public double getFromTime() { + return 0; + } + + @Override + public double getToTime() { + return Double.MAX_VALUE; + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/test/lspScoringTests/TrinkgeldInfoFunction.java b/test/lspScoringTests/TrinkgeldInfoFunction.java new file mode 100644 index 00000000000..720b8f3e460 --- /dev/null +++ b/test/lspScoringTests/TrinkgeldInfoFunction.java @@ -0,0 +1,23 @@ +package lspScoringTests; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; + +public class TrinkgeldInfoFunction implements InfoFunction{ + + private Collection values; + + public TrinkgeldInfoFunction() { + this.values = new ArrayList(); + } + + + @Override + public Collection getValues() { + return values; + } + +} diff --git a/test/lspScoringTests/TrinkgeldInfoFunctionValue.java b/test/lspScoringTests/TrinkgeldInfoFunctionValue.java new file mode 100644 index 00000000000..b15c3d680eb --- /dev/null +++ b/test/lspScoringTests/TrinkgeldInfoFunctionValue.java @@ -0,0 +1,35 @@ +package lspScoringTests; + +import lsp.functions.InfoFunctionValue; + +public class TrinkgeldInfoFunctionValue implements InfoFunctionValue{ + + private String name = "TRINKGELD IN EUR"; + private Class type; + private double value; + + public TrinkgeldInfoFunctionValue() { + this.type = double.class; + } + + @Override + public String getName() { + return name; + } + + @Override + public Class getDataType() { + return type; + } + + @Override + public String getValue() { + return String.valueOf(value); + } + + @Override + public void setValue(String value) { + this.value = Double.valueOf(value).doubleValue(); + } + +} diff --git a/test/lspScoringTests/TrinkgeldScorer.java b/test/lspScoringTests/TrinkgeldScorer.java new file mode 100644 index 00000000000..046db7599bb --- /dev/null +++ b/test/lspScoringTests/TrinkgeldScorer.java @@ -0,0 +1,41 @@ +package lspScoringTests; + +import org.matsim.api.core.v01.population.HasPlansAndId; + +import lsp.LSP; +import lsp.functions.Info; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; +import scoring.LSPScorer; + +public class TrinkgeldScorer implements LSPScorer { + + private LSP lsp; + private TrinkgeldSimulationTracker tracker; + + public TrinkgeldScorer(LSP lsp, TrinkgeldSimulationTracker tracker) { + this.lsp = lsp; + this.tracker = tracker; + } + + @Override + public double scoreCurrentPlan(LSP lsp) { + double score = 0; + for(Info info : tracker.getInfos()) { + if(info.getName() == "TRINKGELDINFO") { + InfoFunction function = info.getFunction(); + for(InfoFunctionValue value : function.getValues()) { + if(value.getName() == "TRINKGELD IN EUR") { + double trinkgeldValue = Double.parseDouble(value.getValue()); + score += trinkgeldValue; + } + } + + } + + } + return score; + } + + +} diff --git a/test/lspScoringTests/TrinkgeldSimulationTracker.java b/test/lspScoringTests/TrinkgeldSimulationTracker.java new file mode 100644 index 00000000000..c92f7e2c70a --- /dev/null +++ b/test/lspScoringTests/TrinkgeldSimulationTracker.java @@ -0,0 +1,50 @@ +package lspScoringTests; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import tracking.SimulationTracker; + +public class TrinkgeldSimulationTracker implements SimulationTracker { + + private TrinkgeldEventHandler handler; + private Info info; + + public TrinkgeldSimulationTracker(TrinkgeldEventHandler handler, Info info) { + this.info = info; + this.handler = handler; + } + + @Override + public Collection getEventHandlers() { + ArrayList handlers = new ArrayList(); + handlers.add(handler); + return handlers; + } + + @Override + public Collection getInfos() { + ArrayList infos = new ArrayList(); + infos.add(info); + return infos; + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + double trinkgeld = handler.getTrinkgeld(); + InfoFunctionValue value = info.getFunction().getValues().iterator().next(); + value.setValue(String.valueOf(trinkgeld)); + } + + @Override + public void reset() { + // TODO Auto-generated method stub + } + + +} diff --git a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java new file mode 100644 index 00000000000..9faea138e74 --- /dev/null +++ b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java @@ -0,0 +1,174 @@ +package lspShipmentAssignmentTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class CollectionLSPShipmentAssigmentTest { + + private Network network; + private LogisticsSolution collectionSolution; + private ShipmentAssigner assigner; + private LSPPlan collectionPlan; + private SolutionScheduler simpleScheduler; + private LSP collectionLSP; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + collectionSolution = collectionSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + collectionPlan = new LSPPlan(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + } + + @Test + public void testCollectionLSPShipmentAssignment() { + assertTrue(collectionLSP.getSelectedPlan() == collectionPlan); + assertFalse(collectionLSP.getShipments().isEmpty()); + ArrayList solutions = new ArrayList(collectionLSP.getSelectedPlan().getSolutions()); + + for(LogisticsSolution solution : solutions) { + if(solutions.indexOf(solution) == 0 ) { + assertTrue(solution.getShipments().size() == 10); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(element.getPreviousElement() == null) { + assertTrue(element.getIncomingShipments().getShipments().size() == 10); + } + } + } + else { + assertTrue(solution.getShipments().isEmpty()); + } + } + + } +} diff --git a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java new file mode 100644 index 00000000000..88c493ae96b --- /dev/null +++ b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java @@ -0,0 +1,322 @@ +package lspShipmentAssignmentTests; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DeterministicShipmentAssigner; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import usecase.SimpleSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class CompleteLSPShipmentAssignerTest { + + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlan completePlan; + private SolutionScheduler simpleScheduler; + private LSP completeLSP; + + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FiretReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = collectionVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(collectionCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlan(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + completeLSP.assignShipmentToLSP(builder.build()); + } + } + + @Test + public void testCollectionLSPShipmentAssignment() { + assertTrue(completeLSP.getSelectedPlan() == completePlan); + ArrayList solutions = new ArrayList(completeLSP.getSelectedPlan().getSolutions()); + + for(LogisticsSolution solution : solutions) { + if(solutions.indexOf(solution) == 0 ) { + assertTrue(solution.getShipments().size() == 10); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(element.getPreviousElement() == null) { + assertTrue(element.getIncomingShipments().getShipments().size() == 10); + } + } + } + else { + assertTrue(solution.getShipments().isEmpty()); + } + } + + } +} diff --git a/test/lspShipmentTest/collectionShipmentBuilderTest.java b/test/lspShipmentTest/collectionShipmentBuilderTest.java new file mode 100644 index 00000000000..144213235ec --- /dev/null +++ b/test/lspShipmentTest/collectionShipmentBuilderTest.java @@ -0,0 +1,100 @@ +package lspShipmentTest; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; + +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class collectionShipmentBuilderTest { + + private Network network; + private Id toLinkId; + private ArrayList shipments; + + + @Before + public void initialize(){ + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + this.toLinkId = network.getLinks().get(collectionLinkId).getId(); + this.shipments = new ArrayList(); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipments.add(builder.build()); + } + } + + @Test + public void testShipments() { + assertTrue(shipments.size() == 10); + for(LSPShipment shipment : shipments) { + assertNotNull(shipment.getId()); + assertNotNull(shipment.getCapacityDemand()); + assertNotNull(shipment.getEndTimeWindow()); + assertNotNull(shipment.getFromLinkId()); + assertNotNull(shipment.getServiceTime()); + assertNotNull(shipment.getToLinkId()); + assertNotNull(shipment.getStartTimeWindow()); + assertNotNull(shipment.getSchedule()); + assertNotNull(shipment.getLog()); + assertNotNull(shipment.getEventHandlers()); + + assertTrue(shipment.getEventHandlers().isEmpty()); + assertEquals(shipment.getLog().getShipment(), shipment); + assertTrue(shipment.getLog().getPlanElements().isEmpty()); + + assertEquals(shipment.getSchedule().getShipment(), shipment); + assertTrue(shipment.getSchedule().getPlanElements().isEmpty()); + + Link link = network.getLinks().get(shipment.getFromLinkId()); + assertTrue(link.getFromNode().getCoord().getX() <= 4); + assertTrue(link.getFromNode().getCoord().getY() <= 4); + + } + } + +} diff --git a/test/lspShipmentTest/completeShipmentBuilderTest.java b/test/lspShipmentTest/completeShipmentBuilderTest.java new file mode 100644 index 00000000000..7bd681d5494 --- /dev/null +++ b/test/lspShipmentTest/completeShipmentBuilderTest.java @@ -0,0 +1,115 @@ +package lspShipmentTest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; + +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class completeShipmentBuilderTest { + + private Network network; + private ArrayList shipments; + + @Before + public void initialize(){ + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + this.shipments = new ArrayList(); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && + pendingFromLink.getFromNode().getCoord().getY() <= 4 && + pendingFromLink.getToNode().getCoord().getX() <= 4 && + pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipments.add(builder.build()); + } + } + + @Test + public void testShipments() { + assertTrue(shipments.size() == 10); + for(LSPShipment shipment : shipments) { + assertNotNull(shipment.getId()); + assertNotNull(shipment.getCapacityDemand()); + assertNotNull(shipment.getEndTimeWindow()); + assertNotNull(shipment.getFromLinkId()); + assertNotNull(shipment.getServiceTime()); + assertNotNull(shipment.getToLinkId()); + assertNotNull(shipment.getStartTimeWindow()); + assertNotNull(shipment.getSchedule()); + assertNotNull(shipment.getLog()); + assertNotNull(shipment.getEventHandlers()); + + assertTrue(shipment.getEventHandlers().isEmpty()); + assertEquals(shipment.getLog().getShipment(), shipment); + assertTrue(shipment.getLog().getPlanElements().isEmpty()); + + assertEquals(shipment.getSchedule().getShipment(), shipment); + assertTrue(shipment.getSchedule().getPlanElements().isEmpty()); + Link link = network.getLinks().get(shipment.getToLinkId()); + assertTrue(link.getFromNode().getCoord().getX() <= 18); + assertTrue(link.getFromNode().getCoord().getX() >= 14); + assertTrue(link.getToNode().getCoord().getX() <= 18); + assertTrue(link.getToNode().getCoord().getX() >= 14); + + link = network.getLinks().get(shipment.getFromLinkId()); + assertTrue(link.getFromNode().getCoord().getX() <= 4); + assertTrue(link.getFromNode().getCoord().getY() <= 4); + } + } +} diff --git a/test/lspShipmentTest/distributionShipmentBuilderTest.java b/test/lspShipmentTest/distributionShipmentBuilderTest.java new file mode 100644 index 00000000000..12fd6323948 --- /dev/null +++ b/test/lspShipmentTest/distributionShipmentBuilderTest.java @@ -0,0 +1,103 @@ +package lspShipmentTest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; + +import shipment.LSPShipment; +import shipment.LSPShipmentImpl; + +public class distributionShipmentBuilderTest { + + private Network network; + private Id fromLinkId; + private ArrayList shipments; + + + @Before + public void initialize(){ + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id distributionLinkId = Id.createLinkId("(14 2) (14 3)"); + this.fromLinkId = network.getLinks().get(distributionLinkId).getId(); + this.shipments = new ArrayList(); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18 && + pendingToLink.getFromNode().getCoord().getY() <= 4 && + pendingToLink.getFromNode().getCoord().getX() >= 14 && + pendingToLink.getToNode().getCoord().getX() <= 18 && + pendingToLink.getToNode().getCoord().getY() <= 4 && + pendingToLink.getToNode().getCoord().getX() >= 14 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + builder.setFromLinkId(fromLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipments.add(builder.build()); + } + } + + @Test + public void testShipments() { + assertTrue(shipments.size() == 10); + for(LSPShipment shipment : shipments) { + assertNotNull(shipment.getId()); + assertNotNull(shipment.getCapacityDemand()); + assertNotNull(shipment.getEndTimeWindow()); + assertNotNull(shipment.getFromLinkId()); + assertNotNull(shipment.getServiceTime()); + assertNotNull(shipment.getToLinkId()); + assertNotNull(shipment.getStartTimeWindow()); + assertNotNull(shipment.getSchedule()); + assertNotNull(shipment.getLog()); + assertNotNull(shipment.getEventHandlers()); + + assertTrue(shipment.getEventHandlers().isEmpty()); + assertEquals(shipment.getLog().getShipment(), shipment); + assertTrue(shipment.getLog().getPlanElements().isEmpty()); + + assertEquals(shipment.getSchedule().getShipment(), shipment); + assertTrue(shipment.getSchedule().getPlanElements().isEmpty()); + Link link = network.getLinks().get(shipment.getToLinkId()); + assertTrue(link.getFromNode().getCoord().getX() <= 18); + assertTrue(link.getFromNode().getCoord().getX() >= 14); + assertTrue(link.getToNode().getCoord().getX() <= 18); + assertTrue(link.getToNode().getCoord().getX() >= 14); + } + } +} diff --git a/test/solutionElementTests/CollectionElementTest.java b/test/solutionElementTests/CollectionElementTest.java new file mode 100644 index 00000000000..fecb1d7601f --- /dev/null +++ b/test/solutionElementTests/CollectionElementTest.java @@ -0,0 +1,103 @@ +package solutionElementTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.resources.Resource; + +public class CollectionElementTest { + + private Network network; + private CollectionCarrierScheduler scheduler; + private CarrierVehicleType collectionType; + private CarrierCapabilities capabilities; + private Carrier carrier; + private LogisticsSolutionElement collectionElement; + private CollectionCarrierAdapter adapter; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder builder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + builder.setCollectionScheduler(scheduler); + builder.setCarrier(carrier); + builder.setLocationLinkId(collectionLinkId); + adapter = builder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionBuilder.setResource(adapter); + collectionElement = collectionBuilder.build(); + } + + @Test + public void testCollectionElement() { + assertTrue(collectionElement.getIncomingShipments()!= null); + assertTrue(collectionElement.getIncomingShipments().getShipments() != null); + assertTrue(collectionElement.getIncomingShipments().getSortedShipments().isEmpty()); + assertTrue(collectionElement.getInfos() != null); + assertTrue(collectionElement.getInfos().isEmpty()); + assertTrue(collectionElement.getLogisticsSolution() == null); + assertTrue(collectionElement.getNextElement() == null); + assertTrue(collectionElement.getOutgoingShipments()!= null); + assertTrue(collectionElement.getOutgoingShipments().getShipments() != null); + assertTrue(collectionElement.getOutgoingShipments().getSortedShipments().isEmpty()); + assertTrue(collectionElement.getPreviousElement() == null); + assertTrue(collectionElement.getResource() == adapter); + assertTrue(collectionElement.getResource().getClientElements().iterator().next() == collectionElement); + } + +} diff --git a/test/solutionElementTests/DistributionElementTest.java b/test/solutionElementTests/DistributionElementTest.java new file mode 100644 index 00000000000..a97d22056ce --- /dev/null +++ b/test/solutionElementTests/DistributionElementTest.java @@ -0,0 +1,104 @@ +package solutionElementTests; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.resources.Resource; + +public class DistributionElementTest { + + private Network network; + private DistributionCarrierScheduler scheduler; + private CarrierVehicleType distributionType; + private CarrierVehicle carrierVehicle; + private CarrierCapabilities capabilities; + private Carrier carrier; + private DistributionCarrierAdapter adapter; + private LogisticsSolutionElement distributionElement; + + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + scheduler = new DistributionCarrierScheduler(); + Id carrierId = Id.create("DistributionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + distributionType = vehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + carrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + carrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder builder = DistributionCarrierAdapter.Builder.newInstance(adapterId, network); + builder.setDistributionScheduler(scheduler); + builder.setCarrier(carrier); + builder.setLocationLinkId(distributionLinkId); + adapter = builder.build(); + + Id elementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + distributionBuilder.setResource(adapter); + distributionElement = distributionBuilder.build(); + + } + + @Test + public void testDistributionElement() { + assertTrue(distributionElement.getIncomingShipments()!= null); + assertTrue(distributionElement.getIncomingShipments().getShipments() != null); + assertTrue(distributionElement.getIncomingShipments().getSortedShipments().isEmpty()); + assertTrue(distributionElement.getInfos() != null); + assertTrue(distributionElement.getInfos().isEmpty()); + assertTrue(distributionElement.getLogisticsSolution() == null); + assertTrue(distributionElement.getNextElement() == null); + assertTrue(distributionElement.getOutgoingShipments()!= null); + assertTrue(distributionElement.getOutgoingShipments().getShipments() != null); + assertTrue(distributionElement.getOutgoingShipments().getSortedShipments().isEmpty()); + assertTrue(distributionElement.getPreviousElement() == null); + assertTrue(distributionElement.getResource() == adapter); + assertTrue(distributionElement.getResource().getClientElements().iterator().next() == distributionElement); + } +} diff --git a/test/solutionElementTests/FirstReloadElementTest.java b/test/solutionElementTests/FirstReloadElementTest.java new file mode 100644 index 00000000000..a78c23c9017 --- /dev/null +++ b/test/solutionElementTests/FirstReloadElementTest.java @@ -0,0 +1,61 @@ +package solutionElementTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; + +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.resources.Resource; + +public class FirstReloadElementTest { + + private Id reloadingId; + private Id reloadingLinkId; + private ReloadingPoint point; + private LogisticsSolutionElement reloadingElement; + private Id elementId; + + @Before + public void initialize() { + ReloadingPointScheduler.Builder schedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + schedulerBuilder.setCapacityNeedFixed(10); + schedulerBuilder.setCapacityNeedLinear(1); + + + reloadingId = Id.create("ReloadingPoint1", Resource.class); + reloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder reloadingPointBuilder = ReloadingPoint.Builder.newInstance(reloadingId, reloadingLinkId); + reloadingPointBuilder.setReloadingScheduler(schedulerBuilder.build()); + point = reloadingPointBuilder.build(); + + elementId = Id.create("FiretReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder reloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + reloadingElementBuilder.setResource(point); + reloadingElement = reloadingElementBuilder.build(); + } + + @Test + public void testDistributionElement() { + assertTrue(reloadingElement.getIncomingShipments()!= null); + assertTrue(reloadingElement.getIncomingShipments().getShipments() != null); + assertTrue(reloadingElement.getIncomingShipments().getSortedShipments().isEmpty()); + assertTrue(reloadingElement.getInfos() != null); + assertTrue(reloadingElement.getInfos().isEmpty()); + assertTrue(reloadingElement.getLogisticsSolution() == null); + assertTrue(reloadingElement.getNextElement() == null); + assertTrue(reloadingElement.getOutgoingShipments()!= null); + assertTrue(reloadingElement.getOutgoingShipments().getShipments() != null); + assertTrue(reloadingElement.getOutgoingShipments().getSortedShipments().isEmpty()); + assertTrue(reloadingElement.getPreviousElement() == null); + assertTrue(reloadingElement.getResource() == point); + assertTrue(reloadingElement.getResource().getClientElements().iterator().next() == reloadingElement); + } + +} diff --git a/test/solutionElementTests/MainRunElementTest.java b/test/solutionElementTests/MainRunElementTest.java new file mode 100644 index 00000000000..19c21d85961 --- /dev/null +++ b/test/solutionElementTests/MainRunElementTest.java @@ -0,0 +1,106 @@ +package solutionElementTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.resources.Resource; + +public class MainRunElementTest { + + private Network network; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Carrier carrier; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + Id carrierId = Id.create("MainRunCarrier", Carrier.class); + Id vehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(30); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(120); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = vehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, fromLinkId); + carrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(mainRunType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + + MainRunCarrierScheduler scheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(scheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(carrier); + mainRunAdapter = mainRunAdapterBuilder.build(); + + Id elementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + mainRunBuilder.setResource( mainRunAdapter); + mainRunElement = mainRunBuilder.build(); + + } + + @Test + public void testDistributionElement() { + assertTrue(mainRunElement.getIncomingShipments()!= null); + assertTrue(mainRunElement.getIncomingShipments().getShipments() != null); + assertTrue(mainRunElement.getIncomingShipments().getSortedShipments().isEmpty()); + assertTrue(mainRunElement.getInfos() != null); + assertTrue(mainRunElement.getInfos().isEmpty()); + assertTrue(mainRunElement.getLogisticsSolution() == null); + assertTrue(mainRunElement.getNextElement() == null); + assertTrue(mainRunElement.getOutgoingShipments()!= null); + assertTrue(mainRunElement.getOutgoingShipments().getShipments() != null); + assertTrue(mainRunElement.getOutgoingShipments().getSortedShipments().isEmpty()); + assertTrue(mainRunElement.getPreviousElement() == null); + assertTrue(mainRunElement.getResource() == mainRunAdapter); + assertTrue(mainRunElement.getResource().getClientElements().iterator().next() == mainRunElement); + } + + +} diff --git a/test/solutionElementTests/SecondReloadElementTest.java b/test/solutionElementTests/SecondReloadElementTest.java new file mode 100644 index 00000000000..598142ad24c --- /dev/null +++ b/test/solutionElementTests/SecondReloadElementTest.java @@ -0,0 +1,60 @@ +package solutionElementTests; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; + +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.resources.Resource; + +public class SecondReloadElementTest { + + private Id reloadingId; + private Id reloadingLinkId; + private Resource point; + private LogisticsSolutionElement reloadElement; + + @Before + public void initialize() { + ReloadingPointScheduler.Builder schedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + schedulerBuilder.setCapacityNeedFixed(10); + schedulerBuilder.setCapacityNeedLinear(1); + + + reloadingId = Id.create("ReloadingPoint2", Resource.class); + reloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder reloadingPointBuilder = ReloadingPoint.Builder.newInstance(reloadingId, reloadingLinkId); + reloadingPointBuilder.setReloadingScheduler(schedulerBuilder.build()); + point = reloadingPointBuilder.build(); + + Id elementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder reloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + reloadingElementBuilder.setResource(point); + reloadElement = reloadingElementBuilder.build(); + + } + + @Test + public void testDistributionElement() { + assertTrue(reloadElement.getIncomingShipments()!= null); + assertTrue(reloadElement.getIncomingShipments().getShipments() != null); + assertTrue(reloadElement.getIncomingShipments().getSortedShipments().isEmpty()); + assertTrue(reloadElement.getInfos() != null); + assertTrue(reloadElement.getInfos().isEmpty()); + assertTrue(reloadElement.getLogisticsSolution() == null); + assertTrue(reloadElement.getNextElement() == null); + assertTrue(reloadElement.getOutgoingShipments()!= null); + assertTrue(reloadElement.getOutgoingShipments().getShipments() != null); + assertTrue(reloadElement.getOutgoingShipments().getSortedShipments().isEmpty()); + assertTrue(reloadElement.getPreviousElement() == null); + assertTrue(reloadElement.getResource() == point); + assertTrue(reloadElement.getResource().getClientElements().iterator().next() == reloadElement); + } +} diff --git a/test/solutionTests/CollectionSolutionTest.java b/test/solutionTests/CollectionSolutionTest.java new file mode 100644 index 00000000000..30d035fb4a9 --- /dev/null +++ b/test/solutionTests/CollectionSolutionTest.java @@ -0,0 +1,117 @@ +package solutionTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.resources.Resource; + +public class CollectionSolutionTest { + + private Network network; + private Carrier carrier; + private CollectionCarrierAdapter adapter; + private LogisticsSolutionElement collectionElement; + private LogisticsSolution collectionSolution; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50 / 3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, + network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + adapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(elementId); + collectionElementBuilder.setResource(adapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder + .newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + collectionSolution = collectionSolutionBuilder.build(); + + } + + @Test + public void testCollectionSolution() { + assertTrue(collectionSolution.getEventHandlers() != null); + assertTrue(collectionSolution.getEventHandlers().isEmpty()); + assertTrue(collectionSolution.getInfos() != null); + assertTrue(collectionSolution.getInfos().isEmpty()); + assertTrue(collectionSolution.getLSP() == null); + assertTrue(collectionSolution.getShipments() != null); + assertTrue(collectionSolution.getShipments().isEmpty()); + assertTrue(collectionSolution.getSolutionElements().size() == 1); + ArrayList elements = new ArrayList(collectionSolution.getSolutionElements()); + for(LogisticsSolutionElement element : elements) { + if(elements.indexOf(element) == 0) { + assertTrue(element.getPreviousElement() == null); + } + if(elements.indexOf(element) == (elements.size() -1)) { + assertTrue(element.getNextElement() == null); + } + assertTrue(element.getLogisticsSolution() == collectionSolution); + } + } + +} diff --git a/test/solutionTests/CompleteSolutionTest.java b/test/solutionTests/CompleteSolutionTest.java new file mode 100644 index 00000000000..24d4334fee3 --- /dev/null +++ b/test/solutionTests/CompleteSolutionTest.java @@ -0,0 +1,265 @@ +package solutionTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import usecase.CollectionCarrierAdapter; +import usecase.CollectionCarrierScheduler; +import usecase.DistributionCarrierAdapter; +import usecase.DistributionCarrierScheduler; +import usecase.MainRunCarrierAdapter; +import usecase.MainRunCarrierScheduler; +import usecase.ReloadingPoint; +import usecase.ReloadingPointScheduler; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.resources.Resource; + +public class CompleteSolutionTest { + + private Network network; + private LogisticsSolutionElement collectionElement; + private LogisticsSolutionElement firstReloadElement; + private LogisticsSolutionElement mainRunElement; + private LogisticsSolutionElement secondReloadElement; + private LogisticsSolutionElement distributionElement; + private LogisticsSolution solution; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder + .newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50 / 3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder + .newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + + Id collectionElementId = Id.create("CollectionElement", + LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapterBuilder.build()); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, + firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + + Id firstReloadingElementId = Id.create("FiretReloadElement", + LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointBuilder.build()); + firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder + .newInstance(collectionVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50 / 3.6); + CarrierVehicleType mainRunType = collectionVehicleTypeBuilder.build(); + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, + network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(collectionCarrier); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapterBuilder.build()); + mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, + secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + + Id secondReloadingElementId = Id.create("SecondReloadElement", + LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointBuilder.build()); + secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder + .newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50 / 3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, + distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder + .newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + + Id distributionElementId = Id.create("DistributionElement", + LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapterBuilder.build()); + distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + solution = completeSolutionBuilder.build(); + + } + + @Test + public void testCompleteSolution() { + assertTrue(solution.getEventHandlers() != null); + assertTrue(solution.getEventHandlers().isEmpty()); + assertTrue(solution.getInfos() != null); + assertTrue(solution.getInfos().isEmpty()); + assertTrue(solution.getLSP() == null); + assertTrue(solution.getShipments() != null); + assertTrue(solution.getShipments().isEmpty()); + assertTrue(solution.getSolutionElements().size() == 5); + ArrayList elements = new ArrayList(solution.getSolutionElements()); + for(LogisticsSolutionElement element : elements) { + if(elements.indexOf(element) == 0) { + assertTrue(element.getPreviousElement() == null); + } + if(elements.indexOf(element) == (elements.size() -1)) { + assertTrue(element.getNextElement() == null); + } + assertTrue(element.getLogisticsSolution() == solution); + } + assertTrue(collectionElement.getPreviousElement() == null); + assertTrue(collectionElement.getNextElement() == firstReloadElement); + assertTrue(firstReloadElement.getPreviousElement() == collectionElement); + assertTrue(firstReloadElement.getNextElement() == mainRunElement); + assertTrue(mainRunElement.getPreviousElement() == firstReloadElement); + assertTrue(mainRunElement.getNextElement() == secondReloadElement); + assertTrue(secondReloadElement.getPreviousElement() == mainRunElement); + assertTrue(secondReloadElement.getNextElement() == distributionElement); + assertTrue(distributionElement.getPreviousElement() == secondReloadElement); + assertTrue(distributionElement.getNextElement() == null); + } + + +} From 65a7d9c34c2e108f7b348652a4e9c284b3afcdc2 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 20 Feb 2018 10:33:46 +0100 Subject: [PATCH 0009/1340] Network file and tests adjusted --- test/cascadingInfoTest/CascadingInfoTest.java | 8 +++---- .../CollectionLSPMobsimTest.java | 8 +++---- .../lspMobsimTests/CompleteLSPMobsimTest.java | 24 +++++++++---------- .../FirstReloadLSPMobsimTest.java | 20 ++++++++-------- test/lspMobsimTests/MainRunLSPMobsimTest.java | 20 ++++++++-------- .../MainRunOnlyLSPMobsimTest.java | 20 ++++++++-------- .../SecondReloadLSPMobsimTest.java | 20 ++++++++-------- .../CollectionLSPReplanningTest.java | 8 +++---- .../CollectionLSPSchedulingTest.java | 8 +++---- .../CompleteLSPSchedulingTest.java | 24 +++++++++---------- .../FirstReloadLSPSchedulingTest.java | 20 ++++++++-------- .../MainRunLSPSchedulingTest.java | 20 ++++++++-------- .../SecondReloadLSPSchedulingTest.java | 20 ++++++++-------- .../CollectionLSPScoringTest.java | 8 +++---- .../CollectionLSPShipmentAssigmentTest.java | 8 +++---- .../CompleteLSPShipmentAssignerTest.java | 20 ++++++++-------- .../collectionShipmentBuilderTest.java | 8 +++---- .../completeShipmentBuilderTest.java | 20 ++++++++-------- .../distributionShipmentBuilderTest.java | 12 +++++----- 19 files changed, 148 insertions(+), 148 deletions(-) diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java index e2720bcfcc8..efa55df449e 100644 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -155,10 +155,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList, random); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java index 49cfa988a78..d877088d7c7 100644 --- a/test/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -141,10 +141,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList, random); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/test/lspMobsimTests/CompleteLSPMobsimTest.java index db22ca0fce8..c4447457559 100644 --- a/test/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/test/lspMobsimTests/CompleteLSPMobsimTest.java @@ -281,12 +281,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -296,10 +296,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } @@ -343,11 +343,11 @@ public void testFirstReloadLSPMobsim() { Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); System.out.println(); for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + "\t" + scheduleElements.get(i).getResourceId() +"\t"+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + "\t End: " + scheduleElements.get(i).getEndTime()); } System.out.println(); for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + "\t" + logElements.get(i).getResourceId() +"\t" + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + "\t End: " + logElements.get(i).getEndTime()); } } diff --git a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java index b18516688b1..e871a782591 100644 --- a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -163,12 +163,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -178,10 +178,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspMobsimTests/MainRunLSPMobsimTest.java b/test/lspMobsimTests/MainRunLSPMobsimTest.java index c50d8fc3d37..e44ae19b2f9 100644 --- a/test/lspMobsimTests/MainRunLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunLSPMobsimTest.java @@ -207,12 +207,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -222,10 +222,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java index a2dabba34c9..0aadec6cf5a 100644 --- a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -147,12 +147,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -162,10 +162,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java index 255f3b05e36..ab475bd1ece 100644 --- a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java @@ -235,12 +235,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -250,10 +250,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspReplanningTests/CollectionLSPReplanningTest.java b/test/lspReplanningTests/CollectionLSPReplanningTest.java index 282e682ad73..83a3f898bf4 100644 --- a/test/lspReplanningTests/CollectionLSPReplanningTest.java +++ b/test/lspReplanningTests/CollectionLSPReplanningTest.java @@ -151,10 +151,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList, random); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index b2b02fb0b07..b5b21d91cd7 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -141,10 +141,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList, random); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index 7335aaf4e0f..7bd38a2f7f2 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -120,7 +120,7 @@ public void initialize() { firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - Id firstReloadingElementId = Id.create("FiretReloadElement", LogisticsSolutionElement.class); + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); @@ -269,12 +269,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList, rand); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -284,10 +284,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList, rand); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } @@ -314,7 +314,7 @@ public void testCompletedLSPScheduling() { Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); System.out.println(); for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); + System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime()); } System.out.println(); } diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java index a850cafeb1d..69505ab135b 100644 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -161,12 +161,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -176,10 +176,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java index 5816cabe221..78ccc23de21 100644 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -203,12 +203,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -218,10 +218,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java index 9acba522ad8..66b17783048 100644 --- a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java @@ -226,12 +226,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -241,10 +241,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java index afb0612e622..bbee55fff4e 100644 --- a/test/lspScoringTests/CollectionLSPScoringTest.java +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -154,10 +154,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList, random); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java index 9faea138e74..cc62486f1c8 100644 --- a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java +++ b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java @@ -130,10 +130,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java index 88c493ae96b..06937e56c51 100644 --- a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java +++ b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java @@ -265,12 +265,12 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -280,10 +280,10 @@ public void initialize() { while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspShipmentTest/collectionShipmentBuilderTest.java b/test/lspShipmentTest/collectionShipmentBuilderTest.java index 144213235ec..459c7e222ad 100644 --- a/test/lspShipmentTest/collectionShipmentBuilderTest.java +++ b/test/lspShipmentTest/collectionShipmentBuilderTest.java @@ -48,10 +48,10 @@ public void initialize(){ while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspShipmentTest/completeShipmentBuilderTest.java b/test/lspShipmentTest/completeShipmentBuilderTest.java index 7bd681d5494..c08d49c843f 100644 --- a/test/lspShipmentTest/completeShipmentBuilderTest.java +++ b/test/lspShipmentTest/completeShipmentBuilderTest.java @@ -46,12 +46,12 @@ public void initialize(){ while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } @@ -61,10 +61,10 @@ public void initialize(){ while(true) { Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4 && - pendingFromLink.getFromNode().getCoord().getY() <= 4 && - pendingFromLink.getToNode().getCoord().getX() <= 4 && - pendingFromLink.getToNode().getCoord().getY() <= 4 ) { + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { builder.setFromLinkId(pendingFromLink.getId()); break; } diff --git a/test/lspShipmentTest/distributionShipmentBuilderTest.java b/test/lspShipmentTest/distributionShipmentBuilderTest.java index 12fd6323948..be562192fa4 100644 --- a/test/lspShipmentTest/distributionShipmentBuilderTest.java +++ b/test/lspShipmentTest/distributionShipmentBuilderTest.java @@ -50,12 +50,12 @@ public void initialize(){ while(true) { Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18 && - pendingToLink.getFromNode().getCoord().getY() <= 4 && - pendingToLink.getFromNode().getCoord().getX() >= 14 && - pendingToLink.getToNode().getCoord().getX() <= 18 && - pendingToLink.getToNode().getCoord().getY() <= 4 && - pendingToLink.getToNode().getCoord().getX() >= 14 )) { + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { builder.setToLinkId(pendingToLink.getId()); break; } From 7543572a6bbea1e7901ce5de0ae9479f54ad6c71 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 23 Feb 2018 15:43:28 +0100 Subject: [PATCH 0010/1340] Update .gitattributes for .zip-files --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 533d55da448..83ad1f3cf10 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ *.png filter=fat -crlf *.jpg filter=fat -crlf *.gz filter=fat -crlf +*.zip filter=fat -crlf \ No newline at end of file From 37285b8afe0e88d8ca10b65308636130e1c6bbf5 Mon Sep 17 00:00:00 2001 From: kturner Date: Fri, 23 Feb 2018 16:02:47 +0100 Subject: [PATCH 0011/1340] add .DS-Store to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0615962b865..0f19fb612ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.class +*.DS_Store # Mobile Tools for Java (J2ME) .mtj.tmp/ From 53326b07c7a88364185d756f28750bc976adaca5 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 28 Feb 2018 17:53:35 +0100 Subject: [PATCH 0012/1340] Demand Side added --- pom.xml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index a834e6e4486..a5349d2d8aa 100644 --- a/pom.xml +++ b/pom.xml @@ -20,28 +20,19 @@ ojo-snapshots http://oss.jfrog.org/libs-snapshot - - jitpack.io - https://jitpack.io - - - - com.github.matsim-org - matsim - freight-dfg17-mainBranch-SNAPSHOT + 0.10.0-SNAPSHOT From c3fa77a7bf0f0906e1d585c11eaaf8afb8e5505b Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 28 Feb 2018 17:54:21 +0100 Subject: [PATCH 0013/1340] Tests updated to match changes in source code --- test/adapterTests/CollectionAdapterTest.java | 4 +- .../adapterTests/DistributionAdapterTest.java | 4 +- test/adapterTests/FirstReloadAdapterTest.java | 4 +- test/adapterTests/MainRunAdapterTest.java | 4 +- .../adapterTests/SecondReloadAdapterTest.java | 4 +- .../cascadingInfoTest/AverageTimeTracker.java | 2 +- test/cascadingInfoTest/CascadingInfoTest.java | 25 ++++++----- test/cascadingInfoTest/TimeSpanHandler.java | 8 ++-- .../CollectionLSPCreationTest.java | 14 +++--- .../CompleteLSPCreationTest.java | 34 +++++++------- .../CollectionLSPMobsimTest.java | 29 ++++++------ .../lspMobsimTests/CompleteLSPMobsimTest.java | 43 +++++++++--------- .../FirstReloadLSPMobsimTest.java | 35 ++++++++------- test/lspMobsimTests/MainRunLSPMobsimTest.java | 39 ++++++++-------- .../MainRunOnlyLSPMobsimTest.java | 39 ++++++++-------- .../SecondReloadLSPMobsimTest.java | 39 ++++++++-------- test/lspPlanTests/CollectionLSPPlanTest.java | 13 +++--- test/lspPlanTests/CompleteLSPPlanTest.java | 25 ++++++----- .../CollectionLSPReplanningTest.java | 29 ++++++------ .../GenericStrategyManagerFactoryImpl.java | 3 +- test/lspReplanningTests/TomorrowAssigner.java | 2 +- ...morrowShipmentAssignerStrategyFactory.java | 3 +- .../CollectionLSPSchedulingTest.java | 27 +++++------ .../CompleteLSPSchedulingTest.java | 37 +++++++-------- .../FirstReloadLSPSchedulingTest.java | 37 +++++++-------- .../MainRunLSPSchedulingTest.java | 37 +++++++-------- .../SecondReloadLSPSchedulingTest.java | 37 +++++++-------- .../CollectionLSPScoringTest.java | 45 +++++++++++-------- .../TrinkgeldEventHandler.java | 7 ++- test/lspScoringTests/TrinkgeldScorer.java | 4 +- .../TrinkgeldSimulationTracker.java | 2 +- .../CollectionLSPShipmentAssigmentTest.java | 21 ++++----- .../CompleteLSPShipmentAssignerTest.java | 33 +++++++------- .../collectionShipmentBuilderTest.java | 4 +- .../completeShipmentBuilderTest.java | 4 +- .../distributionShipmentBuilderTest.java | 4 +- .../CollectionElementTest.java | 4 +- .../DistributionElementTest.java | 4 +- .../FirstReloadElementTest.java | 4 +- .../MainRunElementTest.java | 4 +- .../SecondReloadElementTest.java | 4 +- .../solutionTests/CollectionSolutionTest.java | 4 +- test/solutionTests/CompleteSolutionTest.java | 16 +++---- 43 files changed, 385 insertions(+), 356 deletions(-) diff --git a/test/adapterTests/CollectionAdapterTest.java b/test/adapterTests/CollectionAdapterTest.java index 4140875628d..9337921796e 100644 --- a/test/adapterTests/CollectionAdapterTest.java +++ b/test/adapterTests/CollectionAdapterTest.java @@ -24,8 +24,8 @@ import lsp.resources.CarrierResource; import lsp.resources.Resource; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; diff --git a/test/adapterTests/DistributionAdapterTest.java b/test/adapterTests/DistributionAdapterTest.java index dd89e42d8aa..e142deb0e5b 100644 --- a/test/adapterTests/DistributionAdapterTest.java +++ b/test/adapterTests/DistributionAdapterTest.java @@ -25,8 +25,8 @@ import lsp.resources.CarrierResource; import lsp.resources.Resource; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; diff --git a/test/adapterTests/FirstReloadAdapterTest.java b/test/adapterTests/FirstReloadAdapterTest.java index c758fa4c29e..3452ca79db0 100644 --- a/test/adapterTests/FirstReloadAdapterTest.java +++ b/test/adapterTests/FirstReloadAdapterTest.java @@ -9,8 +9,8 @@ import lsp.resources.CarrierResource; import lsp.resources.Resource; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; public class FirstReloadAdapterTest { diff --git a/test/adapterTests/MainRunAdapterTest.java b/test/adapterTests/MainRunAdapterTest.java index 398488e9e5d..79e7c7ae410 100644 --- a/test/adapterTests/MainRunAdapterTest.java +++ b/test/adapterTests/MainRunAdapterTest.java @@ -24,8 +24,8 @@ import lsp.resources.CarrierResource; import lsp.resources.Resource; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; diff --git a/test/adapterTests/SecondReloadAdapterTest.java b/test/adapterTests/SecondReloadAdapterTest.java index 85c8ea6ffbf..88d46855090 100644 --- a/test/adapterTests/SecondReloadAdapterTest.java +++ b/test/adapterTests/SecondReloadAdapterTest.java @@ -10,8 +10,8 @@ import lsp.resources.CarrierResource; import lsp.resources.Resource; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; public class SecondReloadAdapterTest { diff --git a/test/cascadingInfoTest/AverageTimeTracker.java b/test/cascadingInfoTest/AverageTimeTracker.java index fd4674a3d41..ed00fcc17f0 100644 --- a/test/cascadingInfoTest/AverageTimeTracker.java +++ b/test/cascadingInfoTest/AverageTimeTracker.java @@ -7,7 +7,7 @@ import org.matsim.core.events.handler.EventHandler; import lsp.functions.Info; -import tracking.SimulationTracker; +import lsp.tracking.SimulationTracker; diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java index efa55df449e..9be1eee7a7a 100644 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -27,10 +27,10 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import controler.LSPModule; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -39,14 +39,14 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; @@ -127,7 +127,8 @@ public void initialize() { collectionElement.getInfos().add(solutionInfo); ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlan collectionPlan = new LSPPlan(assigner); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -137,7 +138,7 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); diff --git a/test/cascadingInfoTest/TimeSpanHandler.java b/test/cascadingInfoTest/TimeSpanHandler.java index 07ab8e64e86..0f2438f86fd 100644 --- a/test/cascadingInfoTest/TimeSpanHandler.java +++ b/test/cascadingInfoTest/TimeSpanHandler.java @@ -3,10 +3,10 @@ import java.util.ArrayList; import java.util.Collection; -import events.ServiceBeginsEvent; -import events.ServiceBeginsEventHandler; -import events.TourStartEvent; -import events.TourStartEventHandler; +import lsp.events.ServiceBeginsEvent; +import lsp.events.ServiceBeginsEventHandler; +import lsp.events.TourStartEvent; +import lsp.events.TourStartEventHandler; diff --git a/test/lspCreationTests/CollectionLSPCreationTest.java b/test/lspCreationTests/CollectionLSPCreationTest.java index bc252880d1d..bf13579898a 100644 --- a/test/lspCreationTests/CollectionLSPCreationTest.java +++ b/test/lspCreationTests/CollectionLSPCreationTest.java @@ -25,6 +25,7 @@ import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -32,10 +33,10 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; @@ -100,7 +101,8 @@ public void initialize() { collectionSolution = collectionSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - collectionPlan = new LSPPlan(assigner); + LSPPlan collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -110,7 +112,7 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); } diff --git a/test/lspCreationTests/CompleteLSPCreationTest.java b/test/lspCreationTests/CompleteLSPCreationTest.java index 1c2b27d2ee4..9844d4c8c01 100644 --- a/test/lspCreationTests/CompleteLSPCreationTest.java +++ b/test/lspCreationTests/CompleteLSPCreationTest.java @@ -4,9 +4,6 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - import org.junit.Before; import org.junit.Test; import org.matsim.api.core.v01.Id; @@ -18,7 +15,6 @@ import org.matsim.contrib.freight.carrier.CarrierImpl; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; @@ -29,6 +25,7 @@ import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -36,16 +33,16 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; @@ -231,12 +228,13 @@ public void initialize() { completeSolutionBuilder.addSolutionElement(distributionElement); assigner = new DeterministicShipmentAssigner(); - LSPPlan collectionPlan = new LSPPlan(assigner); + LSPPlan completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner);; completeSolution = completeSolutionBuilder.build(); - collectionPlan.addSolution(completeSolution); + completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(collectionPlan); + completeLSPBuilder.setInitialPlan(completePlan); Id collectionLSPId = Id.create("CollectionLSP", LSP.class); completeLSPBuilder.setId(collectionLSPId); ArrayList resourcesList = new ArrayList(); @@ -247,7 +245,7 @@ public void initialize() { resourcesList.add(distributionAdapter); - SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); completeLSP = completeLSPBuilder.build(); diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java index d877088d7c7..a419124d7f9 100644 --- a/test/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -27,14 +27,14 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -43,12 +43,12 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CollectionLSPMobsimTest { private Network network; @@ -113,7 +113,8 @@ public void initialize() { LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlan collectionPlan = new LSPPlan(assigner); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -123,7 +124,7 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/test/lspMobsimTests/CompleteLSPMobsimTest.java index c4447457559..2c083d1c9b3 100644 --- a/test/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/test/lspMobsimTests/CompleteLSPMobsimTest.java @@ -28,20 +28,20 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -50,18 +50,18 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CompleteLSPMobsimTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP completeLSP; private Carrier carrier; @@ -251,7 +251,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -266,7 +267,7 @@ public void initialize() { resourcesList.add(distributionAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); completeLSP = completeLSPBuilder.build(); diff --git a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java index e871a782591..807093d22a0 100644 --- a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -28,16 +28,16 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -46,18 +46,18 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class FirstReloadLSPMobsimTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -136,7 +136,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -148,7 +149,7 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspMobsimTests/MainRunLSPMobsimTest.java b/test/lspMobsimTests/MainRunLSPMobsimTest.java index e44ae19b2f9..1bb2e48f8a0 100644 --- a/test/lspMobsimTests/MainRunLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunLSPMobsimTest.java @@ -28,18 +28,18 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -48,18 +48,18 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class MainRunLSPMobsimTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -180,7 +180,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner);; completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -192,7 +193,7 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); resourcesList.add(mainRunAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java index 0aadec6cf5a..e9a7bc84b0d 100644 --- a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -28,18 +28,18 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -48,18 +48,18 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class MainRunOnlyLSPMobsimTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -121,7 +121,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner);; completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -132,7 +133,7 @@ public void initialize() { resourcesList.add(mainRunAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java index ab475bd1ece..1932422bf09 100644 --- a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java @@ -28,10 +28,10 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import controler.LSPModule; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -40,20 +40,20 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScoringModuleImpl; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; @@ -61,7 +61,7 @@ public class SecondReloadLSPMobsimTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -205,7 +205,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -220,7 +221,7 @@ public void initialize() { - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspPlanTests/CollectionLSPPlanTest.java b/test/lspPlanTests/CollectionLSPPlanTest.java index 2357da3bc75..da7bd6f13ef 100644 --- a/test/lspPlanTests/CollectionLSPPlanTest.java +++ b/test/lspPlanTests/CollectionLSPPlanTest.java @@ -20,10 +20,10 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import lsp.LSPPlan; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -36,7 +36,7 @@ public class CollectionLSPPlanTest { private Network network; private LogisticsSolution collectionSolution; private ShipmentAssigner assigner; - private LSPPlan collectionPlan; + private LSPPlanImpl collectionPlan; @Before public void initialize() { @@ -90,7 +90,8 @@ public void initialize() { collectionSolution = collectionSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - collectionPlan = new LSPPlan(assigner); + collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); } diff --git a/test/lspPlanTests/CompleteLSPPlanTest.java b/test/lspPlanTests/CompleteLSPPlanTest.java index 00b17895aa9..5b8a347bc30 100644 --- a/test/lspPlanTests/CompleteLSPPlanTest.java +++ b/test/lspPlanTests/CompleteLSPPlanTest.java @@ -20,16 +20,16 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import lsp.LSPPlan; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -41,7 +41,7 @@ public class CompleteLSPPlanTest { private Network network; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private LogisticsSolution completeSolution; @Before @@ -221,7 +221,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); } diff --git a/test/lspReplanningTests/CollectionLSPReplanningTest.java b/test/lspReplanningTests/CollectionLSPReplanningTest.java index 83a3f898bf4..16d15d77d8d 100644 --- a/test/lspReplanningTests/CollectionLSPReplanningTest.java +++ b/test/lspReplanningTests/CollectionLSPReplanningTest.java @@ -28,14 +28,15 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -44,12 +45,12 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplannerImpl; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScorer; -import scoring.LSPScoringModuleImpl; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplannerImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScorer; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; import lspScoringTests.TrinkgeldEventHandler; import lspScoringTests.TrinkgeldInfo; import lspScoringTests.TrinkgeldInfoFunction; @@ -121,7 +122,8 @@ public void initialize() { LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlan collectionPlan = new LSPPlan(assigner); + LSPPlan collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -131,7 +133,7 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); @@ -194,6 +196,7 @@ public void initialize() { @Test public void testCollectionLSPReplanning(){ + System.out.println(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size()); assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() < 20); } diff --git a/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java b/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java index a9d50ac6612..8f5449aa547 100644 --- a/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java +++ b/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java @@ -4,8 +4,9 @@ import lsp.LSP; import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.ShipmentAssigner; -import replanning.LSPPlanStrategyManagerFactory; +import lsp.replanning.LSPPlanStrategyManagerFactory; public class GenericStrategyManagerFactoryImpl implements LSPPlanStrategyManagerFactory { diff --git a/test/lspReplanningTests/TomorrowAssigner.java b/test/lspReplanningTests/TomorrowAssigner.java index c2acf9971ad..ae1eda8fc52 100644 --- a/test/lspReplanningTests/TomorrowAssigner.java +++ b/test/lspReplanningTests/TomorrowAssigner.java @@ -4,7 +4,7 @@ import lsp.LSP; import lsp.ShipmentAssigner; -import shipment.LSPShipment; +import lsp.shipment.LSPShipment; public class TomorrowAssigner implements ShipmentAssigner{ diff --git a/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java b/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java index 9cf07f6ad54..0f42dacca5d 100644 --- a/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java +++ b/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java @@ -10,8 +10,9 @@ import lsp.LSP; import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.ShipmentAssigner; -import shipment.LSPShipment; +import lsp.shipment.LSPShipment; public class TomorrowShipmentAssignerStrategyFactory { diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index b5b21d91cd7..533a3a81a7b 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -32,15 +32,15 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.CollectionServiceEventHandler; -import usecase.CollectionTourEndEventHandler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -48,10 +48,10 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CollectionLSPSchedulingTest { @@ -113,7 +113,8 @@ public void initialize() { LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlan collectionPlan = new LSPPlan(assigner); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -123,7 +124,7 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index 7bd38a2f7f2..70a74fa4fca 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -25,19 +25,19 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -45,17 +45,17 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CompleteLSPSchedulingTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP completeLSP; private Carrier carrier; @@ -239,7 +239,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -254,7 +255,7 @@ public void initialize() { resourcesList.add(distributionAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); completeLSP = completeLSPBuilder.build(); diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java index 69505ab135b..e76431f6f70 100644 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -26,19 +26,19 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -46,16 +46,16 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class FirstReloadLSPSchedulingTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -134,7 +134,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -146,7 +147,7 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java index 78ccc23de21..8798573ffcd 100644 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -26,19 +26,19 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -46,16 +46,16 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class MainRunLSPSchedulingTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -176,7 +176,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -188,7 +189,7 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); resourcesList.add(mainRunAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java index 66b17783048..399d622671d 100644 --- a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java @@ -23,19 +23,19 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -43,16 +43,16 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.AbstractShipmentPlanElement; -import shipment.AbstractShipmentPlanElementComparator; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class SecondReloadLSPSchedulingTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; @@ -196,7 +196,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -211,7 +212,7 @@ public void initialize() { - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java index bbee55fff4e..3aad1bbd429 100644 --- a/test/lspScoringTests/CollectionLSPScoringTest.java +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -27,14 +27,14 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; -import controler.LSPModule; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; @@ -43,11 +43,11 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import replanning.LSPReplanningModuleImpl; -import scoring.LSPScorer; -import scoring.LSPScoringModuleImpl; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScorer; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CollectionLSPScoringTest { @@ -59,6 +59,10 @@ public class CollectionLSPScoringTest { private LogisticsSolutionElement collectionElement; private LSPScorer trinkgeldScorer; private TrinkgeldSimulationTracker trinkgeldTracker; + private TrinkgeldInfo info; + private TrinkgeldInfoFunction function; + private TrinkgeldInfoFunctionValue value; + private int numberOfShipments = 25; @Before public void initialize() { @@ -116,7 +120,8 @@ public void initialize() { LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlan collectionPlan = new LSPPlan(assigner); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -126,15 +131,15 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleSolutionScheduler(resourcesList); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); TrinkgeldEventHandler handler = new TrinkgeldEventHandler(); TrinkgeldInfoFunctionValue value = new TrinkgeldInfoFunctionValue(); - TrinkgeldInfoFunction function = new TrinkgeldInfoFunction(); + function = new TrinkgeldInfoFunction(); function.getValues().add(value); - TrinkgeldInfo info = new TrinkgeldInfo(function); + info = new TrinkgeldInfo(function); trinkgeldTracker = new TrinkgeldSimulationTracker(handler,info); collectionAdapter.addSimulationTracker(trinkgeldTracker); trinkgeldScorer = new TrinkgeldScorer(collectionLSP, trinkgeldTracker); @@ -144,7 +149,7 @@ public void initialize() { Id toLinkId = collectionLinkId; - for(int i = 1; i < 3; i++) { + for(int i = 1; i < (numberOfShipments + 1); i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); Random random = new Random(1); @@ -185,7 +190,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); + config.controler().setLastIteration(25); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -194,8 +199,10 @@ public void initialize() { @Test public void testCollectionLSPScoring() { System.out.println(collectionLSP.getSelectedPlan().getScore()); - assertTrue(collectionLSP.getSelectedPlan().getScore() >=0); - assertTrue(collectionLSP.getSelectedPlan().getScore() <=10); + assertTrue(collectionLSP.getShipments().size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getScore() >0); + assertTrue(collectionLSP.getSelectedPlan().getScore() <=(numberOfShipments*5)); } } diff --git a/test/lspScoringTests/TrinkgeldEventHandler.java b/test/lspScoringTests/TrinkgeldEventHandler.java index 7832b0b2f95..823e5880023 100644 --- a/test/lspScoringTests/TrinkgeldEventHandler.java +++ b/test/lspScoringTests/TrinkgeldEventHandler.java @@ -2,8 +2,10 @@ import java.util.Random; -import events.ServiceCompletedEvent; -import events.ServiceCompletedEventHandler; +import lsp.events.ServiceBeginsEvent; +import lsp.events.ServiceBeginsEventHandler; +import lsp.events.ServiceCompletedEvent; +import lsp.events.ServiceCompletedEventHandler; public class TrinkgeldEventHandler implements ServiceCompletedEventHandler{ @@ -23,6 +25,7 @@ public void reset(int iteration) { @Override public void handleEvent(ServiceCompletedEvent event) { double trinkgeld = trinkgeldRandom.nextDouble() * 5; + System.out.println("ServiceEvent " + trinkgeld); trinkgeldSum += trinkgeld; } diff --git a/test/lspScoringTests/TrinkgeldScorer.java b/test/lspScoringTests/TrinkgeldScorer.java index 046db7599bb..a5841a1f92b 100644 --- a/test/lspScoringTests/TrinkgeldScorer.java +++ b/test/lspScoringTests/TrinkgeldScorer.java @@ -6,7 +6,7 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionValue; -import scoring.LSPScorer; +import lsp.scoring.LSPScorer; public class TrinkgeldScorer implements LSPScorer { @@ -30,9 +30,7 @@ public double scoreCurrentPlan(LSP lsp) { score += trinkgeldValue; } } - } - } return score; } diff --git a/test/lspScoringTests/TrinkgeldSimulationTracker.java b/test/lspScoringTests/TrinkgeldSimulationTracker.java index c92f7e2c70a..5d8241ec8af 100644 --- a/test/lspScoringTests/TrinkgeldSimulationTracker.java +++ b/test/lspScoringTests/TrinkgeldSimulationTracker.java @@ -8,7 +8,7 @@ import lsp.functions.Info; import lsp.functions.InfoFunctionValue; -import tracking.SimulationTracker; +import lsp.tracking.SimulationTracker; public class TrinkgeldSimulationTracker implements SimulationTracker { diff --git a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java index cc62486f1c8..7d193840064 100644 --- a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java +++ b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java @@ -25,13 +25,13 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -39,15 +39,15 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CollectionLSPShipmentAssigmentTest { private Network network; private LogisticsSolution collectionSolution; private ShipmentAssigner assigner; - private LSPPlan collectionPlan; + private LSPPlanImpl collectionPlan; private SolutionScheduler simpleScheduler; private LSP collectionLSP; @@ -103,7 +103,8 @@ public void initialize() { collectionSolution = collectionSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - collectionPlan = new LSPPlan(assigner); + collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); @@ -113,7 +114,7 @@ public void initialize() { ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); diff --git a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java index 06937e56c51..ad922d67c58 100644 --- a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java +++ b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java @@ -25,19 +25,19 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DeterministicShipmentAssigner; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; -import usecase.SimpleSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; import lsp.LSPImpl; -import lsp.LSPPlan; +import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; @@ -45,15 +45,15 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.resources.Resource; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class CompleteLSPShipmentAssignerTest { private Network network; private LogisticsSolution completeSolution; private ShipmentAssigner assigner; - private LSPPlan completePlan; + private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP completeLSP; @@ -235,7 +235,8 @@ public void initialize() { completeSolution = completeSolutionBuilder.build(); assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlan(assigner); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); completePlan.addSolution(completeSolution); LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); @@ -250,7 +251,7 @@ public void initialize() { resourcesList.add(distributionAdapter); - simpleScheduler = new SimpleSolutionScheduler(resourcesList); + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); completeLSP = completeLSPBuilder.build(); diff --git a/test/lspShipmentTest/collectionShipmentBuilderTest.java b/test/lspShipmentTest/collectionShipmentBuilderTest.java index 459c7e222ad..d6108428897 100644 --- a/test/lspShipmentTest/collectionShipmentBuilderTest.java +++ b/test/lspShipmentTest/collectionShipmentBuilderTest.java @@ -17,8 +17,8 @@ import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class collectionShipmentBuilderTest { diff --git a/test/lspShipmentTest/completeShipmentBuilderTest.java b/test/lspShipmentTest/completeShipmentBuilderTest.java index c08d49c843f..139550eb08f 100644 --- a/test/lspShipmentTest/completeShipmentBuilderTest.java +++ b/test/lspShipmentTest/completeShipmentBuilderTest.java @@ -19,8 +19,8 @@ import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class completeShipmentBuilderTest { diff --git a/test/lspShipmentTest/distributionShipmentBuilderTest.java b/test/lspShipmentTest/distributionShipmentBuilderTest.java index be562192fa4..f52e19fbadf 100644 --- a/test/lspShipmentTest/distributionShipmentBuilderTest.java +++ b/test/lspShipmentTest/distributionShipmentBuilderTest.java @@ -19,8 +19,8 @@ import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; -import shipment.LSPShipment; -import shipment.LSPShipmentImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; public class distributionShipmentBuilderTest { diff --git a/test/solutionElementTests/CollectionElementTest.java b/test/solutionElementTests/CollectionElementTest.java index fecb1d7601f..f6369504c17 100644 --- a/test/solutionElementTests/CollectionElementTest.java +++ b/test/solutionElementTests/CollectionElementTest.java @@ -20,8 +20,8 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.resources.Resource; diff --git a/test/solutionElementTests/DistributionElementTest.java b/test/solutionElementTests/DistributionElementTest.java index a97d22056ce..dffc1bca916 100644 --- a/test/solutionElementTests/DistributionElementTest.java +++ b/test/solutionElementTests/DistributionElementTest.java @@ -20,8 +20,8 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.resources.Resource; diff --git a/test/solutionElementTests/FirstReloadElementTest.java b/test/solutionElementTests/FirstReloadElementTest.java index a78c23c9017..e86767168ac 100644 --- a/test/solutionElementTests/FirstReloadElementTest.java +++ b/test/solutionElementTests/FirstReloadElementTest.java @@ -7,8 +7,8 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.resources.Resource; diff --git a/test/solutionElementTests/MainRunElementTest.java b/test/solutionElementTests/MainRunElementTest.java index 19c21d85961..f9cfd215d6a 100644 --- a/test/solutionElementTests/MainRunElementTest.java +++ b/test/solutionElementTests/MainRunElementTest.java @@ -20,8 +20,8 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.resources.Resource; diff --git a/test/solutionElementTests/SecondReloadElementTest.java b/test/solutionElementTests/SecondReloadElementTest.java index 598142ad24c..cd38783e1de 100644 --- a/test/solutionElementTests/SecondReloadElementTest.java +++ b/test/solutionElementTests/SecondReloadElementTest.java @@ -7,8 +7,8 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.resources.Resource; diff --git a/test/solutionTests/CollectionSolutionTest.java b/test/solutionTests/CollectionSolutionTest.java index 30d035fb4a9..28c24ed961e 100644 --- a/test/solutionTests/CollectionSolutionTest.java +++ b/test/solutionTests/CollectionSolutionTest.java @@ -22,8 +22,8 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; diff --git a/test/solutionTests/CompleteSolutionTest.java b/test/solutionTests/CompleteSolutionTest.java index 24d4334fee3..9df359e9434 100644 --- a/test/solutionTests/CompleteSolutionTest.java +++ b/test/solutionTests/CompleteSolutionTest.java @@ -22,14 +22,14 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import usecase.CollectionCarrierAdapter; -import usecase.CollectionCarrierScheduler; -import usecase.DistributionCarrierAdapter; -import usecase.DistributionCarrierScheduler; -import usecase.MainRunCarrierAdapter; -import usecase.MainRunCarrierScheduler; -import usecase.ReloadingPoint; -import usecase.ReloadingPointScheduler; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; From e03eaea34fc0dca9c1ef430c48a3199a01e9253c Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 28 Feb 2018 18:00:22 +0100 Subject: [PATCH 0014/1340] Demand Side added --- .../LSPScoring/CollectionLSPScoringTest.java | 208 ++++++++++++ .../example/LSPScoring/ExampleLSPScoring.java | 5 + .../example/LSPScoring/TipEventHandler.java | 35 ++ examples/example/LSPScoring/TipInfo.java | 41 +++ .../example/LSPScoring/TipInfoFunction.java | 23 ++ .../LSPScoring/TipInfoFunctionValue.java | 35 ++ examples/example/LSPScoring/TipScorer.java | 39 +++ .../LSPScoring/TipSimulationTracker.java | 50 +++ .../ExampleSchedulingOfInitialPlan.java | 192 +++++++++++ examples/examples/ExampleCascadingInfos.java | 5 + examples/examples/ExampleLSPReplanning.java | 5 + .../examples/ExampleMobsimOfSimpleLSP.java | 5 + .../ExampleSchedulingOfTransportChain.java | 5 + .../examples/ExampleSimulationTrackers.java | 5 + .../controler/MutualControlerListener.java | 237 ++++++++++++++ src/demand/controler/MutualModule.java | 114 +++++++ src/demand/controler/SupplyClearer.java | 33 ++ src/demand/controler/SupplyRescheduler.java | 26 ++ src/demand/decoratedLSP/DefaultAssigner.java | 32 ++ src/demand/decoratedLSP/LSPDecorator.java | 20 ++ src/demand/decoratedLSP/LSPPlanDecorator.java | 13 + .../LSPPlanWithOfferTransferrer.java | 89 +++++ src/demand/decoratedLSP/LSPWithOffers.java | 308 ++++++++++++++++++ src/demand/decoratedLSP/LSPsWithOffers.java | 40 +++ .../LogisticsSolutionDecorator.java | 14 + .../LogisticsSolutionWithOffers.java | 195 +++++++++++ src/demand/demandAgent/DemandAgent.java | 15 + src/demand/demandAgent/DemandAgentImpl.java | 67 ++++ src/demand/demandObject/DemandObject.java | 41 +++ src/demand/demandObject/DemandObjectImpl.java | 308 ++++++++++++++++++ src/demand/demandObject/DemandObjects.java | 37 +++ src/demand/demandObject/DemandPlan.java | 78 +++++ .../demandObject/DemandPlanGenerator.java | 7 + src/demand/demandObject/OfferRequester.java | 12 + src/demand/demandObject/ShipperShipment.java | 22 ++ .../mutualReplanning/DemandReplanner.java | 15 + .../LSPWithOffersReplanner.java | 55 ++++ .../MutualReplanningModule.java | 37 +++ .../MutualReplanningModuleImpl.java | 42 +++ .../OfferReplanningStrategyModule.java | 55 ++++ src/demand/offer/DefaultOfferImpl.java | 51 +++ src/demand/offer/Offer.java | 15 + src/demand/offer/OfferFactory.java | 21 ++ src/demand/offer/OfferFactoryImpl.java | 73 +++++ src/demand/offer/OfferTransferrer.java | 16 + src/demand/offer/OfferTransferrerImpl.java | 38 +++ src/demand/offer/OfferUpdater.java | 12 + src/demand/offer/OfferUpdaterImpl.java | 47 +++ src/demand/offer/OfferVisitor.java | 10 + .../offer/RequirementsOfferRequester.java | 30 ++ src/demand/scoring/DemandScorer.java | 10 + src/demand/scoring/DemandScoringModule.java | 8 + .../scoring/DemandScoringModuleImpl.java | 30 ++ .../utilityFunctions/UtilityFunction.java | 11 + test/requirementsCheckerTests/BlueInfo.java | 44 +++ .../BlueInfoFunctionValue.java | 30 ++ .../BlueRequirement.java | 19 ++ .../NonsenseOffer.java | 52 +++ test/requirementsCheckerTests/RedInfo.java | 44 +++ .../RedInfoFunctionValue.java | 30 ++ .../RedRequirement.java | 19 ++ .../RequirementsAssigner.java | 49 +++ .../RequirementsTransferrer.java | 59 ++++ .../assignerRequirementsTest.java | 208 ++++++++++++ .../transferrerRequirementsTest.java | 213 ++++++++++++ .../CollectionServiceHandler.java | 87 +++++ .../CollectionTrackerTest.java | 210 ++++++++++++ test/testLSPWithCostTracker/CostInfo.java | 42 +++ .../CostInfoFunction.java | 31 ++ .../DistanceAndTimeHandler.java | 81 +++++ .../FixedCostFunctionValue.java | 29 ++ .../LinearCostFunctionValue.java | 29 ++ .../LinearCostTracker.java | 102 ++++++ .../TourStartHandler.java | 24 ++ test/testMutualReplanning/LotSizeScorer.java | 21 ++ test/testMutualReplanning/NonsenseOffer.java | 52 +++ .../SimpleOfferRequester.java | 35 ++ 77 files changed, 4447 insertions(+) create mode 100644 examples/example/LSPScoring/CollectionLSPScoringTest.java create mode 100644 examples/example/LSPScoring/ExampleLSPScoring.java create mode 100644 examples/example/LSPScoring/TipEventHandler.java create mode 100644 examples/example/LSPScoring/TipInfo.java create mode 100644 examples/example/LSPScoring/TipInfoFunction.java create mode 100644 examples/example/LSPScoring/TipInfoFunctionValue.java create mode 100644 examples/example/LSPScoring/TipScorer.java create mode 100644 examples/example/LSPScoring/TipSimulationTracker.java create mode 100644 examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java create mode 100644 examples/examples/ExampleCascadingInfos.java create mode 100644 examples/examples/ExampleLSPReplanning.java create mode 100644 examples/examples/ExampleMobsimOfSimpleLSP.java create mode 100644 examples/examples/ExampleSchedulingOfTransportChain.java create mode 100644 examples/examples/ExampleSimulationTrackers.java create mode 100644 src/demand/controler/MutualControlerListener.java create mode 100644 src/demand/controler/MutualModule.java create mode 100644 src/demand/controler/SupplyClearer.java create mode 100644 src/demand/controler/SupplyRescheduler.java create mode 100644 src/demand/decoratedLSP/DefaultAssigner.java create mode 100644 src/demand/decoratedLSP/LSPDecorator.java create mode 100644 src/demand/decoratedLSP/LSPPlanDecorator.java create mode 100644 src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java create mode 100644 src/demand/decoratedLSP/LSPWithOffers.java create mode 100644 src/demand/decoratedLSP/LSPsWithOffers.java create mode 100644 src/demand/decoratedLSP/LogisticsSolutionDecorator.java create mode 100644 src/demand/decoratedLSP/LogisticsSolutionWithOffers.java create mode 100644 src/demand/demandAgent/DemandAgent.java create mode 100644 src/demand/demandAgent/DemandAgentImpl.java create mode 100644 src/demand/demandObject/DemandObject.java create mode 100644 src/demand/demandObject/DemandObjectImpl.java create mode 100644 src/demand/demandObject/DemandObjects.java create mode 100644 src/demand/demandObject/DemandPlan.java create mode 100644 src/demand/demandObject/DemandPlanGenerator.java create mode 100644 src/demand/demandObject/OfferRequester.java create mode 100644 src/demand/demandObject/ShipperShipment.java create mode 100644 src/demand/mutualReplanning/DemandReplanner.java create mode 100644 src/demand/mutualReplanning/LSPWithOffersReplanner.java create mode 100644 src/demand/mutualReplanning/MutualReplanningModule.java create mode 100644 src/demand/mutualReplanning/MutualReplanningModuleImpl.java create mode 100644 src/demand/mutualReplanning/OfferReplanningStrategyModule.java create mode 100644 src/demand/offer/DefaultOfferImpl.java create mode 100644 src/demand/offer/Offer.java create mode 100644 src/demand/offer/OfferFactory.java create mode 100644 src/demand/offer/OfferFactoryImpl.java create mode 100644 src/demand/offer/OfferTransferrer.java create mode 100644 src/demand/offer/OfferTransferrerImpl.java create mode 100644 src/demand/offer/OfferUpdater.java create mode 100644 src/demand/offer/OfferUpdaterImpl.java create mode 100644 src/demand/offer/OfferVisitor.java create mode 100644 src/demand/offer/RequirementsOfferRequester.java create mode 100644 src/demand/scoring/DemandScorer.java create mode 100644 src/demand/scoring/DemandScoringModule.java create mode 100644 src/demand/scoring/DemandScoringModuleImpl.java create mode 100644 src/demand/utilityFunctions/UtilityFunction.java create mode 100644 test/requirementsCheckerTests/BlueInfo.java create mode 100644 test/requirementsCheckerTests/BlueInfoFunctionValue.java create mode 100644 test/requirementsCheckerTests/BlueRequirement.java create mode 100644 test/requirementsCheckerTests/NonsenseOffer.java create mode 100644 test/requirementsCheckerTests/RedInfo.java create mode 100644 test/requirementsCheckerTests/RedInfoFunctionValue.java create mode 100644 test/requirementsCheckerTests/RedRequirement.java create mode 100644 test/requirementsCheckerTests/RequirementsAssigner.java create mode 100644 test/requirementsCheckerTests/RequirementsTransferrer.java create mode 100644 test/requirementsCheckerTests/assignerRequirementsTest.java create mode 100644 test/requirementsCheckerTests/transferrerRequirementsTest.java create mode 100644 test/testLSPWithCostTracker/CollectionServiceHandler.java create mode 100644 test/testLSPWithCostTracker/CollectionTrackerTest.java create mode 100644 test/testLSPWithCostTracker/CostInfo.java create mode 100644 test/testLSPWithCostTracker/CostInfoFunction.java create mode 100644 test/testLSPWithCostTracker/DistanceAndTimeHandler.java create mode 100644 test/testLSPWithCostTracker/FixedCostFunctionValue.java create mode 100644 test/testLSPWithCostTracker/LinearCostFunctionValue.java create mode 100644 test/testLSPWithCostTracker/LinearCostTracker.java create mode 100644 test/testLSPWithCostTracker/TourStartHandler.java create mode 100644 test/testMutualReplanning/LotSizeScorer.java create mode 100644 test/testMutualReplanning/NonsenseOffer.java create mode 100644 test/testMutualReplanning/SimpleOfferRequester.java diff --git a/examples/example/LSPScoring/CollectionLSPScoringTest.java b/examples/example/LSPScoring/CollectionLSPScoringTest.java new file mode 100644 index 00000000000..8b03b9f7e68 --- /dev/null +++ b/examples/example/LSPScoring/CollectionLSPScoringTest.java @@ -0,0 +1,208 @@ +package example.LSPScoring; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScorer; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + + +public class CollectionLSPScoringTest { + + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private LSPScorer trinkgeldScorer; + private TipSimulationTracker trinkgeldTracker; + private TipInfo info; + private TipInfoFunction function; + private TipInfoFunctionValue value; + private int numberOfShipments = 25; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + if (collectionLink == null) { + System.exit(1); + } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + TipEventHandler handler = new TipEventHandler(); + TipInfoFunctionValue value = new TipInfoFunctionValue(); + function = new TipInfoFunction(); + function.getValues().add(value); + info = new TipInfo(function); + trinkgeldTracker = new TipSimulationTracker(handler,info); + collectionAdapter.addSimulationTracker(trinkgeldTracker); + trinkgeldScorer = new TipScorer(collectionLSP, trinkgeldTracker); + collectionLSP.setScorer(trinkgeldScorer); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < (numberOfShipments + 1); i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(25); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPScoring() { + System.out.println(collectionLSP.getSelectedPlan().getScore()); + assertTrue(collectionLSP.getShipments().size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getScore() >0); + assertTrue(collectionLSP.getSelectedPlan().getScore() <=(numberOfShipments*5)); + } + +} diff --git a/examples/example/LSPScoring/ExampleLSPScoring.java b/examples/example/LSPScoring/ExampleLSPScoring.java new file mode 100644 index 00000000000..5d042e72428 --- /dev/null +++ b/examples/example/LSPScoring/ExampleLSPScoring.java @@ -0,0 +1,5 @@ +package example.LSPScoring; + +public class ExampleLSPScoring { + +} diff --git a/examples/example/LSPScoring/TipEventHandler.java b/examples/example/LSPScoring/TipEventHandler.java new file mode 100644 index 00000000000..57d683ce7c3 --- /dev/null +++ b/examples/example/LSPScoring/TipEventHandler.java @@ -0,0 +1,35 @@ +package example.LSPScoring; + +import java.util.Random; + +import lsp.events.ServiceBeginsEvent; +import lsp.events.ServiceBeginsEventHandler; +import lsp.events.ServiceCompletedEvent; +import lsp.events.ServiceCompletedEventHandler; + +public class TipEventHandler implements ServiceCompletedEventHandler{ + + private double trinkgeldSum; + private Random trinkgeldRandom; + + public TipEventHandler() { + trinkgeldRandom = new Random(1); + trinkgeldSum = 0; + } + + @Override + public void reset(int iteration) { + trinkgeldSum = 0; + } + + @Override + public void handleEvent(ServiceCompletedEvent event) { + double trinkgeld = trinkgeldRandom.nextDouble() * 5; + System.out.println("ServiceEvent " + trinkgeld); + trinkgeldSum += trinkgeld; + } + + public double getTrinkgeld() { + return trinkgeldSum; + } +} diff --git a/examples/example/LSPScoring/TipInfo.java b/examples/example/LSPScoring/TipInfo.java new file mode 100644 index 00000000000..688cf57e566 --- /dev/null +++ b/examples/example/LSPScoring/TipInfo.java @@ -0,0 +1,41 @@ +package example.LSPScoring; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; + +public class TipInfo extends Info{ + + private TipInfoFunction function; + private String name = "TRINKGELDINFO"; + + public TipInfo (TipInfoFunction function) { + this.function = function; + } + + @Override + public String getName() { + return name; + } + + @Override + public InfoFunction getFunction() { + return function; + } + + @Override + public double getFromTime() { + return 0; + } + + @Override + public double getToTime() { + return Double.MAX_VALUE; + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/examples/example/LSPScoring/TipInfoFunction.java b/examples/example/LSPScoring/TipInfoFunction.java new file mode 100644 index 00000000000..82a0b36960a --- /dev/null +++ b/examples/example/LSPScoring/TipInfoFunction.java @@ -0,0 +1,23 @@ +package example.LSPScoring; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; + +public class TipInfoFunction implements InfoFunction{ + + private Collection values; + + public TipInfoFunction() { + this.values = new ArrayList(); + } + + + @Override + public Collection getValues() { + return values; + } + +} diff --git a/examples/example/LSPScoring/TipInfoFunctionValue.java b/examples/example/LSPScoring/TipInfoFunctionValue.java new file mode 100644 index 00000000000..d6afbfab183 --- /dev/null +++ b/examples/example/LSPScoring/TipInfoFunctionValue.java @@ -0,0 +1,35 @@ +package example.LSPScoring; + +import lsp.functions.InfoFunctionValue; + +public class TipInfoFunctionValue implements InfoFunctionValue{ + + private String name = "TRINKGELD IN EUR"; + private Class type; + private double value; + + public TipInfoFunctionValue() { + this.type = double.class; + } + + @Override + public String getName() { + return name; + } + + @Override + public Class getDataType() { + return type; + } + + @Override + public String getValue() { + return String.valueOf(value); + } + + @Override + public void setValue(String value) { + this.value = Double.valueOf(value).doubleValue(); + } + +} diff --git a/examples/example/LSPScoring/TipScorer.java b/examples/example/LSPScoring/TipScorer.java new file mode 100644 index 00000000000..33adc7bdf0f --- /dev/null +++ b/examples/example/LSPScoring/TipScorer.java @@ -0,0 +1,39 @@ +package example.LSPScoring; + +import org.matsim.api.core.v01.population.HasPlansAndId; + +import lsp.LSP; +import lsp.functions.Info; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; +import lsp.scoring.LSPScorer; + +public class TipScorer implements LSPScorer { + + private LSP lsp; + private TipSimulationTracker tracker; + + public TipScorer(LSP lsp, TipSimulationTracker tracker) { + this.lsp = lsp; + this.tracker = tracker; + } + + @Override + public double scoreCurrentPlan(LSP lsp) { + double score = 0; + for(Info info : tracker.getInfos()) { + if(info.getName() == "TRINKGELDINFO") { + InfoFunction function = info.getFunction(); + for(InfoFunctionValue value : function.getValues()) { + if(value.getName() == "TRINKGELD IN EUR") { + double trinkgeldValue = Double.parseDouble(value.getValue()); + score += trinkgeldValue; + } + } + } + } + return score; + } + + +} diff --git a/examples/example/LSPScoring/TipSimulationTracker.java b/examples/example/LSPScoring/TipSimulationTracker.java new file mode 100644 index 00000000000..363e17de872 --- /dev/null +++ b/examples/example/LSPScoring/TipSimulationTracker.java @@ -0,0 +1,50 @@ +package example.LSPScoring; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.tracking.SimulationTracker; + +public class TipSimulationTracker implements SimulationTracker { + + private TipEventHandler handler; + private Info info; + + public TipSimulationTracker(TipEventHandler handler, Info info) { + this.info = info; + this.handler = handler; + } + + @Override + public Collection getEventHandlers() { + ArrayList handlers = new ArrayList(); + handlers.add(handler); + return handlers; + } + + @Override + public Collection getInfos() { + ArrayList infos = new ArrayList(); + infos.add(info); + return infos; + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + double trinkgeld = handler.getTrinkgeld(); + InfoFunctionValue value = info.getFunction().getValues().iterator().next(); + value.setValue(String.valueOf(trinkgeld)); + } + + @Override + public void reset() { + // TODO Auto-generated method stub + } + + +} diff --git a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java new file mode 100644 index 00000000000..e8027c8bb0a --- /dev/null +++ b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java @@ -0,0 +1,192 @@ +package example.initialPlans; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.usecase.CollectionCarrierAdapter.Builder; + +public class ExampleSchedulingOfInitialPlan { + + + + public static LSP createInitialLSP(Network network) { + + //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + //The Adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + + //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + + return collectionLSPBuilder.build(); + + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id toLinkId = collectionLinkId; + + //Create five LSPShipments that are located in the left half of the network. + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + public static void main(String [] args) { + + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createInitialLSP(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + //schedule the LSP with the shipments and according to the scheduler of the Resource + lsp.scheduleSoultions(); + + //print the schedules for the assigned LSPShipments + for(LSPShipment shipment : shipments) { + System.out.println("Shipment: " + shipment.getId()); + for(AbstractShipmentPlanElement element : shipment.getSchedule().getPlanElements().values()) { + System.out.println("Solution Id: " + element.getSolutionElement().getLogisticsSolution().getId() + + " SolutionElement Id: " + element.getSolutionElement().getId() + + " Resource Id: " + element.getResourceId() + + " Type: " + element.getElementType() + + " Start Time: " + element.getStartTime() + + " End Time: " + element.getEndTime()); + } + System.out.println(); + } + } +} diff --git a/examples/examples/ExampleCascadingInfos.java b/examples/examples/ExampleCascadingInfos.java new file mode 100644 index 00000000000..5178e727256 --- /dev/null +++ b/examples/examples/ExampleCascadingInfos.java @@ -0,0 +1,5 @@ +package examples; + +public class ExampleCascadingInfos { + +} diff --git a/examples/examples/ExampleLSPReplanning.java b/examples/examples/ExampleLSPReplanning.java new file mode 100644 index 00000000000..7500d8f4bb3 --- /dev/null +++ b/examples/examples/ExampleLSPReplanning.java @@ -0,0 +1,5 @@ +package examples; + +public class ExampleLSPReplanning { + +} diff --git a/examples/examples/ExampleMobsimOfSimpleLSP.java b/examples/examples/ExampleMobsimOfSimpleLSP.java new file mode 100644 index 00000000000..1cca31889a1 --- /dev/null +++ b/examples/examples/ExampleMobsimOfSimpleLSP.java @@ -0,0 +1,5 @@ +package examples; + +public class ExampleMobsimOfSimpleLSP { + +} diff --git a/examples/examples/ExampleSchedulingOfTransportChain.java b/examples/examples/ExampleSchedulingOfTransportChain.java new file mode 100644 index 00000000000..e65278d21b2 --- /dev/null +++ b/examples/examples/ExampleSchedulingOfTransportChain.java @@ -0,0 +1,5 @@ +package examples; + +public class ExampleSchedulingOfTransportChain { + +} diff --git a/examples/examples/ExampleSimulationTrackers.java b/examples/examples/ExampleSimulationTrackers.java new file mode 100644 index 00000000000..800252bd36c --- /dev/null +++ b/examples/examples/ExampleSimulationTrackers.java @@ -0,0 +1,5 @@ +package examples; + +public class ExampleSimulationTrackers { + +} diff --git a/src/demand/controler/MutualControlerListener.java b/src/demand/controler/MutualControlerListener.java new file mode 100644 index 00000000000..dd48cf2ffed --- /dev/null +++ b/src/demand/controler/MutualControlerListener.java @@ -0,0 +1,237 @@ +package demand.controler; + +import java.util.ArrayList; +import javax.inject.Inject; + +import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.Carriers; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.controler.events.BeforeMobsimEvent; +import org.matsim.core.controler.events.IterationEndsEvent; +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.controler.events.ScoringEvent; +import org.matsim.core.controler.listener.AfterMobsimListener; +import org.matsim.core.controler.listener.BeforeMobsimListener; +import org.matsim.core.controler.listener.IterationEndsListener; +import org.matsim.core.controler.listener.ReplanningListener; +import org.matsim.core.controler.listener.ScoringListener; +import org.matsim.core.events.handler.EventHandler; + +import demand.decoratedLSP.LSPsWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; +import demand.mutualReplanning.MutualReplanningModule; +import demand.scoring.DemandScoringModule; +import lsp.LSP; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.controler.FreightControlerListener; +import lsp.functions.Info; +import lsp.mobsim.CarrierResourceTracker; +import lsp.resources.CarrierResource; +import lsp.scoring.LSPScoringModule; +import lsp.shipment.LSPShipment; +import lsp.tracking.SimulationTracker; + +public class MutualControlerListener implements FreightControlerListener, BeforeMobsimListener, AfterMobsimListener, ScoringListener, +ReplanningListener, IterationEndsListener { + + private CarrierResourceTracker carrierResourceTracker; + private Carriers carriers; + private LSPsWithOffers lsps; + private DemandObjects demandObjects; + private DemandScoringModule demandScoringModule; + private LSPScoringModule lspScoringModule; + private MutualReplanningModule replanningModule; + + + private ArrayList registeredHandlers; + + + @Inject EventsManager eventsManager; + @Inject Network network; + + + @Inject + protected MutualControlerListener(LSPsWithOffers lsps, DemandObjects demandObjects, DemandScoringModule demandScoringModule, LSPScoringModule lspScoringModule, MutualReplanningModule replanningModule) { + this.lsps = lsps; + this.demandObjects = demandObjects; + this.demandScoringModule = demandScoringModule; + this.lspScoringModule = lspScoringModule; + this.replanningModule = replanningModule; + this.carriers = getCarriers(); + } + + public CarrierResourceTracker getCarrierResourceTracker() { + return carrierResourceTracker; + } + + @Override + public void notifyIterationEnds(IterationEndsEvent event) { + + SupplyClearer supplyClearer = new SupplyClearer(lsps); + supplyClearer.notifyIterationEnds(event); + + for(EventHandler handler : registeredHandlers) { + eventsManager.removeHandler(handler); + } + + for(LSP lsp : lsps.getLSPs().values()) { + for(LSPShipment shipment : lsp.getShipments()) { + shipment.getEventHandlers().clear(); + } + + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(EventHandler handler : solution.getEventHandlers()) { + handler.reset(event.getIteration()); + } + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(EventHandler handler : element.getEventHandlers()) { + handler.reset(event.getIteration()); + } + for(EventHandler handler : element.getResource().getEventHandlers()) { + handler.reset(event.getIteration()); + } + } + } + } + + } + + @Override + public void notifyReplanning(ReplanningEvent event) { + replanningModule.replan(event); + } + + @Override + public void notifyScoring(ScoringEvent event) { + boolean score = true; + for(LSP lsp : lsps.getLSPs().values()) { + if(lsp.getScorer() == null) { + score = false; + } + if(score == true) { + lspScoringModule.scoreLSPs(); + } + } + + for(DemandObject demandObject : demandObjects.getDemandObjects().values()) { + if(demandObject.getScorer() == null) { + score = false; + } + if(score == true) { + demandScoringModule.scoreDemandObjects(); + } + } + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + eventsManager.removeHandler(carrierResourceTracker); + + ArrayList alreadyUpdatedTrackers = new ArrayList(); + for(LSP lsp : lsps.getLSPs().values()) { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(SimulationTracker tracker : element.getResource().getSimulationTrackers()) { + if(!alreadyUpdatedTrackers.contains(tracker)) { + tracker.notifyAfterMobsim(event); + alreadyUpdatedTrackers.add(tracker); + tracker.reset(); + } + } + for(SimulationTracker tracker : element.getSimulationTrackers()) { + tracker.notifyAfterMobsim(event); + tracker.reset(); + } + } + for(SimulationTracker tracker : solution.getSimulationTrackers()) { + tracker.notifyAfterMobsim(event); + tracker.reset(); + } + } + } + + for(LSP lsp : lsps.getLSPs().values()) { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(Info info : element.getInfos()) { + info.update(); + } + } + for(Info info : solution.getInfos()) { + info.update(); + } + } + } + + } + + @Override + public void notifyBeforeMobsim(BeforeMobsimEvent event) { + SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); + rescheduler.notifyBeforeMobsim(event); + + carrierResourceTracker = new CarrierResourceTracker(carriers, network, this); + eventsManager.addHandler(carrierResourceTracker); + registeredHandlers = new ArrayList(); + + for(LSP lsp : lsps.getLSPs().values()) { + for(LSPShipment shipment : lsp.getShipments()) { + for(EventHandler handler : shipment.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + } + LSPPlan selectedPlan = lsp.getSelectedPlan(); + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + for(EventHandler handler : solution.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(EventHandler handler : element.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + ArrayList resourceHandlers = (ArrayList)element.getResource().getEventHandlers(); + for(EventHandler handler : resourceHandlers) { + if(!registeredHandlers.contains(handler)) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + } + } + } + } + } + + public void processEvent(Event event){ + eventsManager.processEvent(event); + } + + private Carriers getCarriers() { + Carriers carriers = new Carriers(); + for(LSP lsp : lsps.getLSPs().values()) { + LSPPlan selectedPlan = lsp.getSelectedPlan(); + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(element.getResource() instanceof CarrierResource) { + + CarrierResource carrierResource = (CarrierResource) element.getResource(); + Carrier carrier = carrierResource.getCarrier(); + if(!carriers.getCarriers().containsKey(carrier.getId())) { + carriers.addCarrier(carrier); + } + } + } + } + } + return carriers; + } + +} diff --git a/src/demand/controler/MutualModule.java b/src/demand/controler/MutualModule.java new file mode 100644 index 00000000000..f2c2a41149e --- /dev/null +++ b/src/demand/controler/MutualModule.java @@ -0,0 +1,114 @@ +package demand.controler; + +import java.util.Collection; + +import org.matsim.contrib.freight.CarrierConfig; +import org.matsim.core.controler.AbstractModule; + +import com.google.inject.Provides; +import com.google.inject.multibindings.Multibinder; + +import demand.decoratedLSP.LSPsWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; +import demand.mutualReplanning.MutualReplanningModule; +import demand.scoring.DemandScoringModule; +import lsp.mobsim.CarrierResourceTracker; +import lsp.mobsim.FreightQSimFactory; +import lsp.scoring.LSPScoringModule; + +public class MutualModule extends AbstractModule{ + + private LSPsWithOffers lsps; + private DemandObjects demandObjects; + private DemandScoringModule demandScoringModule; + private LSPScoringModule lspScoringModule; + private MutualReplanningModule replanningModule; + + private CarrierConfig carrierConfig = new CarrierConfig(); + + + + public static class Builder{ + + private LSPsWithOffers lsps; + private DemandObjects demandObjects; + private DemandScoringModule demandScoringModule; + private LSPScoringModule lspScoringModule; + private MutualReplanningModule replanningModule; + + public Builder newInstance() { + return new Builder(); + } + + public Builder setLsps(LSPsWithOffers lsps) { + this.lsps = lsps; + return this; + } + + public Builder setDemandScoringModule(DemandScoringModule demandScoringModule) { + this.demandScoringModule = demandScoringModule; + return this; + } + + public Builder setLSPScoringModule(LSPScoringModule lspScoringModule) { + this.lspScoringModule = lspScoringModule; + return this; + } + + public Builder setMutualReplanningModule(MutualReplanningModule replanningModule) { + this.replanningModule = replanningModule; + return this; + } + + public Builder setDemandObjects(DemandObjects demandObjects) { + this.demandObjects = demandObjects; + return this; + } + + public MutualModule build() { + return new MutualModule(this); + } + } + + private MutualModule(Builder builder) { + this.lsps = builder.lsps; + this.demandObjects = builder.demandObjects; + this.demandScoringModule = builder.demandScoringModule; + this.lspScoringModule = builder.lspScoringModule; + this.replanningModule = builder.replanningModule; + } + + + @Override + public void install() { + bind(CarrierConfig.class).toInstance(carrierConfig); + bind(LSPsWithOffers.class).toInstance(lsps); + bind(DemandObjects.class).toInstance(demandObjects); + + if(replanningModule != null) { + bind(MutualReplanningModule.class).toInstance(replanningModule); + } + if(demandScoringModule != null) { + bind(DemandScoringModule.class).toInstance(demandScoringModule); + } + if(lspScoringModule != null) { + bind(LSPScoringModule.class).toInstance(lspScoringModule); + } + bind(MutualControlerListener.class).asEagerSingleton(); + addControlerListenerBinding().to(MutualControlerListener.class); + bindMobsim().toProvider(FreightQSimFactory.class); + + } + + + @Provides + CarrierResourceTracker provideCarrierResourceTracker(MutualControlerListener mutualControlerListener) { + return mutualControlerListener.getCarrierResourceTracker(); + } + + public void setPhysicallyEnforceTimeWindowBeginnings(boolean physicallyEnforceTimeWindowBeginnings) { + this.carrierConfig.setPhysicallyEnforceTimeWindowBeginnings(physicallyEnforceTimeWindowBeginnings); + } + +} diff --git a/src/demand/controler/SupplyClearer.java b/src/demand/controler/SupplyClearer.java new file mode 100644 index 00000000000..53cd95fcc34 --- /dev/null +++ b/src/demand/controler/SupplyClearer.java @@ -0,0 +1,33 @@ +package demand.controler; + +import org.matsim.core.controler.events.IterationEndsEvent; +import org.matsim.core.controler.listener.IterationEndsListener; + +import demand.decoratedLSP.LSPsWithOffers; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; + +public class SupplyClearer implements IterationEndsListener{ + + private LSPsWithOffers lsps; + + public SupplyClearer(LSPsWithOffers lsps) { + this.lsps = lsps; + } + + @Override + public void notifyIterationEnds(IterationEndsEvent arg0) { + for(LSP lsp : lsps.getLSPs().values()){ + lsp.getShipments().clear(); + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + solution.getShipments().clear(); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + element.getIncomingShipments().clear(); + element.getOutgoingShipments().clear(); + } + } + } + } + +} diff --git a/src/demand/controler/SupplyRescheduler.java b/src/demand/controler/SupplyRescheduler.java new file mode 100644 index 00000000000..0bd6d2c2665 --- /dev/null +++ b/src/demand/controler/SupplyRescheduler.java @@ -0,0 +1,26 @@ +package demand.controler; + +import org.matsim.core.controler.events.BeforeMobsimEvent; +import org.matsim.core.controler.listener.BeforeMobsimListener; + +import demand.decoratedLSP.LSPsWithOffers; +import lsp.LSP; + + +public class SupplyRescheduler implements BeforeMobsimListener{ + + private LSPsWithOffers lsps; + + public SupplyRescheduler(LSPsWithOffers lsps) { + this.lsps = lsps; + } + + + public void notifyBeforeMobsim(BeforeMobsimEvent arg0) { + if(arg0.getIteration() != 0) { + for(LSP lsp : lsps.getLSPs().values()){ + lsp.scheduleSoultions(); + } + } + } +} diff --git a/src/demand/decoratedLSP/DefaultAssigner.java b/src/demand/decoratedLSP/DefaultAssigner.java new file mode 100644 index 00000000000..4453a3efd5e --- /dev/null +++ b/src/demand/decoratedLSP/DefaultAssigner.java @@ -0,0 +1,32 @@ +package demand.decoratedLSP; + +import lsp.LSP; +import lsp.ShipmentAssigner; +import lsp.shipment.LSPShipment; + +public class DefaultAssigner implements ShipmentAssigner{ + + private LSP lsp; + + public DefaultAssigner (LSP lsp) { + this.lsp = lsp; + } + + @Override + public void assignShipment(LSPShipment shipment) { + //Has to be empty, as an LSPWithOffers does not assign with the assigner. + //This job is done by the OfferTransferrer who gives the right solution in the offer + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + + } + + @Override + public LSP getLSP() { + return lsp; + } + +} diff --git a/src/demand/decoratedLSP/LSPDecorator.java b/src/demand/decoratedLSP/LSPDecorator.java new file mode 100644 index 00000000000..c5d6f93ebbd --- /dev/null +++ b/src/demand/decoratedLSP/LSPDecorator.java @@ -0,0 +1,20 @@ +package demand.decoratedLSP; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.controler.events.ReplanningEvent; + +import demand.demandObject.DemandObject; +import demand.offer.Offer; +import demand.offer.OfferTransferrer; +import demand.offer.OfferUpdater; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.shipment.LSPShipment; + +public interface LSPDecorator extends LSP { + + public Offer getOffer(DemandObject object, String type, Id solutionId); + public void assignShipmentToSolution(LSPShipment shipment, Id id); + public OfferUpdater getOfferUpdater(); + public void setOfferUpdater(OfferUpdater offerUpdater); +} diff --git a/src/demand/decoratedLSP/LSPPlanDecorator.java b/src/demand/decoratedLSP/LSPPlanDecorator.java new file mode 100644 index 00000000000..79e0e2c4146 --- /dev/null +++ b/src/demand/decoratedLSP/LSPPlanDecorator.java @@ -0,0 +1,13 @@ +package demand.decoratedLSP; + +import demand.offer.OfferTransferrer; +import demand.offer.OfferUpdater; +import lsp.LSPPlan; + +public interface LSPPlanDecorator extends LSPPlan{ + + public void setOfferTransferrer(OfferTransferrer transferrer); + public OfferTransferrer getOfferTransferrer(); + + +} diff --git a/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java b/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java new file mode 100644 index 00000000000..633896af061 --- /dev/null +++ b/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java @@ -0,0 +1,89 @@ +package demand.decoratedLSP; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.offer.OfferTransferrer; +import demand.offer.OfferUpdater; +import lsp.LSP; +import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.ShipmentAssigner; + +public class LSPPlanWithOfferTransferrer implements LSPPlanDecorator{ + + private LSPDecorator lsp; + private double score; + private Collection solutions; + private ShipmentAssigner assigner; + private OfferTransferrer transferrer; + + public LSPPlanWithOfferTransferrer() { + this.solutions = new ArrayList(); + this.assigner = new DefaultAssigner(this.lsp); + } + + @Override + public void addSolution(LogisticsSolution solution) { + try { + LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; + this.solutions.add(solutionDecorator); + solution.setLSP(this.lsp); + } + catch(ClassCastException e) { + System.out.println("The class " + this.toString() + " expects an LogisticsSolutionDecorator and not any other implementation of LogisticsSolution"); + System.exit(1); + } + } + + @Override + public Collection getSolutions() { + return solutions; + } + + @Override + public ShipmentAssigner getAssigner() { + return assigner; + } + + @Override + public void setAssigner(ShipmentAssigner assigner) { + + } + + @Override + public void setLSP(LSP lsp) { + try { + this.lsp = (LSPDecorator) lsp; + } + catch(ClassCastException e) { + System.out.println("The class " + this.toString() + " expects an LSPDecorator and not any other implementation of LSP"); + System.exit(1); + } + } + + @Override + public LSP getLsp() { + return lsp; + } + + @Override + public void setScore(Double score) { + this.score = score; + } + + @Override + public Double getScore() { + return score; + } + + public OfferTransferrer getOfferTransferrer() { + return transferrer; + } + + public void setOfferTransferrer(OfferTransferrer offerTransferrer) { + this.transferrer = offerTransferrer; + this.transferrer.setLSP(lsp); + } + +} diff --git a/src/demand/decoratedLSP/LSPWithOffers.java b/src/demand/decoratedLSP/LSPWithOffers.java new file mode 100644 index 00000000000..d7f5f9e085f --- /dev/null +++ b/src/demand/decoratedLSP/LSPWithOffers.java @@ -0,0 +1,308 @@ +package demand.decoratedLSP; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.matsim.api.core.v01.Id; + +import demand.demandObject.DemandObject; +import demand.offer.Offer; +import demand.offer.OfferTransferrer; +import demand.offer.OfferTransferrerImpl; +import demand.offer.OfferUpdater; +import lsp.LogisticsSolutionImpl; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.SolutionScheduler; +import lsp.LSPImpl.Builder; +import lsp.replanning.LSPReplanner; +import lsp.resources.Resource; +import lsp.scoring.LSPScorer; +import lsp.shipment.LSPShipment; + +public class LSPWithOffers implements LSPDecorator { + + private Id id; + private Collection shipments; + private ArrayList plans; + private SolutionScheduler solutionScheduler; + private LSPPlanDecorator selectedPlan; + private Collection resources; + private LSPScorer scorer; + private LSPReplanner replanner; + private OfferUpdater offerUpdater; + + public static class Builder{ + private Id id; + private SolutionScheduler solutionScheduler; + private LSPPlanDecorator initialPlan; + private Collection resources; + private LSPScorer scorer; + private LSPReplanner replanner; + private OfferUpdater offerUpdater; + + + public static Builder getInstance(){ + return new Builder(); + } + + private Builder(){ + this.resources = new ArrayList(); + + } + + public Builder setSolutionScheduler(SolutionScheduler solutionScheduler){ + this.solutionScheduler = solutionScheduler; + return this; + } + + public Builder setSolutionScorer(LSPScorer scorer){ + this.scorer = scorer; + return this; + } + + public Builder setReplanner(LSPReplanner replanner){ + this.replanner= replanner; + return this; + } + + public Builder setOfferUpdater(OfferUpdater offerUpdater){ + this.offerUpdater= offerUpdater; + return this; + } + + public Builder setInitialPlan(LSPPlanDecorator plan){ + this.initialPlan = plan; + for(LogisticsSolution solution : plan.getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(!resources.contains(element.getResource())) { + resources.add(element.getResource()); + } + } + } + return this; + } + + public Builder setId(Id id){ + this.id = id; + return this; + } + + public LSPWithOffers build(){ + return new LSPWithOffers(this); + } + + } + + private LSPWithOffers(LSPWithOffers.Builder builder){ + this.shipments = new ArrayList(); + this.plans= new ArrayList(); + this.id = builder.id; + this.solutionScheduler = builder.solutionScheduler; + this.solutionScheduler.setLSP(this); + builder.initialPlan.setLSP(this); + this.selectedPlan=builder.initialPlan; + this.plans.add(builder.initialPlan); + this.selectedPlan.setLSP(this); + this.selectedPlan.getOfferTransferrer().setLSP(this); + this.resources = builder.resources; + this.scorer = builder.scorer; + this.replanner = builder.replanner; + this.offerUpdater = builder.offerUpdater; + if(offerUpdater != null) { + offerUpdater.setLSP(this); + } + } + + @Override + public Id getId() { + return id; + } + + @Override + public Collection getShipments() { + return shipments; + } + + @Override + public void scheduleSoultions() { + solutionScheduler.scheduleSolutions(); + } + + @Override + public ArrayList getPlans() { + for(LSPPlan plan : plans) { + plan.setLSP(this); + for(LogisticsSolution solution : plan.getSolutions()) { + if(solution instanceof LogisticsSolutionWithOffers) { + LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; + solutionWithOffers.setLSP(this); + solutionWithOffers.getOfferFactory().setLSP(this); + for(Offer offer : solutionWithOffers.getOfferFactory().getOffers()) { + offer.setLSP(this); + } + } + } + } + return plans; + } + + @Override + public Collection getResources() { + return resources; + } + + @Override + public LSPPlan getSelectedPlan() { + selectedPlan.setLSP(this); + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + if(solution instanceof LogisticsSolutionWithOffers) { + LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; + solutionWithOffers.setLSP(this); + solutionWithOffers.getOfferFactory().setLSP(this); + } + } + return selectedPlan; + } + + @Override + public void setSelectedPlan(LSPPlan plan) { + try { + plan.setLSP(this); + this.selectedPlan = (LSPPlanDecorator) plan; + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + if(solution instanceof LogisticsSolutionWithOffers) { + LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; + solutionWithOffers.setLSP(this); + solutionWithOffers.getOfferFactory().setLSP(this); + } + } + if(!plans.contains(selectedPlan)) { + plans.add(selectedPlan); + } + } + catch(ClassCastException e) { + System.out.println("The class " + this.toString() + " expects an LSPPlanDecorator and not any other implementation of LSPPlan"); + System.exit(1); + } + } + + @Override + public void scoreSelectedPlan() { + double score = scorer.scoreCurrentPlan(this); + this.selectedPlan.setScore(score); + } + + @Override + public void assignShipmentToLSP(LSPShipment shipment) { + //remains empty, as assignment is done via the OfferTransferrer + } + + @Override + public LSPScorer getScorer() { + return scorer; + } + + @Override + public void setScorer(LSPScorer scorer) { + this.scorer = scorer; + } + + @Override + public boolean addPlan(LSPPlan p) { + try { + LSPPlanDecorator plan = (LSPPlanDecorator) p; + for(LogisticsSolution solution : plan.getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(!resources.contains(element.getResource())) { + resources.add(element.getResource()); + } + } + } + return plans.add(plan); + } + catch(ClassCastException e) { + System.out.println("The class " + this.toString() + " expects an LSPPlanDecorator and not any other implementation of LSPPlan"); + System.exit(1); + } + return false; + } + + @Override + public boolean removePlan(LSPPlan plan) { + if(plans.contains(plan)) { + plans.remove(plan); + return true; + } + else { + return false; + } + } + + @Override + public LSPPlan createCopyOfSelectedPlanAndMakeSelected() { + LSPPlanDecorator newPlan = LSPWithOffers.copyPlan(this.selectedPlan) ; + this.setSelectedPlan( newPlan ) ; + return newPlan ; + } + + @Override + public Offer getOffer(DemandObject object, String type, Id solutionId) { + return selectedPlan.getOfferTransferrer().transferOffer(object, type, solutionId); + } + + @Override + public void assignShipmentToSolution(LSPShipment shipment, Id id) { + assignShipmentToLSP(shipment); + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + if(solution.getId() == id) { + solution.assignShipment(shipment); + } + } + } + + @Override + public LSPReplanner getReplanner() { + return replanner; + } + + @Override + public void setReplanner(LSPReplanner replanner) { + this.replanner = replanner; + } + + @Override + public OfferUpdater getOfferUpdater() { + return offerUpdater; + } + + @Override + public void setOfferUpdater(OfferUpdater offerUpdater) { + this.offerUpdater = offerUpdater; + } + + public static LSPPlanDecorator copyPlan(LSPPlanDecorator plan2copy) { + List copiedSolutions = new ArrayList(); + for (LogisticsSolution solution : plan2copy.getSolutions()) { + LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; + LogisticsSolutionDecorator copiedSolution = LogisticsSolutionWithOffers.Builder.newInstance(solutionDecorator.getId()).build(); + copiedSolution.getSolutionElements().addAll(solutionDecorator.getSolutionElements()); + copiedSolution.setOfferFactory(solutionDecorator.getOfferFactory()); + copiedSolutions.add(copiedSolution); + } + LSPPlanDecorator copiedPlan = new LSPPlanWithOfferTransferrer(); + copiedPlan.setOfferTransferrer(plan2copy.getOfferTransferrer()); + copiedPlan.setLSP(plan2copy.getLsp()); + double initialScoreOfCopiedPlan = plan2copy.getScore(); + copiedPlan.setScore(initialScoreOfCopiedPlan); + copiedPlan.getSolutions().addAll(copiedSolutions); + return copiedPlan; + } + + +} diff --git a/src/demand/decoratedLSP/LSPsWithOffers.java b/src/demand/decoratedLSP/LSPsWithOffers.java new file mode 100644 index 00000000000..f0fdf0754b1 --- /dev/null +++ b/src/demand/decoratedLSP/LSPsWithOffers.java @@ -0,0 +1,40 @@ +package demand.decoratedLSP; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.matsim.api.core.v01.Id; + +import lsp.LSP; + + + +public class LSPsWithOffers { + + private Map, LSPWithOffers> lsps = new HashMap<>(); + + public LSPsWithOffers(Collection lsps) { + makeMap(lsps); + } + + private void makeMap(Collection lsps) { + for (LSPWithOffers c : lsps) { + this.lsps.put(c.getId(), c); + } + } + + public LSPsWithOffers() { + + } + + public Map, LSPWithOffers> getLSPs() { + return lsps; + } + + public void addLSP(LSPWithOffers lsp) { + if(!lsps.containsKey(lsp.getId())){ + lsps.put(lsp.getId(), lsp); + } + } +} diff --git a/src/demand/decoratedLSP/LogisticsSolutionDecorator.java b/src/demand/decoratedLSP/LogisticsSolutionDecorator.java new file mode 100644 index 00000000000..0710f5500bf --- /dev/null +++ b/src/demand/decoratedLSP/LogisticsSolutionDecorator.java @@ -0,0 +1,14 @@ +package demand.decoratedLSP; + +import demand.demandObject.DemandObject; +import demand.offer.Offer; +import demand.offer.OfferFactory; +import lsp.LogisticsSolution; + +public interface LogisticsSolutionDecorator extends LogisticsSolution { + + public Offer getOffer(DemandObject object, String type); + public void setOfferFactory(OfferFactory factory); + public OfferFactory getOfferFactory(); + +} diff --git a/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java b/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java new file mode 100644 index 00000000000..02b5f34cdf8 --- /dev/null +++ b/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java @@ -0,0 +1,195 @@ +package demand.decoratedLSP; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import demand.demandObject.DemandObject; +import demand.offer.Offer; +import demand.offer.OfferFactory; +import lsp.functions.Info; +import lsp.LogisticsSolutionImpl; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionImpl.Builder; +import lsp.shipment.LSPShipment; +import lsp.tracking.SimulationTracker; + +public class LogisticsSolutionWithOffers implements LogisticsSolutionDecorator { + + private Id id; + private LSPWithOffers lsp; + private Collection solutionElements; + private Collection shipments; + private Collection solutionInfos; + private Collection eventHandlers; + private Collectiontrackers; + private EventsManager eventsManager; + private OfferFactory offerFactory; + + public static class Builder{ + private Id id; + private Collection elements; + private Collection solutionInfos; + private Collection eventHandlers; + private Collectiontrackers; + private OfferFactory offerFactory; + + public static Builder newInstance(Idid){ + return new Builder(id); + } + + private Builder(Id id){ + this.elements = new ArrayList(); + this.solutionInfos = new ArrayList(); + this.eventHandlers = new ArrayList(); + this.trackers = new ArrayList(); + this.id = id; + } + + public Builder addSolutionElement(LogisticsSolutionElement element){ + elements.add(element); + return this; + } + + public Builder addInfo(Info info) { + solutionInfos.add(info); + return this; + } + + public Builder addEventHandler(EventHandler handler) { + eventHandlers.add(handler); + return this; + } + + public Builder addTracker(SimulationTracker tracker) { + trackers.add(tracker); + return this; + } + + public Builder addOfferFactory(OfferFactory offerFactory) { + this.offerFactory = offerFactory; + return this; + } + + public LogisticsSolutionWithOffers build(){ + return new LogisticsSolutionWithOffers(this); + } + } + + + private LogisticsSolutionWithOffers(LogisticsSolutionWithOffers.Builder builder){ + this.id = builder.id; + this.solutionElements = builder.elements; + for(LogisticsSolutionElement element : this.solutionElements) { + element.setLogisticsSolution(this); + } + this.shipments = new ArrayList (); + this.solutionInfos = builder.solutionInfos; + this.eventHandlers = builder.eventHandlers; + this.trackers = builder.trackers; + this.offerFactory = builder.offerFactory; + if(this.offerFactory != null) { + this.offerFactory.setLogisticsSolution(this); + this.offerFactory.setLSP(lsp); + } + } + + + + @Override + public Id getId() { + return id; + } + + @Override + public void setLSP(LSP lsp) { + try { + this.lsp = (LSPWithOffers) lsp; + } + catch(ClassCastException e) { + System.out.println("The class " + this.toString() + " expects an LSPWithOffers and not any other implementation of LSP"); + System.exit(1); + } + } + + @Override + public LSP getLSP() { + return lsp; + } + + @Override + public Collection getSolutionElements() { + return solutionElements; + } + + @Override + public Collection getShipments() { + return shipments; + } + + @Override + public void assignShipment(LSPShipment shipment) { + shipments.add(shipment); + getFirstElement().getIncomingShipments().addShipment(shipment.getStartTimeWindow().getStart(), shipment); + } + + private LogisticsSolutionElement getFirstElement(){ + for(LogisticsSolutionElement element : solutionElements){ + if(element.getPreviousElement() == null){ + return element; + } + + } + return null; + } + + @Override + public Collection getInfos() { + return solutionInfos; + } + + @Override + public Collection getEventHandlers() { + return eventHandlers; + } + + @Override + public void addSimulationTracker(SimulationTracker tracker) { + this.trackers.add(tracker); + this.eventHandlers.addAll(tracker.getEventHandlers()); + this.solutionInfos.addAll(tracker.getInfos()); + } + + @Override + public Collection getSimulationTrackers() { + return trackers; + } + + @Override + public void setEventsManager(EventsManager eventsManager) { + this.eventsManager = eventsManager; + } + + @Override + public Offer getOffer(DemandObject object, String type) { + return offerFactory.makeOffer(object, type); + } + + @Override + public void setOfferFactory(OfferFactory factory) { + this.offerFactory = factory; + this.offerFactory.setLogisticsSolution(this); + this.offerFactory.setLSP(lsp); + } + + @Override + public OfferFactory getOfferFactory() { + return offerFactory; + } + +} diff --git a/src/demand/demandAgent/DemandAgent.java b/src/demand/demandAgent/DemandAgent.java new file mode 100644 index 00000000000..55c1582d8ad --- /dev/null +++ b/src/demand/demandAgent/DemandAgent.java @@ -0,0 +1,15 @@ +package demand.demandAgent; + +import java.util.Collection; + +import org.matsim.api.core.v01.Id; + +import demand.demandObject.DemandObject; +import demand.utilityFunctions.UtilityFunction; + +public interface DemandAgent { + + public Id getId(); + public Collection getDemandObjects(); + public Collection getUtilityFunctions(); +} diff --git a/src/demand/demandAgent/DemandAgentImpl.java b/src/demand/demandAgent/DemandAgentImpl.java new file mode 100644 index 00000000000..d8bac96fa0f --- /dev/null +++ b/src/demand/demandAgent/DemandAgentImpl.java @@ -0,0 +1,67 @@ +package demand.demandAgent; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; + +import demand.demandObject.DemandObject; +import demand.utilityFunctions.UtilityFunction; + +public class DemandAgentImpl implements DemandAgent { + + private Id id; + private ArrayList demandObjects; + private ArrayList utilityFunctions; + + public static class Builder{ + private Id id; + private ArrayList utilityFunctions; + + public Builder newInstance() { + return new Builder(); + } + + private Builder() { + this.utilityFunctions = new ArrayList(); + } + + public Builder setId(Id id) { + this.id = id; + return this; + } + + public Builder addUtilityFunction(UtilityFunction utilityFunction) { + this.utilityFunctions.add(utilityFunction); + return this; + } + + public DemandAgentImpl build() { + return new DemandAgentImpl(this); + } + } + + private DemandAgentImpl(Builder builder) { + this.demandObjects = new ArrayList(); + this.utilityFunctions = new ArrayList(); + this.utilityFunctions = builder.utilityFunctions; + this.id = builder.id; + } + + + @Override + public Id getId() { + return id; + } + + @Override + public Collection getDemandObjects() { + return demandObjects; + } + + @Override + public Collection getUtilityFunctions() { + return utilityFunctions; + } + +} diff --git a/src/demand/demandObject/DemandObject.java b/src/demand/demandObject/DemandObject.java new file mode 100644 index 00000000000..eaf51afad5b --- /dev/null +++ b/src/demand/demandObject/DemandObject.java @@ -0,0 +1,41 @@ +package demand.demandObject; + +import java.util.Collection; +import java.util.List; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.population.HasPlansAndId; + +import demand.demandAgent.DemandAgent; +import demand.mutualReplanning.DemandReplanner; +import demand.scoring.DemandScorer; +import demand.utilityFunctions.UtilityFunction; +import lsp.functions.Info; +import lsp.shipment.Requirement; + + +public interface DemandObject extends HasPlansAndId{ + + public DemandAgent getShipper(); + public DemandAgent getRecipient(); + public Id getId(); + public List getPlans(); + public double getStrengthOfFlow(); + public Id getFromLinkId(); + public Id getToLinkId(); + public Collection getUtilityFunctions(); + public void scoreSelectedPlan(); + public DemandPlan getSelectedPlan(); + public void setSelectedPlan(DemandPlan plan); + public void setScorer(DemandScorer scorer); + public DemandScorer getScorer(); + public DemandReplanner getReplanner(); + public void setReplanner(DemandReplanner replanner); + public void setOfferRequester(OfferRequester requester); + public OfferRequester getOfferRequester(); + public void setDemandPlanGenerator(DemandPlanGenerator generator); + public DemandPlanGenerator getDemandPlanGenerator(); + public Collection getRequirements(); + public Collection getInfos(); +} diff --git a/src/demand/demandObject/DemandObjectImpl.java b/src/demand/demandObject/DemandObjectImpl.java new file mode 100644 index 00000000000..775bfa0a253 --- /dev/null +++ b/src/demand/demandObject/DemandObjectImpl.java @@ -0,0 +1,308 @@ +package demand.demandObject; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.core.replanning.GenericStrategyManager; + +import demand.decoratedLSP.LSPWithOffers; +import demand.demandAgent.DemandAgent; +import demand.mutualReplanning.DemandReplanner; +import demand.offer.Offer; +import demand.scoring.DemandScorer; +import demand.utilityFunctions.UtilityFunction; +import lsp.functions.Info; +import lsp.shipment.Requirement; + +public class DemandObjectImpl implements DemandObject{ + + private DemandAgent shipper; + private DemandAgent recipient; + private Id id; + private ArrayList plans; + private double strengthOfFlow; + private Id fromLinkId; + private Id toLinkId; + private ArrayList utilityFunctions; + private DemandPlan selectedPlan; + private DemandScorer scorer; + private DemandReplanner replanner; + private Collection requirements; + private OfferRequester offerRequester; + private DemandPlanGenerator generator; + private Collection infos; + + public static class Builder{ + private DemandAgent shipper; + private DemandAgent recipient; + private Id id; + private double strengthOfFlow; + private Id fromLinkId; + private Id toLinkId; + private ArrayList utilityFunctions; + private DemandPlan initialPlan; + private DemandScorer scorer; + private DemandReplanner replanner; + private Collection requirements; + private OfferRequester offerRequester; + private DemandPlanGenerator generator; + private Collection infos; + + public static Builder newInstance() { + return new Builder(); + } + + private Builder() { + this.requirements = new ArrayList(); + this.utilityFunctions = new ArrayList(); + this.infos = new ArrayList(); + } + + public Builder setShipper(DemandAgent shipper) { + this.shipper = shipper; + return this; + } + + public Builder setRecipient(DemandAgent recipient) { + this.recipient = recipient; + return this; + } + + public Builder setId(Id id) { + this.id = id; + return this; + } + + public Builder setInitialPlan(DemandPlan plan){ + this.initialPlan = plan; + return this; + } + + public Builder setStrengthOfFlow(double strength){ + this.strengthOfFlow = strength; + return this; + } + + public Builder setFromLinkId(Id fromLinkId){ + this.fromLinkId = fromLinkId; + return this; + } + + public Builder setToLinkId(Id toLinkId){ + this.toLinkId = toLinkId; + return this; + } + + public Builder setOfferRequester(OfferRequester offerRequester){ + this.offerRequester = offerRequester; + return this; + } + + public Builder setDemandPlanGenerator(DemandPlanGenerator generator){ + this.generator = generator; + return this; + } + + public Builder addUtilityFunction(UtilityFunction utilityFunction) { + this.utilityFunctions.add(utilityFunction); + return this; + } + + public Builder addRequirement(Requirement requirement) { + this.requirements.add(requirement); + return this; + } + + public Builder addInfo(Info info) { + this.infos.add(info); + return this; + } + + public Builder setScorer(DemandScorer scorer) { + this.scorer = scorer; + return this; + } + + public Builder setReplanner(DemandReplanner replanner) { + this.replanner = replanner; + return this; + } + + public DemandObject build() { + return new DemandObjectImpl(this); + } + + } + + private DemandObjectImpl(Builder builder) { + this.plans = new ArrayList(); + this.utilityFunctions = new ArrayList(); + this.shipper = builder.shipper; + if(this.shipper != null) { + this.shipper.getDemandObjects().add(this); + } + this.recipient = builder.recipient; + if(this.recipient != null) { + this.recipient.getDemandObjects().add(this); + } + this.id = builder.id; + this.strengthOfFlow = builder.strengthOfFlow; + this.fromLinkId = builder.fromLinkId; + this.toLinkId = builder.toLinkId; + this.selectedPlan=builder.initialPlan; + this.plans.add(builder.initialPlan); + this.utilityFunctions = builder.utilityFunctions; + this.scorer = builder.scorer; + this.replanner = builder.replanner; + this.requirements = builder.requirements; + this.offerRequester = builder.offerRequester; + if(this.offerRequester != null) { + this.offerRequester.setDemandObject(this); + } + this.infos = builder.infos; + } + + + @Override + public boolean addPlan(DemandPlan plan) { + return plans.add(plan); + } + + @Override + public boolean removePlan(DemandPlan plan) { + if(plans.contains(plan)) { + plans.remove(plan); + return true; + } + else { + return false; + } + } + + @Override + public DemandPlan getSelectedPlan() { + return selectedPlan; + } + + @Override + public void setSelectedPlan(DemandPlan selectedPlan) { + if(!plans.contains(selectedPlan)) plans.add(selectedPlan); + this.selectedPlan = selectedPlan; + } + + @Override + public DemandPlan createCopyOfSelectedPlanAndMakeSelected() { + DemandPlan newPlan = DemandObjectImpl.copyPlan(this.selectedPlan) ; + this.setSelectedPlan( newPlan ) ; + return newPlan; + } + + @Override + public DemandAgent getShipper() { + return shipper; + } + + @Override + public DemandAgent getRecipient() { + return recipient; + } + + @Override + public Id getId() { + return id; + } + + @Override + public List getPlans() { + return plans; + } + + @Override + public double getStrengthOfFlow() { + return strengthOfFlow; + } + + @Override + public Id getFromLinkId() { + return fromLinkId; + } + + @Override + public Id getToLinkId() { + return toLinkId; + } + + @Override + public Collection getUtilityFunctions() { + return utilityFunctions; + } + + private static DemandPlan copyPlan(DemandPlan plan2copy) { + DemandPlan.Builder builder = DemandPlan.Builder.getInstance(); + builder.setLogisticsSolutionId(plan2copy.getSolutionId()); + builder.setLsp(plan2copy.getLsp()); + builder.setShipperShipment(plan2copy.getShipment()); + DemandPlan copiedPlan = builder.build(); + copiedPlan.setScore(plan2copy.getScore()); + return copiedPlan; + } + + @Override + public void scoreSelectedPlan() { + double score = scorer.scoreCurrentPlan(this); + this.selectedPlan.setScore(score); + } + + @Override + public void setScorer(DemandScorer scorer) { + this.scorer = scorer; + } + + @Override + public DemandScorer getScorer() { + return scorer; + } + + @Override + public DemandReplanner getReplanner() { + return replanner; + } + + @Override + public void setReplanner(DemandReplanner replanner) { + this.replanner = replanner; + } + + @Override + public void setOfferRequester(OfferRequester requester) { + this.offerRequester = requester; + } + + @Override + public OfferRequester getOfferRequester() { + return offerRequester; + } + + @Override + public void setDemandPlanGenerator(DemandPlanGenerator generator) { + this.generator = generator; + } + + @Override + public DemandPlanGenerator getDemandPlanGenerator() { + return generator; + } + + @Override + public Collection getRequirements() { + return requirements; + } + + @Override + public Collection getInfos() { + return infos; + } +} diff --git a/src/demand/demandObject/DemandObjects.java b/src/demand/demandObject/DemandObjects.java new file mode 100644 index 00000000000..04ad2087f9f --- /dev/null +++ b/src/demand/demandObject/DemandObjects.java @@ -0,0 +1,37 @@ +package demand.demandObject; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.matsim.api.core.v01.Id; + +public class DemandObjects { + + private Map, DemandObject> demandObjects = new HashMap<>(); + + public DemandObjects(Collection demandObjects) { + makeMap(demandObjects); + } + + public DemandObjects() { + + } + + public Map, DemandObject> getDemandObjects(){ + return demandObjects; + } + + private void makeMap(Collection demandObjects) { + for(DemandObject d : demandObjects) { + this.demandObjects.put(d.getId(), d); + } + } + + public void addDemandObject(DemandObject demandObject) { + if(!demandObjects.containsKey(demandObject.getId())) { + demandObjects.put(demandObject.getId(), demandObject); + } + } + +} diff --git a/src/demand/demandObject/DemandPlan.java b/src/demand/demandObject/DemandPlan.java new file mode 100644 index 00000000000..7fe8ce0ff42 --- /dev/null +++ b/src/demand/demandObject/DemandPlan.java @@ -0,0 +1,78 @@ +package demand.demandObject; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.BasicPlan; + +import demand.decoratedLSP.LSPWithOffers; +import lsp.LogisticsSolution; + + +public class DemandPlan implements BasicPlan{ + + private double score; + private ShipperShipment shipment; + private LSPWithOffers lsp; + private Id solutionId; + + public static class Builder{ + private ShipperShipment shipment; + private LSPWithOffers lsp; + private Id solutionId; + + public static Builder getInstance(){ + return new Builder(); + } + + private Builder(){ + } + + public Builder setShipperShipment(ShipperShipment shipment){ + this.shipment = shipment; + return this; + } + + public Builder setLsp(LSPWithOffers lsp){ + this.lsp = lsp; + return this; + } + + public Builder setLogisticsSolutionId(Id solutionId){ + this.solutionId = solutionId; + return this; + } + + public DemandPlan build() { + return new DemandPlan(this); + } + + } + + private DemandPlan(Builder builder) { + this.shipment = builder.shipment; + this.lsp = builder.lsp; + this.solutionId = builder.solutionId; + } + + @Override + public Double getScore() { + return score; + } + + @Override + public void setScore(Double arg0) { + this.score = arg0; + } + + public ShipperShipment getShipment() { + return shipment; + } + + public LSPWithOffers getLsp() { + return lsp; + } + + public Id getSolutionId() { + return solutionId; + } + +} diff --git a/src/demand/demandObject/DemandPlanGenerator.java b/src/demand/demandObject/DemandPlanGenerator.java new file mode 100644 index 00000000000..a786f98f364 --- /dev/null +++ b/src/demand/demandObject/DemandPlanGenerator.java @@ -0,0 +1,7 @@ +package demand.demandObject; + +public interface DemandPlanGenerator { + + public DemandPlan createDemandPlan(); + +} diff --git a/src/demand/demandObject/OfferRequester.java b/src/demand/demandObject/OfferRequester.java new file mode 100644 index 00000000000..82418cca139 --- /dev/null +++ b/src/demand/demandObject/OfferRequester.java @@ -0,0 +1,12 @@ +package demand.demandObject; + +import java.util.Collection; + +import demand.decoratedLSP.LSPWithOffers; +import demand.offer.Offer; + +public interface OfferRequester { + + public Collection requestOffers(Collection lsps); + public void setDemandObject(DemandObject demandObject); +} diff --git a/src/demand/demandObject/ShipperShipment.java b/src/demand/demandObject/ShipperShipment.java new file mode 100644 index 00000000000..2d3a98980a5 --- /dev/null +++ b/src/demand/demandObject/ShipperShipment.java @@ -0,0 +1,22 @@ +package demand.demandObject; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.TimeWindow; + +import lsp.shipment.LSPShipment; + + + +public interface ShipperShipment { + + public Id getId(); + public double getShipmentSize(); + public TimeWindow getStartTimeWindow(); + public TimeWindow getEndTimeWindow(); + public double getServiceTime(); + public void setLSPShipment(LSPShipment lspShipment); + public LSPShipment getLSPShipment(); + public void setDemandObject(DemandObject demandObject); + public DemandObject getDemandObject(); + +} diff --git a/src/demand/mutualReplanning/DemandReplanner.java b/src/demand/mutualReplanning/DemandReplanner.java new file mode 100644 index 00000000000..eaf89c157be --- /dev/null +++ b/src/demand/mutualReplanning/DemandReplanner.java @@ -0,0 +1,15 @@ +package demand.mutualReplanning; + +import java.util.Collection; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.LSP; +import lsp.LSPPlanImpl; + +public interface DemandReplanner { + public void replan(Collection lsps, ReplanningEvent event); + public GenericStrategyManager getStrategyManager(); + public void setStrategyManager(GenericStrategyManager manager); +} diff --git a/src/demand/mutualReplanning/LSPWithOffersReplanner.java b/src/demand/mutualReplanning/LSPWithOffersReplanner.java new file mode 100644 index 00000000000..59059ebb55c --- /dev/null +++ b/src/demand/mutualReplanning/LSPWithOffersReplanner.java @@ -0,0 +1,55 @@ +package demand.mutualReplanning; + +import java.util.ArrayList; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.replanning.GenericStrategyManager; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.offer.OfferUpdater; +import lsp.LSP; +import lsp.LSPPlan; +import lsp.replanning.LSPReplanner; + +public class LSPWithOffersReplanner implements LSPReplanner{ + + private LSPDecorator lsp; + private GenericStrategyManager strategyManager; + private OfferUpdater offerUpdater; + + public LSPWithOffersReplanner(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public void replan(ReplanningEvent event) { + if(strategyManager != null) { + ArrayList lspList = new ArrayList (); + lspList.add(lsp); + strategyManager.run(lspList, null, event.getIteration(), event.getReplanningContext()); + } + if(offerUpdater != null) { + offerUpdater.updateOffers(); + } + } + + @Override + public GenericStrategyManager getStrategyManager() { + return strategyManager; + } + + @Override + public void setStrategyManager(GenericStrategyManager strategyManager) { + this.strategyManager = strategyManager; + } + + public void setOfferUpdater(OfferUpdater offerUpdater) { + this.offerUpdater = offerUpdater; + offerUpdater.setLSP(lsp); + } + + public OfferUpdater getOfferUpdater() { + return offerUpdater; + } +} diff --git a/src/demand/mutualReplanning/MutualReplanningModule.java b/src/demand/mutualReplanning/MutualReplanningModule.java new file mode 100644 index 00000000000..d3f0a02137e --- /dev/null +++ b/src/demand/mutualReplanning/MutualReplanningModule.java @@ -0,0 +1,37 @@ +package demand.mutualReplanning; + +import java.util.Collection; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.controler.listener.ReplanningListener; + +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; +import lsp.LSP; + +public abstract class MutualReplanningModule implements ReplanningListener{ + + protected Collection lsps; + protected Collection demandObjects; + + public MutualReplanningModule(Collection lsps, DemandObjects demandObjects ) { + this.lsps = lsps; + this.demandObjects = demandObjects.getDemandObjects().values(); + } + + public void notifyReplanning(ReplanningEvent event) { + replan(event); + } + + public void replan(ReplanningEvent arg0) { + replanLSPs(arg0); + replanDemandObjects(arg0); + } + + abstract void replanLSPs(ReplanningEvent event); + + abstract void replanDemandObjects(ReplanningEvent event); + +} + + diff --git a/src/demand/mutualReplanning/MutualReplanningModuleImpl.java b/src/demand/mutualReplanning/MutualReplanningModuleImpl.java new file mode 100644 index 00000000000..0870e77fbfa --- /dev/null +++ b/src/demand/mutualReplanning/MutualReplanningModuleImpl.java @@ -0,0 +1,42 @@ +package demand.mutualReplanning; + +import java.util.Collection; + +import org.matsim.core.controler.events.ReplanningEvent; + +import demand.decoratedLSP.LSPWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; +import lsp.LSP; + +public class MutualReplanningModuleImpl extends MutualReplanningModule{ + + public MutualReplanningModuleImpl(Collection lsps, DemandObjects demandObjects) { + super(lsps, demandObjects); + } + + @Override + void replanLSPs(ReplanningEvent event) { + for(LSP lsp : lsps) { + if(lsp instanceof LSPWithOffers) { + LSPWithOffers lspWithOffers = (LSPWithOffers)lsp; + if(lspWithOffers.getReplanner()!= null) { + lspWithOffers.getReplanner().replan(event); + } + if(lspWithOffers.getOfferUpdater()!= null) { + lspWithOffers.getOfferUpdater().updateOffers(); + } + } + } + } + + @Override + void replanDemandObjects(ReplanningEvent event) { + for(DemandObject demandObject : demandObjects) { + if(demandObject.getReplanner()!= null) { + demandObject.getReplanner().replan(lsps, event); + } + } + } + +} diff --git a/src/demand/mutualReplanning/OfferReplanningStrategyModule.java b/src/demand/mutualReplanning/OfferReplanningStrategyModule.java new file mode 100644 index 00000000000..25d68dd2eac --- /dev/null +++ b/src/demand/mutualReplanning/OfferReplanningStrategyModule.java @@ -0,0 +1,55 @@ +package demand.mutualReplanning; + +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.replanning.modules.GenericPlanStrategyModule; + +import demand.decoratedLSP.LSPWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; +import demand.offer.Offer; +import lsp.functions.Info; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public abstract class OfferReplanningStrategyModule implements GenericPlanStrategyModule{ + + protected DemandObject demandObject; + protected Collection lsps; + + public OfferReplanningStrategyModule(DemandObject demandObject, Collection lsps) { + this.demandObject = demandObject; + this.lsps = lsps; + } + + + @Override + public void handlePlan(DemandPlan demandPlan) { + Collection offers = recieveOffers(lsps); + DemandPlan plan = createPlan(offers); + assignShipmentToLSP(plan); + } + + protected abstract Collection recieveOffers(Collection lsps); + protected abstract DemandPlan createPlan(Collection offers); + + private void assignShipmentToLSP(DemandPlan plan) { + Id id = Id.create(plan.getShipment().getId(), LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + builder.setFromLinkId(demandObject.getFromLinkId()); + builder.setToLinkId(demandObject.getToLinkId()); + builder.setCapacityDemand((int)plan.getShipment().getShipmentSize()); + builder.setServiceTime(plan.getShipment().getServiceTime()); + builder.setStartTimeWindow(plan.getShipment().getStartTimeWindow()); + builder.setEndTimeWindow(plan.getShipment().getEndTimeWindow()); + for(Info info : demandObject.getInfos()) { + builder.addInfo(info); + } + LSPShipment lspShipment = builder.build(); + plan.getLsp().assignShipmentToSolution(lspShipment, plan.getSolutionId()); + plan.getShipment().setLSPShipment(lspShipment); + + } + +} diff --git a/src/demand/offer/DefaultOfferImpl.java b/src/demand/offer/DefaultOfferImpl.java new file mode 100644 index 00000000000..633479e5544 --- /dev/null +++ b/src/demand/offer/DefaultOfferImpl.java @@ -0,0 +1,51 @@ +package demand.offer; + +import lsp.LSP; +import lsp.LogisticsSolution; + +public class DefaultOfferImpl implements Offer { + + private LSP lsp; + private LogisticsSolution solution; + + public DefaultOfferImpl(LSP lsp, LogisticsSolution logisticsSolution) { + this.lsp = lsp; + this.solution = logisticsSolution; + } + + @Override + public LSP getLsp() { + return lsp; + } + + @Override + public LogisticsSolution getSolution() { + return solution; + } + + @Override + public String getType() { + return "DEFAULT"; + } + + public void update() { + + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + @Override + public void setSolution(LogisticsSolution solution) { + this.solution = solution; + } + + +} diff --git a/src/demand/offer/Offer.java b/src/demand/offer/Offer.java new file mode 100644 index 00000000000..f1326920eed --- /dev/null +++ b/src/demand/offer/Offer.java @@ -0,0 +1,15 @@ +package demand.offer; + +import lsp.LSP; +import lsp.LogisticsSolution; + +public interface Offer { + + public LSP getLsp(); + public LogisticsSolution getSolution(); + public String getType(); + public void accept(OfferVisitor visitor); + public void update(); + public void setLSP (LSP lsp); + public void setSolution(LogisticsSolution solution); +} diff --git a/src/demand/offer/OfferFactory.java b/src/demand/offer/OfferFactory.java new file mode 100644 index 00000000000..b7d7b4e8523 --- /dev/null +++ b/src/demand/offer/OfferFactory.java @@ -0,0 +1,21 @@ +package demand.offer; + +import java.util.Collection; + +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.demandObject.DemandObject; +import lsp.LSP; +import lsp.LogisticsSolution; + +public interface OfferFactory { + + public Offer makeOffer(DemandObject object, String offerType); + public Collection getOffers(); + public LSP getLSP(); + public LogisticsSolutionDecorator getLogisticsSolution(); + public void setLogisticsSolution(LogisticsSolutionDecorator solution); + public void setLSP(LSP lsp); + public void addOffer(Offer offer); +} diff --git a/src/demand/offer/OfferFactoryImpl.java b/src/demand/offer/OfferFactoryImpl.java new file mode 100644 index 00000000000..9255623be3e --- /dev/null +++ b/src/demand/offer/OfferFactoryImpl.java @@ -0,0 +1,73 @@ +package demand.offer; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandObject.DemandObject; +import demand.offer.DefaultOfferImpl; +import demand.offer.Offer; +import demand.offer.OfferFactory; +import lsp.LSP; +import lsp.LogisticsSolution; + +public class OfferFactoryImpl implements OfferFactory{ + + + private ArrayList offerList; + private LogisticsSolutionDecorator solution; + private LSP lsp; + + public OfferFactoryImpl(LogisticsSolutionDecorator solution) { + this.solution = solution; + this.lsp = solution.getLSP(); + offerList = new ArrayList(); + } + + @Override + public Offer makeOffer(DemandObject object, String offerType) { + for(Offer offer : offerList) { + if(offer.getType() == offerType) { + offer.setLSP(lsp); + return offer; + } + } + return new DefaultOfferImpl(this.lsp, this.solution); + } + + @Override + public Collection getOffers() { + return offerList; + } + + @Override + public LSP getLSP() { + return lsp; + } + + @Override + public LogisticsSolutionDecorator getLogisticsSolution() { + return solution; + } + + @Override + public void setLogisticsSolution(LogisticsSolutionDecorator solution) { + this.solution = solution; + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + @Override + public void addOffer(Offer offer) { + offer.setLSP(lsp); + offer.setSolution(solution); + offerList.add(offer); + } + +} diff --git a/src/demand/offer/OfferTransferrer.java b/src/demand/offer/OfferTransferrer.java new file mode 100644 index 00000000000..5b2df94ea8f --- /dev/null +++ b/src/demand/offer/OfferTransferrer.java @@ -0,0 +1,16 @@ +package demand.offer; + +import org.matsim.api.core.v01.Id; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.demandObject.DemandObject; +import lsp.LSP; +import lsp.LogisticsSolution; + +public interface OfferTransferrer { + + public Offer transferOffer(DemandObject object, String type, Id solutionId); + public void setLSP(LSPDecorator lsp); + public LSPDecorator getLSP(); +} diff --git a/src/demand/offer/OfferTransferrerImpl.java b/src/demand/offer/OfferTransferrerImpl.java new file mode 100644 index 00000000000..dcc04748732 --- /dev/null +++ b/src/demand/offer/OfferTransferrerImpl.java @@ -0,0 +1,38 @@ +package demand.offer; + +import org.matsim.api.core.v01.Id; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.demandObject.DemandObject; +import lsp.LogisticsSolution; + +public class OfferTransferrerImpl implements OfferTransferrer{ + + private LSPDecorator lsp; + + + @Override + public Offer transferOffer(DemandObject object, String type, Id solutionId) { + for(LogisticsSolution planSolution : lsp.getSelectedPlan().getSolutions()) { + if(planSolution instanceof LogisticsSolutionDecorator) { + LogisticsSolutionDecorator offerSolution = (LogisticsSolutionDecorator) planSolution; + if(offerSolution.getId() == solutionId) { + if(!(offerSolution.getOffer(object, type) instanceof DefaultOfferImpl)) { + return offerSolution.getOffer(object, type); + } + } + } + } + return new DefaultOfferImpl(lsp, null); + } + + public void setLSP(LSPDecorator lsp){ + this.lsp = lsp; + } + + public LSPDecorator getLSP(){ + return lsp; + } +} + diff --git a/src/demand/offer/OfferUpdater.java b/src/demand/offer/OfferUpdater.java new file mode 100644 index 00000000000..5a84ef6f479 --- /dev/null +++ b/src/demand/offer/OfferUpdater.java @@ -0,0 +1,12 @@ +package demand.offer; + +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; + +public interface OfferUpdater { + + public void updateOffers(); + public Collection getOfferVisitors(); + public void setLSP (LSPDecorator lsp); +} diff --git a/src/demand/offer/OfferUpdaterImpl.java b/src/demand/offer/OfferUpdaterImpl.java new file mode 100644 index 00000000000..554b2d27d82 --- /dev/null +++ b/src/demand/offer/OfferUpdaterImpl.java @@ -0,0 +1,47 @@ +package demand.offer; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import lsp.LogisticsSolution; + +public class OfferUpdaterImpl implements OfferUpdater{ + + private LSPDecorator lsp; + private Collection visitors; + + public OfferUpdaterImpl() { + this.visitors = new ArrayList(); + } + + + @Override + public void updateOffers() { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + if(solution instanceof LogisticsSolutionWithOffers) { + LogisticsSolutionWithOffers offerSolution = (LogisticsSolutionWithOffers) solution; + for(OfferVisitor visitor : visitors) { + if(visitor.getLogisticsSolution() == solution) { + for(Offer offer : offerSolution.getOfferFactory().getOffers()) { + if(offer.getClass() == visitor.getOfferClass()) { + visitor.visit(offer); + } + } + } + } + } + } + + } + + @Override + public Collection getOfferVisitors() { + return visitors; + } + + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } +} diff --git a/src/demand/offer/OfferVisitor.java b/src/demand/offer/OfferVisitor.java new file mode 100644 index 00000000000..59bdf105677 --- /dev/null +++ b/src/demand/offer/OfferVisitor.java @@ -0,0 +1,10 @@ +package demand.offer; + +import lsp.LogisticsSolution; + +public interface OfferVisitor { + + public void visit(Offer offer); + public Class getOfferClass(); + public LogisticsSolution getLogisticsSolution(); +} diff --git a/src/demand/offer/RequirementsOfferRequester.java b/src/demand/offer/RequirementsOfferRequester.java new file mode 100644 index 00000000000..e2f84b74366 --- /dev/null +++ b/src/demand/offer/RequirementsOfferRequester.java @@ -0,0 +1,30 @@ +package demand.offer; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.OfferRequester; +import lsp.LogisticsSolution; + +public class RequirementsOfferRequester implements OfferRequester { + + private DemandObject demandObject; + + @Override + public Collection requestOffers(Collection lsps) { + ArrayList offerList = new ArrayList(); + for(LSPWithOffers lsp : lsps) { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions() ) { + offerList.add(lsp.getOffer(demandObject, "linear", solution.getId())); + } + } + return offerList; + } + + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/src/demand/scoring/DemandScorer.java b/src/demand/scoring/DemandScorer.java new file mode 100644 index 00000000000..20d1a0d9e99 --- /dev/null +++ b/src/demand/scoring/DemandScorer.java @@ -0,0 +1,10 @@ +package demand.scoring; + +import demand.demandObject.DemandObject; +import lsp.scoring.Scorer; + +public interface DemandScorer extends Scorer{ + + public double scoreCurrentPlan(DemandObject demandObject); + +} diff --git a/src/demand/scoring/DemandScoringModule.java b/src/demand/scoring/DemandScoringModule.java new file mode 100644 index 00000000000..90c63159402 --- /dev/null +++ b/src/demand/scoring/DemandScoringModule.java @@ -0,0 +1,8 @@ +package demand.scoring; + +import org.matsim.core.controler.listener.ScoringListener; + +public interface DemandScoringModule extends ScoringListener{ + + public void scoreDemandObjects(); +} diff --git a/src/demand/scoring/DemandScoringModuleImpl.java b/src/demand/scoring/DemandScoringModuleImpl.java new file mode 100644 index 00000000000..3a3e638d609 --- /dev/null +++ b/src/demand/scoring/DemandScoringModuleImpl.java @@ -0,0 +1,30 @@ +package demand.scoring; + +import java.util.Collection; + +import org.matsim.core.controler.events.ScoringEvent; + +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; + + +public class DemandScoringModuleImpl implements DemandScoringModule{ + + private Collection demandObjects; + + public DemandScoringModuleImpl(DemandObjects demandObjects) { + this.demandObjects = demandObjects.getDemandObjects().values(); + } + + @Override + public void notifyScoring(ScoringEvent arg0) { + scoreDemandObjects(); + } + + @Override + public void scoreDemandObjects() { + for(DemandObject demandObject : demandObjects) { + demandObject.scoreSelectedPlan(); + } + } +} diff --git a/src/demand/utilityFunctions/UtilityFunction.java b/src/demand/utilityFunctions/UtilityFunction.java new file mode 100644 index 00000000000..ab3932addd8 --- /dev/null +++ b/src/demand/utilityFunctions/UtilityFunction.java @@ -0,0 +1,11 @@ +package demand.utilityFunctions; + +import demand.demandObject.ShipperShipment; +import demand.offer.Offer; + +public interface UtilityFunction { + + public String getName(); + public double getUtilityValue(Offer offer, ShipperShipment shipment); + +} diff --git a/test/requirementsCheckerTests/BlueInfo.java b/test/requirementsCheckerTests/BlueInfo.java new file mode 100644 index 00000000000..ecdf8dcb16e --- /dev/null +++ b/test/requirementsCheckerTests/BlueInfo.java @@ -0,0 +1,44 @@ +package requirementsCheckerTests; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; + +public class BlueInfo extends Info{ + + private InfoFunctionImpl blueInfoFunction; + + public BlueInfo() { + blueInfoFunction = new InfoFunctionImpl(); + blueInfoFunction.getValues().add(new BlueInfoFunctionValue()); + } + + @Override + public String getName() { + return "blue"; + } + + @Override + public InfoFunction getFunction() { + return blueInfoFunction; + } + + @Override + public double getFromTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public double getToTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/test/requirementsCheckerTests/BlueInfoFunctionValue.java b/test/requirementsCheckerTests/BlueInfoFunctionValue.java new file mode 100644 index 00000000000..309e346122e --- /dev/null +++ b/test/requirementsCheckerTests/BlueInfoFunctionValue.java @@ -0,0 +1,30 @@ +package requirementsCheckerTests; + +import java.awt.Color; + +import lsp.functions.InfoFunctionValue; + +public class BlueInfoFunctionValue implements InfoFunctionValue{ + + @Override + public String getName() { + return "blue"; + } + + @Override + public Class getDataType() { + return Color.class; + } + + @Override + public String getValue() { + return "blue"; + } + + @Override + public void setValue(String value) { + // TODO Auto-generated method stub + + } + +} diff --git a/test/requirementsCheckerTests/BlueRequirement.java b/test/requirementsCheckerTests/BlueRequirement.java new file mode 100644 index 00000000000..b1ccf4a9ec6 --- /dev/null +++ b/test/requirementsCheckerTests/BlueRequirement.java @@ -0,0 +1,19 @@ +package requirementsCheckerTests; + +import lsp.functions.Info; +import lsp.LogisticsSolution; +import lsp.shipment.Requirement; + +public class BlueRequirement implements Requirement{ + + @Override + public boolean checkRequirement(LogisticsSolution solution) { + for(Info info : solution.getInfos()) { + if(info instanceof BlueInfo) { + return true; + } + } + return false; + } + +} diff --git a/test/requirementsCheckerTests/NonsenseOffer.java b/test/requirementsCheckerTests/NonsenseOffer.java new file mode 100644 index 00000000000..87379a9e098 --- /dev/null +++ b/test/requirementsCheckerTests/NonsenseOffer.java @@ -0,0 +1,52 @@ +package requirementsCheckerTests; + +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import lsp.LSP; +import lsp.LogisticsSolution; + +public class NonsenseOffer implements Offer{ + + private LSP lsp; + private LogisticsSolution solution; + + + @Override + public LSP getLsp() { + return lsp; + } + + @Override + public LogisticsSolution getSolution() { + return solution; + } + + @Override + public String getType() { + return "nonsense"; + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + + } + + @Override + public void setSolution(LogisticsSolution solution) { + this.solution = solution; + + } + +} diff --git a/test/requirementsCheckerTests/RedInfo.java b/test/requirementsCheckerTests/RedInfo.java new file mode 100644 index 00000000000..45dd88830bb --- /dev/null +++ b/test/requirementsCheckerTests/RedInfo.java @@ -0,0 +1,44 @@ +package requirementsCheckerTests; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; + +public class RedInfo extends Info{ + + private InfoFunctionImpl redInfoFunction; + + public RedInfo() { + redInfoFunction = new InfoFunctionImpl(); + redInfoFunction.getValues().add(new RedInfoFunctionValue()); + } + + @Override + public String getName() { + return "red"; + } + + @Override + public InfoFunction getFunction() { + return redInfoFunction; + } + + @Override + public double getFromTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public double getToTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/test/requirementsCheckerTests/RedInfoFunctionValue.java b/test/requirementsCheckerTests/RedInfoFunctionValue.java new file mode 100644 index 00000000000..1d1c8acbd13 --- /dev/null +++ b/test/requirementsCheckerTests/RedInfoFunctionValue.java @@ -0,0 +1,30 @@ +package requirementsCheckerTests; + +import java.awt.Color; + +import lsp.functions.InfoFunctionValue; + +public class RedInfoFunctionValue implements InfoFunctionValue{ + + @Override + public String getName() { + return "red"; + } + + @Override + public Class getDataType() { + return Color.class; + } + + @Override + public String getValue() { + return "red"; + } + + @Override + public void setValue(String value) { + // TODO Auto-generated method stub + + } + +} diff --git a/test/requirementsCheckerTests/RedRequirement.java b/test/requirementsCheckerTests/RedRequirement.java new file mode 100644 index 00000000000..e980cc53dfb --- /dev/null +++ b/test/requirementsCheckerTests/RedRequirement.java @@ -0,0 +1,19 @@ +package requirementsCheckerTests; + +import lsp.functions.Info; +import lsp.LogisticsSolution; +import lsp.shipment.Requirement; + +public class RedRequirement implements Requirement{ + + @Override + public boolean checkRequirement(LogisticsSolution solution) { + for(Info info : solution.getInfos()) { + if(info instanceof RedInfo) { + return true; + } + } + return false; + } + +} diff --git a/test/requirementsCheckerTests/RequirementsAssigner.java b/test/requirementsCheckerTests/RequirementsAssigner.java new file mode 100644 index 00000000000..f36b4715b09 --- /dev/null +++ b/test/requirementsCheckerTests/RequirementsAssigner.java @@ -0,0 +1,49 @@ +package requirementsCheckerTests; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.ShipmentAssigner; +import lsp.shipment.LSPShipment; +import lsp.shipment.Requirement; + +public class RequirementsAssigner implements ShipmentAssigner { + + private LSP lsp; + private Collection feasibleSolutions; + + public RequirementsAssigner() { + this.feasibleSolutions = new ArrayList(); + } + + @Override + public void assignShipment(LSPShipment shipment) { + feasibleSolutions.clear(); + + label: + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(Requirement requirement : shipment.getRequirements()) { + if(requirement.checkRequirement(solution) == false) { + + continue label; + } + } + feasibleSolutions.add(solution); + } + LogisticsSolution chosenSolution = feasibleSolutions.iterator().next(); + chosenSolution.assignShipment(shipment); + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + @Override + public LSP getLSP() { + return lsp; + } + +} diff --git a/test/requirementsCheckerTests/RequirementsTransferrer.java b/test/requirementsCheckerTests/RequirementsTransferrer.java new file mode 100644 index 00000000000..cbe7452baeb --- /dev/null +++ b/test/requirementsCheckerTests/RequirementsTransferrer.java @@ -0,0 +1,59 @@ +package requirementsCheckerTests; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandObject.DemandObject; +import demand.offer.DefaultOfferImpl; +import demand.offer.Offer; +import demand.offer.OfferTransferrer; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.shipment.Requirement; + +public class RequirementsTransferrer implements OfferTransferrer{ + + private LSPDecorator lsp; + private Collection feasibleSolutions; + + public RequirementsTransferrer() { + this.feasibleSolutions = new ArrayList(); + } + + + @Override + public Offer transferOffer(DemandObject object, String type, Id solutionId) { + feasibleSolutions.clear(); + label: + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; + for(Requirement requirement : object.getRequirements()) { + if(requirement.checkRequirement(solutionWithOffers) == false) { + continue label; + } + } + feasibleSolutions.add(solutionWithOffers); + } + + LogisticsSolutionDecorator chosenSolution = feasibleSolutions.iterator().next(); + return chosenSolution.getOffer(object, type); + + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + + @Override + public LSPDecorator getLSP() { + return lsp; + } +} diff --git a/test/requirementsCheckerTests/assignerRequirementsTest.java b/test/requirementsCheckerTests/assignerRequirementsTest.java new file mode 100644 index 00000000000..ecf337bb423 --- /dev/null +++ b/test/requirementsCheckerTests/assignerRequirementsTest.java @@ -0,0 +1,208 @@ +package requirementsCheckerTests; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.functions.Info; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; + +public class assignerRequirementsTest { + + private Network network; + private LogisticsSolution blueSolution; + private LogisticsSolution redSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl collectionPlan; + private LSP collectionLSP; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); + Id redCarrierId = Id.create("RedCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id redVehicleId = Id.createVehicleId("RedVehicle"); + CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId); + redVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder redCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + redCapabilitiesBuilder.addType(collectionType); + redCapabilitiesBuilder.addVehicle(redVehicle); + redCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities redCapabilities = redCapabilitiesBuilder.build(); + Carrier redCarrier = CarrierImpl.newInstance(redCarrierId); + redCarrier.setCarrierCapabilities(redCapabilities); + + Id redAdapterId = Id.create("RedCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder redAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(redAdapterId, network); + redAdapterBuilder.setCollectionScheduler(redScheduler); + redAdapterBuilder.setCarrier(redCarrier); + redAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource redCollectionAdapter = redAdapterBuilder.build(); + + Id redElementId = Id.create("RedCollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder redCollectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(redElementId); + redCollectionElementBuilder.setResource(redCollectionAdapter); + LogisticsSolutionElement redCollectionElement = redCollectionElementBuilder.build(); + + Id redCollectionSolutionId = Id.create("RedCollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder redCollectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(redCollectionSolutionId); + redCollectionSolutionBuilder.addSolutionElement(redCollectionElement); + redSolution = redCollectionSolutionBuilder.build(); + redSolution.getInfos().add(new RedInfo()); + + assigner = new RequirementsAssigner(); + collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(redSolution); + + CollectionCarrierScheduler blueScheduler = new CollectionCarrierScheduler(); + Id blueCarrierId = Id.create("BlueCarrier", Carrier.class); + Id blueVehicleId = Id.createVehicleId("BlueVehicle"); + CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId); + blueVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + blueCapabilitiesBuilder.addType(collectionType); + blueCapabilitiesBuilder.addVehicle(redVehicle); + blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); + Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); + blueCarrier.setCarrierCapabilities(blueCapabilities); + + Id blueAdapterId = Id.create("BlueCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder blueAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(blueAdapterId, network); + blueAdapterBuilder.setCollectionScheduler(blueScheduler); + blueAdapterBuilder.setCarrier(blueCarrier); + blueAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource blueCollectionAdapter = blueAdapterBuilder.build(); + + Id blueElementId = Id.create("BlueCollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder blueCollectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(blueElementId); + blueCollectionElementBuilder.setResource(blueCollectionAdapter); + LogisticsSolutionElement blueCollectionElement = blueCollectionElementBuilder.build(); + + Id blueCollectionSolutionId = Id.create("BlueCollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder blueCollectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(blueCollectionSolutionId); + blueCollectionSolutionBuilder.addSolutionElement(blueCollectionElement); + blueSolution = blueCollectionSolutionBuilder.build(); + blueSolution.getInfos().add(new BlueInfo()); + collectionPlan.addSolution(blueSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(redCollectionAdapter); + resourcesList.add(blueCollectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + Random rand = new Random(1); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = rand.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + boolean blue = rand.nextBoolean(); + if (blue == true) { + builder.addRequirement(new BlueRequirement()); + } + else { + builder.addRequirement(new RedRequirement()); + } + + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + } + + @Test + public void testAssignerRequirements() { + for(LSPShipment shipment : blueSolution.getShipments()) { + assertTrue(shipment.getRequirements().iterator().next() instanceof BlueRequirement); + } + for(LSPShipment shipment : redSolution.getShipments()) { + assertTrue(shipment.getRequirements().iterator().next() instanceof RedRequirement); + } + } + +} diff --git a/test/requirementsCheckerTests/transferrerRequirementsTest.java b/test/requirementsCheckerTests/transferrerRequirementsTest.java new file mode 100644 index 00000000000..d6e0fe2777c --- /dev/null +++ b/test/requirementsCheckerTests/transferrerRequirementsTest.java @@ -0,0 +1,213 @@ +package requirementsCheckerTests; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPPlanDecorator; +import demand.decoratedLSP.LSPPlanWithOfferTransferrer; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjectImpl; +import demand.offer.Offer; +import demand.offer.OfferFactoryImpl; +import demand.offer.OfferTransferrer; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.shipment.Requirement; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; + +public class transferrerRequirementsTest { + private Network network; + private LogisticsSolutionWithOffers blueOfferSolution; + private LogisticsSolutionWithOffers redOfferSolution; + private OfferTransferrer transferrer; + private LSPPlanDecorator collectionPlan; + private LSPDecorator offerLSP; + private ArrayList demandObjects; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); + Id redCarrierId = Id.create("RedCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id redVehicleId = Id.createVehicleId("RedVehicle"); + CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId); + redVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder redCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + redCapabilitiesBuilder.addType(collectionType); + redCapabilitiesBuilder.addVehicle(redVehicle); + redCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities redCapabilities = redCapabilitiesBuilder.build(); + Carrier redCarrier = CarrierImpl.newInstance(redCarrierId); + redCarrier.setCarrierCapabilities(redCapabilities); + + Id redAdapterId = Id.create("RedCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder redAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(redAdapterId, network); + redAdapterBuilder.setCollectionScheduler(redScheduler); + redAdapterBuilder.setCarrier(redCarrier); + redAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource redCollectionAdapter = redAdapterBuilder.build(); + + Id redElementId = Id.create("RedCollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder redCollectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(redElementId); + redCollectionElementBuilder.setResource(redCollectionAdapter); + LogisticsSolutionElement redCollectionElement = redCollectionElementBuilder.build(); + + Id redCollectionSolutionId = Id.create("RedCollectionSolution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder redOfferSolutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(redCollectionSolutionId); + redOfferSolutionBuilder.addSolutionElement(redCollectionElement); + redOfferSolution = redOfferSolutionBuilder.build(); + redOfferSolution.getInfos().add(new RedInfo()); + OfferFactoryImpl redOfferFactory = new OfferFactoryImpl(redOfferSolution); + redOfferFactory.addOffer(new NonsenseOffer()); + redOfferSolution.setOfferFactory(redOfferFactory); + + collectionPlan = new LSPPlanWithOfferTransferrer(); + collectionPlan.addSolution(redOfferSolution); + + CollectionCarrierScheduler blueScheduler = new CollectionCarrierScheduler(); + Id blueCarrierId = Id.create("BlueCarrier", Carrier.class); + Id blueVehicleId = Id.createVehicleId("BlueVehicle"); + CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId); + blueVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + blueCapabilitiesBuilder.addType(collectionType); + blueCapabilitiesBuilder.addVehicle(redVehicle); + blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); + Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); + blueCarrier.setCarrierCapabilities(blueCapabilities); + + Id blueAdapterId = Id.create("BlueCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder blueAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(blueAdapterId, network); + blueAdapterBuilder.setCollectionScheduler(blueScheduler); + blueAdapterBuilder.setCarrier(blueCarrier); + blueAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource blueCollectionAdapter = blueAdapterBuilder.build(); + + Id blueElementId = Id.create("BlueCollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder blueCollectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(blueElementId); + blueCollectionElementBuilder.setResource(blueCollectionAdapter); + LogisticsSolutionElement blueCollectionElement = blueCollectionElementBuilder.build(); + + Id blueCollectionSolutionId = Id.create("BlueCollectionSolution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder blueOfferSolutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(blueCollectionSolutionId); + blueOfferSolutionBuilder.addSolutionElement(blueCollectionElement); + blueOfferSolution = blueOfferSolutionBuilder.build(); + blueOfferSolution.getInfos().add(new BlueInfo()); + OfferFactoryImpl blueOfferFactory = new OfferFactoryImpl(blueOfferSolution); + blueOfferFactory.addOffer(new NonsenseOffer()); + blueOfferSolution.setOfferFactory(blueOfferFactory); + collectionPlan.addSolution(blueOfferSolution); + + transferrer = new RequirementsTransferrer(); + collectionPlan.setOfferTransferrer(transferrer); + + LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); + offerLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + offerLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(redCollectionAdapter); + resourcesList.add(blueCollectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + offerLSPBuilder.setSolutionScheduler(simpleScheduler); + offerLSP = offerLSPBuilder.build(); + LSPPlanDecorator decorator = (LSPPlanDecorator)offerLSP.getSelectedPlan(); + + demandObjects = new ArrayList(); + + Random rand = new Random(1); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, DemandObject.class); + DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); + + boolean blue = rand.nextBoolean(); + if (blue == true) { + builder.addRequirement(new BlueRequirement()); + } + else { + builder.addRequirement(new RedRequirement()); + } + + DemandObject demandObject = builder.build(); + demandObjects.add(demandObject); + } + } + + @Test + public void testRequirementsTransferrer() { + for(DemandObject demandObject : demandObjects) { + Offer offer = offerLSP.getOffer(demandObject, "nonsense", null); + for(Requirement requirement : demandObject.getRequirements()) { + if(requirement instanceof RedRequirement) { + assertTrue(offer.getSolution() == redOfferSolution); + } + if(requirement instanceof BlueRequirement) { + assertTrue(offer.getSolution() == blueOfferSolution); + } + } + } + } + + + + + + +} diff --git a/test/testLSPWithCostTracker/CollectionServiceHandler.java b/test/testLSPWithCostTracker/CollectionServiceHandler.java new file mode 100644 index 00000000000..e458f1aa765 --- /dev/null +++ b/test/testLSPWithCostTracker/CollectionServiceHandler.java @@ -0,0 +1,87 @@ +package testLSPWithCostTracker; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.events.ServiceBeginsEvent; +import lsp.events.ServiceBeginsEventHandler; +import lsp.events.ServiceCompletedEvent; +import lsp.events.ServiceCompletedEventHandler; + + +public class CollectionServiceHandler implements ServiceBeginsEventHandler, ServiceCompletedEventHandler{ + + + + private class ServiceTuple { + private CarrierService service; + private double startTime; + + public ServiceTuple(CarrierService service, double startTime) { + this.service = service; + this.startTime = startTime; + } + + public CarrierService getService() { + return service; + } + + public double getStartTime() { + return startTime; + } + + } + + private Collection tuples; + private double totalLoadingCosts; + private int totalNumberOfShipments; + private int totalWeightOfShipments; + + public CollectionServiceHandler() { + this.tuples = new ArrayList(); + } + + @Override + public void reset(int iteration) { + tuples.clear(); + totalNumberOfShipments = 0; + totalWeightOfShipments = 0; + } + + @Override + public void handleEvent(ServiceCompletedEvent event) { + System.out.println("Service Ends"); + double loadingCosts = 0; + for(ServiceTuple tuple : tuples) { + if(tuple.getService() == event.getService()) { + double serviceDuration = event.getTime() - tuple.getStartTime(); + loadingCosts = serviceDuration * event.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; + totalLoadingCosts = totalLoadingCosts + loadingCosts; + tuples.remove(tuple); + break; + } + } + } + + @Override + public void handleEvent(ServiceBeginsEvent event) { + totalNumberOfShipments++; + totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); + tuples.add(new ServiceTuple(event.getService(), event.getTime())); + } + + public double getTotalLoadingCosts() { + return totalLoadingCosts; + } + + public int getTotalNumberOfShipments() { + return totalNumberOfShipments; + } + + public int getTotalWeightOfShipments() { + return totalWeightOfShipments; + } + +} diff --git a/test/testLSPWithCostTracker/CollectionTrackerTest.java b/test/testLSPWithCostTracker/CollectionTrackerTest.java new file mode 100644 index 00000000000..ff6b375406c --- /dev/null +++ b/test/testLSPWithCostTracker/CollectionTrackerTest.java @@ -0,0 +1,210 @@ +package testLSPWithCostTracker; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.controler.LSPModule; +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.resources.Resource; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; + + + +public class CollectionTrackerTest { + + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private LogisticsSolution collectionSolution; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + collectionSolution = collectionSolutionBuilder.build(); + + + LinearCostTracker tracker = new LinearCostTracker(0.2); + tracker.getEventHandlers().add(new TourStartHandler()); + tracker.getEventHandlers().add(new CollectionServiceHandler()); + tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); + + collectionSolution.addSimulationTracker(tracker); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 2; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + + + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionTracker() { + assertTrue(collectionSolution.getInfos().size() == 1); + Info info = collectionSolution.getInfos().iterator().next(); + assertTrue(info instanceof CostInfo); + CostInfo costInfo = (CostInfo) info; + assertTrue(costInfo.getFunction() instanceof CostInfoFunction); + CostInfoFunction function = (CostInfoFunction) costInfo.getFunction(); + ArrayList values = new ArrayList(function.getValues()); + assertTrue(values.get(0).getDataType() == Double.class); + assertTrue(Double.valueOf(values.get(0).getValue()) > 0); + System.out.println(Double.valueOf(values.get(0).getValue())); + assertTrue(values.get(1).getDataType() == Double.class); + assertTrue(Double.valueOf(values.get(1).getValue()) > 0); + System.out.println(Double.valueOf(values.get(0).getValue())); + } + +} diff --git a/test/testLSPWithCostTracker/CostInfo.java b/test/testLSPWithCostTracker/CostInfo.java new file mode 100644 index 00000000000..d454d8aff25 --- /dev/null +++ b/test/testLSPWithCostTracker/CostInfo.java @@ -0,0 +1,42 @@ +package testLSPWithCostTracker; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; + +public class CostInfo extends Info { + + private CostInfoFunction costFunction; + + public CostInfo() { + this.costFunction = new CostInfoFunction(); + } + + + @Override + public String getName() { + return "cost_function"; + } + + @Override + public InfoFunction getFunction() { + return costFunction; + } + + @Override + public double getFromTime() { + return 0; + } + + @Override + public double getToTime() { + return Double.MAX_VALUE; + } + + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/test/testLSPWithCostTracker/CostInfoFunction.java b/test/testLSPWithCostTracker/CostInfoFunction.java new file mode 100644 index 00000000000..a4b2ca1b0c8 --- /dev/null +++ b/test/testLSPWithCostTracker/CostInfoFunction.java @@ -0,0 +1,31 @@ +package testLSPWithCostTracker; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; + + + +public class CostInfoFunction implements InfoFunction { + + private FixedCostFunctionValue fixedValue; + private LinearCostFunctionValue linearValue; + private Collection values; + + public CostInfoFunction() { + values = new ArrayList(); + fixedValue = new FixedCostFunctionValue(); + linearValue = new LinearCostFunctionValue(); + values.add(fixedValue); + values.add(linearValue); + + } + + @Override + public Collection getValues() { + return values; + } + +} diff --git a/test/testLSPWithCostTracker/DistanceAndTimeHandler.java b/test/testLSPWithCostTracker/DistanceAndTimeHandler.java new file mode 100644 index 00000000000..d5b1d27b3b8 --- /dev/null +++ b/test/testLSPWithCostTracker/DistanceAndTimeHandler.java @@ -0,0 +1,81 @@ +package testLSPWithCostTracker; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; + +import lsp.events.FreightLinkEnterEvent; +import lsp.events.FreightLinkLeaveEvent; +import lsp.events.FreightLinkLeaveEventHandler; +import lsp.events.FreightVehicleLeavesTrafficEvent; +import lsp.events.FreightVehicleLeavesTrafficEventHandler; +import lsp.usecase.FreightLinkEnterEventHandler; + + +public class DistanceAndTimeHandler implements FreightLinkEnterEventHandler, FreightVehicleLeavesTrafficEventHandler, FreightLinkLeaveEventHandler { + + private Collection events; + private double distanceCosts; + private double timeCosts; + private Network network; + + public DistanceAndTimeHandler(Network network) { + this.network = network; + this.events = new ArrayList(); + } + + + @Override + public void handleEvent(FreightLinkEnterEvent event) { + events.add(event); + + } + + @Override + public void reset(int iteration) { + events.clear(); + } + + + @Override + public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } + + + @Override + public void handleEvent(FreightLinkLeaveEvent leaveEvent) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } + + public double getDistanceCosts() { + return distanceCosts; + } + + public double getTimeCosts() { + return timeCosts; + } + +} diff --git a/test/testLSPWithCostTracker/FixedCostFunctionValue.java b/test/testLSPWithCostTracker/FixedCostFunctionValue.java new file mode 100644 index 00000000000..64241f60723 --- /dev/null +++ b/test/testLSPWithCostTracker/FixedCostFunctionValue.java @@ -0,0 +1,29 @@ +package testLSPWithCostTracker; + +import lsp.functions.InfoFunctionValue; + +public class FixedCostFunctionValue implements InfoFunctionValue { + + private String value; + + @Override + public String getName() { + return "fixed"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + +} diff --git a/test/testLSPWithCostTracker/LinearCostFunctionValue.java b/test/testLSPWithCostTracker/LinearCostFunctionValue.java new file mode 100644 index 00000000000..81cccb79dff --- /dev/null +++ b/test/testLSPWithCostTracker/LinearCostFunctionValue.java @@ -0,0 +1,29 @@ +package testLSPWithCostTracker; + +import lsp.functions.InfoFunctionValue; + +public class LinearCostFunctionValue implements InfoFunctionValue { + + private String value; + + @Override + public String getName() { + return "linear"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + +} diff --git a/test/testLSPWithCostTracker/LinearCostTracker.java b/test/testLSPWithCostTracker/LinearCostTracker.java new file mode 100644 index 00000000000..711a37de951 --- /dev/null +++ b/test/testLSPWithCostTracker/LinearCostTracker.java @@ -0,0 +1,102 @@ +package testLSPWithCostTracker; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.tracking.SimulationTracker; + +public class LinearCostTracker implements SimulationTracker{ + + private Collection eventHandlers; + private Collection infos; + private double distanceCosts; + private double timeCosts; + private double loadingCosts; + private double vehicleFixedCosts; + private int totalNumberOfShipments; + private int totalWeightOfShipments; + + private double fixedUnitCosts; + private double linearUnitCosts; + + private double shareOfFixedCosts; + + public LinearCostTracker(double shareOfFixedCosts) { + this.shareOfFixedCosts = shareOfFixedCosts; + CostInfo costInfo = new CostInfo(); + infos = new ArrayList(); + infos.add(costInfo); + this.eventHandlers = new ArrayList(); + } + + + @Override + public Collection getEventHandlers() { + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + for(EventHandler handler : eventHandlers) { + if(handler instanceof TourStartHandler) { + TourStartHandler startHandler = (TourStartHandler) handler; + this.vehicleFixedCosts = startHandler.getVehicleFixedCosts(); + } + if(handler instanceof DistanceAndTimeHandler) { + DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; + this.distanceCosts = distanceHandler.getDistanceCosts(); + this.timeCosts = distanceHandler.getTimeCosts(); + } + if(handler instanceof CollectionServiceHandler) { + CollectionServiceHandler collectionHandler = (CollectionServiceHandler) handler; + totalNumberOfShipments = collectionHandler.getTotalNumberOfShipments(); + System.out.println(totalNumberOfShipments); + totalWeightOfShipments = collectionHandler.getTotalWeightOfShipments(); + loadingCosts = collectionHandler.getTotalLoadingCosts(); + } + } + + double totalCosts = distanceCosts + timeCosts + loadingCosts + vehicleFixedCosts; + fixedUnitCosts = (totalCosts * shareOfFixedCosts)/totalNumberOfShipments; + linearUnitCosts = (totalCosts * (1-shareOfFixedCosts))/totalWeightOfShipments; + + CostInfo info = (CostInfo) infos.iterator().next(); + for(InfoFunctionValue value : info.getFunction().getValues()) { + if(value instanceof FixedCostFunctionValue) { + ((FixedCostFunctionValue)value).setValue(Double.toString(fixedUnitCosts)); + } + if(value instanceof LinearCostFunctionValue) { + ((LinearCostFunctionValue)value).setValue(Double.toString(linearUnitCosts)); + } + } + + + } + + + @Override + public void reset() { + distanceCosts = 0; + timeCosts = 0; + loadingCosts = 0; + vehicleFixedCosts = 0; + totalNumberOfShipments = 0; + totalWeightOfShipments = 0; + fixedUnitCosts = 0; + linearUnitCosts = 0; + + } + + + +} diff --git a/test/testLSPWithCostTracker/TourStartHandler.java b/test/testLSPWithCostTracker/TourStartHandler.java new file mode 100644 index 00000000000..0f35e6a0edd --- /dev/null +++ b/test/testLSPWithCostTracker/TourStartHandler.java @@ -0,0 +1,24 @@ +package testLSPWithCostTracker; + +import lsp.events.TourStartEvent; +import lsp.events.TourStartEventHandler; + +public class TourStartHandler implements TourStartEventHandler{ + + private double vehicleFixedCosts; + + @Override + public void reset(int iteration) { + vehicleFixedCosts = 0; + } + + @Override + public void handleEvent(TourStartEvent event) { + vehicleFixedCosts = vehicleFixedCosts + event.getVehicle().getVehicleType().getVehicleCostInformation().fix; + } + + public double getVehicleFixedCosts() { + return vehicleFixedCosts; + } + +} diff --git a/test/testMutualReplanning/LotSizeScorer.java b/test/testMutualReplanning/LotSizeScorer.java new file mode 100644 index 00000000000..777f6ae9e8d --- /dev/null +++ b/test/testMutualReplanning/LotSizeScorer.java @@ -0,0 +1,21 @@ +package testMutualReplanning; + +import demand.demandObject.DemandObject; +import demand.scoring.DemandScorer; +import testDemandObjectsWithLotsizes.LotSizeShipment; + +public class LotSizeScorer implements DemandScorer{ + + + + + + @Override + public double scoreCurrentPlan(DemandObject demandObject) { + if(demandObject.getSelectedPlan().getShipment() instanceof LotSizeShipment) { + + } + return 0; + } + +} diff --git a/test/testMutualReplanning/NonsenseOffer.java b/test/testMutualReplanning/NonsenseOffer.java new file mode 100644 index 00000000000..7e3f9664f67 --- /dev/null +++ b/test/testMutualReplanning/NonsenseOffer.java @@ -0,0 +1,52 @@ +package testMutualReplanning; + +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import lsp.LSP; +import lsp.LogisticsSolution; + +public class NonsenseOffer implements Offer{ + + private LSP lsp; + private LogisticsSolution solution; + + + @Override + public LSP getLsp() { + return lsp; + } + + @Override + public LogisticsSolution getSolution() { + return solution; + } + + @Override + public String getType() { + return "nonsense"; + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + + } + + @Override + public void setSolution(LogisticsSolution solution) { + this.solution = solution; + + } + +} diff --git a/test/testMutualReplanning/SimpleOfferRequester.java b/test/testMutualReplanning/SimpleOfferRequester.java new file mode 100644 index 00000000000..777cb0ed224 --- /dev/null +++ b/test/testMutualReplanning/SimpleOfferRequester.java @@ -0,0 +1,35 @@ +package testMutualReplanning; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.OfferRequester; +import demand.offer.Offer; +import lsp.LogisticsSolution; + +public class SimpleOfferRequester implements OfferRequester{ + + private DemandObject demandObject; + + + @Override + public Collection requestOffers(Collection lsps) { + ArrayList offerList = new ArrayList(); + for(LSPWithOffers lsp : lsps) { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + Offer offer = lsp.getOffer(demandObject, "nonsense", solution.getId()); + offerList.add(offer); + } + } + return offerList; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + + } + +} From 14be887abeb0f2527539759d047d683b4e580e31 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 28 Feb 2018 18:26:42 +0100 Subject: [PATCH 0015/1340] Example for customized Scoring added --- .../example/LSPScoring/ExampleLSPScoring.java | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/examples/example/LSPScoring/ExampleLSPScoring.java b/examples/example/LSPScoring/ExampleLSPScoring.java index 5d042e72428..3de573ef0b9 100644 --- a/examples/example/LSPScoring/ExampleLSPScoring.java +++ b/examples/example/LSPScoring/ExampleLSPScoring.java @@ -1,5 +1,225 @@ package example.LSPScoring; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.controler.LSPModule; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.resources.Resource; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; + +/* Example for customized scoring. Each customer that is visited will give a random tip between zero and five + * + * + */ + + public class ExampleLSPScoring { + + public static LSP createLSPWithScorer(Network network) { + + //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + //The Adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + + //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + + LSP lsp = collectionLSPBuilder.build(); + + //Create EventHandler for the SimulationTracker which the scorer needs + TipEventHandler handler = new TipEventHandler(); + + //Create Info for the SimulationTracker which the scorer needs + TipInfoFunctionValue value = new TipInfoFunctionValue(); + TipInfoFunction function = new TipInfoFunction(); + function.getValues().add(value); + TipInfo info = new TipInfo(function); + + //Create SimulationTracker foe the information that the Scorer needs + TipSimulationTracker tracker = new TipSimulationTracker(handler,info); + //add SimulationTracker to the Resource + collectionAdapter.addSimulationTracker(tracker); + + //Create the Scorer and add it to the lsp + TipScorer scorer = new TipScorer(lsp, tracker); + lsp.setScorer(scorer); + + return lsp; + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id toLinkId = collectionLinkId; + + //Create five LSPShipments that are located in the left half of the network. + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + public static void main(String []args) { + + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createLSPWithScorer(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + //schedule the LSP with the shipments and according to the scheduler of the Resource + lsp.scheduleSoultions(); + + //Prepare LSPModule and add the LSP + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + //Start the Mobsim one iteration is sufficient for scoring + Controler controler = new Controler(config); + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + + System.out.println("The tip of all customers was: " + lsp.getSelectedPlan().getScore()); + + } + + } From 0c5ebaff35d3c5296973875999b083cc66c26331 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 28 Feb 2018 18:31:14 +0100 Subject: [PATCH 0016/1340] Unnecessary class removed --- .../LSPScoring/CollectionLSPScoringTest.java | 208 ------------------ 1 file changed, 208 deletions(-) delete mode 100644 examples/example/LSPScoring/CollectionLSPScoringTest.java diff --git a/examples/example/LSPScoring/CollectionLSPScoringTest.java b/examples/example/LSPScoring/CollectionLSPScoringTest.java deleted file mode 100644 index 8b03b9f7e68..00000000000 --- a/examples/example/LSPScoring/CollectionLSPScoringTest.java +++ /dev/null @@ -1,208 +0,0 @@ -package example.LSPScoring; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.controler.LSPModule; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.scoring.LSPScorer; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - - -public class CollectionLSPScoringTest { - - private Network network; - private LSP collectionLSP; - private Carrier carrier; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private LSPScorer trinkgeldScorer; - private TipSimulationTracker trinkgeldTracker; - private TipInfo info; - private TipInfoFunction function; - private TipInfoFunctionValue value; - private int numberOfShipments = 25; - - @Before - public void initialize() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Link collectionLink = network.getLinks().get(collectionLinkId); - if (collectionLink == null) { - System.exit(1); - } - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = adapterBuilder.build(); - - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - collectionElement = collectionElementBuilder.build(); - - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - collectionLSP = collectionLSPBuilder.build(); - - TipEventHandler handler = new TipEventHandler(); - TipInfoFunctionValue value = new TipInfoFunctionValue(); - function = new TipInfoFunction(); - function.getValues().add(value); - info = new TipInfo(function); - trinkgeldTracker = new TipSimulationTracker(handler,info); - collectionAdapter.addSimulationTracker(trinkgeldTracker); - trinkgeldScorer = new TipScorer(collectionLSP, trinkgeldTracker); - collectionLSP.setScorer(trinkgeldScorer); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id toLinkId = collectionLinkId; - - - for(int i = 1; i < (numberOfShipments + 1); i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(10); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - collectionLSP.assignShipmentToLSP(shipment); - } - - collectionLSP.scheduleSoultions(); - - ArrayList lspList = new ArrayList(); - lspList.add(collectionLSP); - LSPs lsps = new LSPs(lspList); - - Controler controler = new Controler(config); - - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); - - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(25); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); - controler.run(); - } - - @Test - public void testCollectionLSPScoring() { - System.out.println(collectionLSP.getSelectedPlan().getScore()); - assertTrue(collectionLSP.getShipments().size() == numberOfShipments); - assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() == numberOfShipments); - assertTrue(collectionLSP.getSelectedPlan().getScore() >0); - assertTrue(collectionLSP.getSelectedPlan().getScore() <=(numberOfShipments*5)); - } - -} From 41cb5d688304abb530a2bb7fb0c21252db9d8664 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 28 Feb 2018 18:34:05 +0100 Subject: [PATCH 0017/1340] Doubled class removed --- examples/examples/ExampleLSPReplanning.java | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 examples/examples/ExampleLSPReplanning.java diff --git a/examples/examples/ExampleLSPReplanning.java b/examples/examples/ExampleLSPReplanning.java deleted file mode 100644 index 7500d8f4bb3..00000000000 --- a/examples/examples/ExampleLSPReplanning.java +++ /dev/null @@ -1,5 +0,0 @@ -package examples; - -public class ExampleLSPReplanning { - -} From ca663dad30d028027d7402e3f5ddc615d47ce349 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 10:52:50 +0100 Subject: [PATCH 0018/1340] Replanning example added --- .../LSPReplanning/ExampleLSPReplanning.java | 223 ++++++++++++++++++ .../GenericStrategyManagerFactoryImpl.java | 22 ++ .../LSPReplanning/TomorrowAssigner.java | 37 +++ ...morrowShipmentAssignerStrategyFactory.java | 58 +++++ 4 files changed, 340 insertions(+) create mode 100644 examples/example/LSPReplanning/ExampleLSPReplanning.java create mode 100644 examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java create mode 100644 examples/example/LSPReplanning/TomorrowAssigner.java create mode 100644 examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java diff --git a/examples/example/LSPReplanning/ExampleLSPReplanning.java b/examples/example/LSPReplanning/ExampleLSPReplanning.java new file mode 100644 index 00000000000..efa1eabbb6e --- /dev/null +++ b/examples/example/LSPReplanning/ExampleLSPReplanning.java @@ -0,0 +1,223 @@ +package example.LSPReplanning; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.replanning.GenericStrategyManager; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import example.LSPScoring.TipEventHandler; +import example.LSPScoring.TipInfo; +import example.LSPScoring.TipInfoFunction; +import example.LSPScoring.TipInfoFunctionValue; +import example.LSPScoring.TipScorer; +import example.LSPScoring.TipSimulationTracker; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.controler.LSPModule; +import lsp.replanning.LSPReplannerImpl; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.resources.Resource; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; + +public class ExampleLSPReplanning { + + public static LSP createLSPWithReplanner(Network network) { + //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + //The Adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + + //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + + LSP lsp = collectionLSPBuilder.build(); + + //Create StrategyManager, insert it in Replanner and add it to the lsp; + GenericStrategyManagerFactoryImpl factory = new GenericStrategyManagerFactoryImpl(); + GenericStrategyManager manager = factory.createStrategyManager(lsp); + LSPReplannerImpl replanner = new LSPReplannerImpl(lsp); + replanner.setStrategyManager(manager); + lsp.setReplanner(replanner); + + return lsp; + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id toLinkId = collectionLinkId; + + //Create five LSPShipments that are located in the left half of the network. + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + public static void main(String[]args) { + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createLSPWithReplanner(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + + //Prepare LSPModule and add the LSP + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + //Start the Mobsim two iterations are necessary for replanning + Controler controler = new Controler(config); + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(4); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + + System.out.println("Shipments delivered today:"); + for(LSPShipment shipment : lsp.getSelectedPlan().getSolutions().iterator().next().getShipments()) { + System.out.println(shipment.getId()); + } + + lsp.getShipments().removeAll(lsp.getSelectedPlan().getSolutions().iterator().next().getShipments()); + + System.out.println("Shipments delivered tomorrow:"); + for(LSPShipment shipment : lsp.getShipments()) { + System.out.println(shipment.getId()); + } + + } + + +} diff --git a/examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java b/examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java new file mode 100644 index 00000000000..b72d29cad87 --- /dev/null +++ b/examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java @@ -0,0 +1,22 @@ +package example.LSPReplanning; + +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.LSP; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; +import lsp.ShipmentAssigner; +import lsp.replanning.LSPPlanStrategyManagerFactory; + +public class GenericStrategyManagerFactoryImpl implements LSPPlanStrategyManagerFactory { + + @Override + public GenericStrategyManager createStrategyManager(LSP lsp) { + GenericStrategyManager strategyManager = new GenericStrategyManager(); + ShipmentAssigner tomorrowAssigner = new TomorrowAssigner(); + tomorrowAssigner.setLSP(lsp); + strategyManager.addStrategy(new TomorrowShipmentAssignerStrategyFactory(tomorrowAssigner).createStrategy(), null, 1); + return strategyManager; + } + +} diff --git a/examples/example/LSPReplanning/TomorrowAssigner.java b/examples/example/LSPReplanning/TomorrowAssigner.java new file mode 100644 index 00000000000..ca276223736 --- /dev/null +++ b/examples/example/LSPReplanning/TomorrowAssigner.java @@ -0,0 +1,37 @@ +package example.LSPReplanning; + +import java.util.Random; + +import lsp.LSP; +import lsp.ShipmentAssigner; +import lsp.shipment.LSPShipment; + +public class TomorrowAssigner implements ShipmentAssigner{ + + private LSP lsp; + private Random random; + + public TomorrowAssigner() { + this.random = new Random(1); + } + + @Override + public void assignShipment(LSPShipment shipment) { + boolean assignToday = random.nextBoolean(); + if(assignToday) { + lsp.getSelectedPlan().getSolutions().iterator().next().assignShipment(shipment); + } + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + + } + + @Override + public LSP getLSP() { + return lsp; + } + +} diff --git a/examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java b/examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java new file mode 100644 index 00000000000..34c9654899f --- /dev/null +++ b/examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java @@ -0,0 +1,58 @@ +package example.LSPReplanning; + +import java.util.Collection; + +import org.matsim.core.replanning.GenericPlanStrategy; +import org.matsim.core.replanning.GenericPlanStrategyImpl; +import org.matsim.core.replanning.ReplanningContext; +import org.matsim.core.replanning.modules.GenericPlanStrategyModule; +import org.matsim.core.replanning.selectors.BestPlanSelector; + +import lsp.LSP; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; +import lsp.ShipmentAssigner; +import lsp.shipment.LSPShipment; + +public class TomorrowShipmentAssignerStrategyFactory { + + private ShipmentAssigner assigner; + + public TomorrowShipmentAssignerStrategyFactory(ShipmentAssigner assigner) { + this.assigner = assigner; + } + + public GenericPlanStrategy createStrategy(){ + GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl( new BestPlanSelector()); + + GenericPlanStrategyModule tomorrowModule = new GenericPlanStrategyModule() { + + @Override + public void prepareReplanning(ReplanningContext replanningContext) { + // TODO Auto-generated method stub + + } + + @Override + public void handlePlan(LSPPlan plan) { + plan.setAssigner(assigner); + LSP lsp = assigner.getLSP(); + Collection shipments = lsp.getShipments(); + for(LSPShipment shipment : shipments) { + assigner.assignShipment(shipment); + } + } + + @Override + public void finishReplanning() { + // TODO Auto-generated method stub + + } + + }; + + strategy.addStrategyModule(tomorrowModule); + return strategy; + } + +} From ac7b6494ef092e32ff21daf4fe53b3156677a0c9 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 11:55:49 +0100 Subject: [PATCH 0019/1340] Mobsim example added --- examples/examples/ExampleMobsimOfSimpleLSP.java | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 examples/examples/ExampleMobsimOfSimpleLSP.java diff --git a/examples/examples/ExampleMobsimOfSimpleLSP.java b/examples/examples/ExampleMobsimOfSimpleLSP.java deleted file mode 100644 index 1cca31889a1..00000000000 --- a/examples/examples/ExampleMobsimOfSimpleLSP.java +++ /dev/null @@ -1,5 +0,0 @@ -package examples; - -public class ExampleMobsimOfSimpleLSP { - -} From b3f5c9021ec19f9c2abc75a4d1c903d1f78394ad Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 13:34:19 +0100 Subject: [PATCH 0020/1340] Another example added --- .../ExampleSchedulingOfTransportChain.java | 361 ++++++++++++++++++ .../ExampleSimulationTrackers.java | 0 .../ExampleSchedulingOfTransportChain.java | 5 - 3 files changed, 361 insertions(+), 5 deletions(-) create mode 100644 examples/example/initialPlans/ExampleSchedulingOfTransportChain.java rename examples/{examples => example/simulationTrackers}/ExampleSimulationTrackers.java (100%) delete mode 100644 examples/examples/ExampleSchedulingOfTransportChain.java diff --git a/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java b/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java new file mode 100644 index 00000000000..515c6629a00 --- /dev/null +++ b/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java @@ -0,0 +1,361 @@ +package example.initialPlans; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; + +/*A transport chain with five elements (collection-> reloading -> main run -> reloading -> delivery) is created and scheduled + * + */ + +public class ExampleSchedulingOfTransportChain { + + public static LSP createInitialLSP(Network network) { + + //The Carrier for collection is created + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(capabilities); + + //The collection adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(collectionCarrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + + //The first reloading adapter i.e. the Resource is created + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + + //The scheduler for the first reloading point is created + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + //The scheduler is added to the Resource and the Resource is created + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + //The SolutionElement for the first reloading point is created + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + + //The Carrier for the main run Resource is created + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + //The adapter i.e. the main run resource is created + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + + //The scheduler for the main run Rescource is created and added to the Resource + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + //The LogisticsSolutionElement for the main run Resource is created + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + + //The second reloading adapter i.e. the Resource is created + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + + //The scheduler for the second reloading point is created + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + //The scheduler is added to the Resource and the Resource is created + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + + //The Carrier for distribution is created + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder distributionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + distributionCapabilitiesBuilder.addType(distributionType); + distributionCapabilitiesBuilder.addVehicle(distributionCarrierVehicle); + distributionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = distributionCapabilitiesBuilder.build(); + Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); + distributionCarrier.setCarrierCapabilities(distributionCapabilities); + + //The distribution adapter i.e. the Resource is created + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setCarrier(distributionCarrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + //The Order of the logisticsSolutionElements is now specified + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + + //The SolutionElements are now inserted into the only LogisticsSolution of the LSP + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + LogisticsSolution completeSolution = completeSolutionBuilder.build(); + + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl completePlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id completeLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(completeLSPId); + + //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + + return completeLSPBuilder.build(); + + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Random rand = new Random(1); + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = rand.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + public static void main (String [] args) { + + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createInitialLSP(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + //schedule the LSP with the shipments and according to the scheduler of the Resource + lsp.scheduleSoultions(); + + //print the schedules for the assigned LSPShipments + for(LSPShipment shipment : lsp.getShipments()) { + ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); + System.out.println("Shipment: " + shipment.getId()); + for(AbstractShipmentPlanElement element : elementList) { + System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime()); + } + System.out.println(); + } + + + + } + +} diff --git a/examples/examples/ExampleSimulationTrackers.java b/examples/example/simulationTrackers/ExampleSimulationTrackers.java similarity index 100% rename from examples/examples/ExampleSimulationTrackers.java rename to examples/example/simulationTrackers/ExampleSimulationTrackers.java diff --git a/examples/examples/ExampleSchedulingOfTransportChain.java b/examples/examples/ExampleSchedulingOfTransportChain.java deleted file mode 100644 index e65278d21b2..00000000000 --- a/examples/examples/ExampleSchedulingOfTransportChain.java +++ /dev/null @@ -1,5 +0,0 @@ -package examples; - -public class ExampleSchedulingOfTransportChain { - -} From bcd2eb32a5cffac0c35750ee57cbff151feba12d Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 13:40:27 +0100 Subject: [PATCH 0021/1340] Another Mobsim example added --- .../ExampleMobsimOfSimpleLSP.java | 217 ++++++++++ .../ExampleMobsimOfTransportChain.java | 380 ++++++++++++++++++ 2 files changed, 597 insertions(+) create mode 100644 examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java create mode 100644 examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java diff --git a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java new file mode 100644 index 00000000000..c867d056f50 --- /dev/null +++ b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java @@ -0,0 +1,217 @@ +package example.mobsimExamples; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.controler.LSPModule; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.resources.Resource; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; + +public class ExampleMobsimOfSimpleLSP { + +public static LSP createInitialLSP(Network network) { + + //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + //The Adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + + //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + + return collectionLSPBuilder.build(); + + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id toLinkId = collectionLinkId; + + //Create five LSPShipments that are located in the left half of the network. + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + + public static void main (String[]args) { + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createInitialLSP(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + //schedule the LSP with the shipments and according to the scheduler of the Resource + lsp.scheduleSoultions(); + + //set up simulation controler and LSPModule + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + Controler controler = new Controler(config); + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + + for(LSPShipment shipment : lsp.getShipments()) { + System.out.println("Shipment: " + shipment.getId()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + System.out.println(); + } + + + } + + +} diff --git a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java new file mode 100644 index 00000000000..49b2601b361 --- /dev/null +++ b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java @@ -0,0 +1,380 @@ +package example.mobsimExamples; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.controler.LSPModule; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.resources.Resource; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; + +public class ExampleMobsimOfTransportChain { + +public static LSP createInitialLSP(Network network) { + + //The Carrier for collection is created + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(capabilities); + + //The collection adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(collectionCarrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + + //The first reloading adapter i.e. the Resource is created + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + + //The scheduler for the first reloading point is created + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + //The scheduler is added to the Resource and the Resource is created + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + //The SolutionElement for the first reloading point is created + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + + //The Carrier for the main run Resource is created + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + //The adapter i.e. the main run resource is created + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + + //The scheduler for the main run Rescource is created and added to the Resource + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + //The LogisticsSolutionElement for the main run Resource is created + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + + //The second reloading adapter i.e. the Resource is created + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + + //The scheduler for the second reloading point is created + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + //The scheduler is added to the Resource and the Resource is created + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + + //The Carrier for distribution is created + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder distributionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + distributionCapabilitiesBuilder.addType(distributionType); + distributionCapabilitiesBuilder.addVehicle(distributionCarrierVehicle); + distributionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = distributionCapabilitiesBuilder.build(); + Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); + distributionCarrier.setCarrierCapabilities(distributionCapabilities); + + //The distribution adapter i.e. the Resource is created + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setCarrier(distributionCarrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + //The Order of the logisticsSolutionElements is now specified + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + + //The SolutionElements are now inserted into the only LogisticsSolution of the LSP + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + LogisticsSolution completeSolution = completeSolutionBuilder.build(); + + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl completePlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id completeLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(completeLSPId); + + //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + + return completeLSPBuilder.build(); + + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Random rand = new Random(1); + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = rand.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + public static void main (String[]args) { + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createInitialLSP(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + //schedule the LSP with the shipments and according to the scheduler of the Resource + lsp.scheduleSoultions(); + + //set up simulation controler and LSPModule + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + Controler controler = new Controler(config); + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + + for(LSPShipment shipment : lsp.getShipments()) { + System.out.println("Shipment: " + shipment.getId()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { + System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + } + System.out.println(); + } + } + + +} From 70c20abdd2597e098003fa9d8f5401da20be5a56 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 14:02:30 +0100 Subject: [PATCH 0022/1340] Simulation tracking example added --- .../CollectionServiceHandler.java | 87 +++++++ .../example/simulationTrackers/CostInfo.java | 42 ++++ .../simulationTrackers/CostInfoFunction.java | 31 +++ .../DistanceAndTimeHandler.java | 81 +++++++ .../ExampleSimulationTrackers.java | 217 +++++++++++++++++- .../FixedCostFunctionValue.java | 29 +++ .../LinearCostFunctionValue.java | 29 +++ .../simulationTrackers/LinearCostTracker.java | 102 ++++++++ .../simulationTrackers/TourStartHandler.java | 24 ++ 9 files changed, 641 insertions(+), 1 deletion(-) create mode 100644 examples/example/simulationTrackers/CollectionServiceHandler.java create mode 100644 examples/example/simulationTrackers/CostInfo.java create mode 100644 examples/example/simulationTrackers/CostInfoFunction.java create mode 100644 examples/example/simulationTrackers/DistanceAndTimeHandler.java create mode 100644 examples/example/simulationTrackers/FixedCostFunctionValue.java create mode 100644 examples/example/simulationTrackers/LinearCostFunctionValue.java create mode 100644 examples/example/simulationTrackers/LinearCostTracker.java create mode 100644 examples/example/simulationTrackers/TourStartHandler.java diff --git a/examples/example/simulationTrackers/CollectionServiceHandler.java b/examples/example/simulationTrackers/CollectionServiceHandler.java new file mode 100644 index 00000000000..86e8f08cb0c --- /dev/null +++ b/examples/example/simulationTrackers/CollectionServiceHandler.java @@ -0,0 +1,87 @@ +package example.simulationTrackers; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.events.ServiceBeginsEvent; +import lsp.events.ServiceBeginsEventHandler; +import lsp.events.ServiceCompletedEvent; +import lsp.events.ServiceCompletedEventHandler; + + +public class CollectionServiceHandler implements ServiceBeginsEventHandler, ServiceCompletedEventHandler{ + + + + private class ServiceTuple { + private CarrierService service; + private double startTime; + + public ServiceTuple(CarrierService service, double startTime) { + this.service = service; + this.startTime = startTime; + } + + public CarrierService getService() { + return service; + } + + public double getStartTime() { + return startTime; + } + + } + + private Collection tuples; + private double totalLoadingCosts; + private int totalNumberOfShipments; + private int totalWeightOfShipments; + + public CollectionServiceHandler() { + this.tuples = new ArrayList(); + } + + @Override + public void reset(int iteration) { + tuples.clear(); + totalNumberOfShipments = 0; + totalWeightOfShipments = 0; + } + + @Override + public void handleEvent(ServiceCompletedEvent event) { + System.out.println("Service Ends"); + double loadingCosts = 0; + for(ServiceTuple tuple : tuples) { + if(tuple.getService() == event.getService()) { + double serviceDuration = event.getTime() - tuple.getStartTime(); + loadingCosts = serviceDuration * event.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; + totalLoadingCosts = totalLoadingCosts + loadingCosts; + tuples.remove(tuple); + break; + } + } + } + + @Override + public void handleEvent(ServiceBeginsEvent event) { + totalNumberOfShipments++; + totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); + tuples.add(new ServiceTuple(event.getService(), event.getTime())); + } + + public double getTotalLoadingCosts() { + return totalLoadingCosts; + } + + public int getTotalNumberOfShipments() { + return totalNumberOfShipments; + } + + public int getTotalWeightOfShipments() { + return totalWeightOfShipments; + } + +} diff --git a/examples/example/simulationTrackers/CostInfo.java b/examples/example/simulationTrackers/CostInfo.java new file mode 100644 index 00000000000..55a607e5353 --- /dev/null +++ b/examples/example/simulationTrackers/CostInfo.java @@ -0,0 +1,42 @@ +package example.simulationTrackers; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; + +public class CostInfo extends Info { + + private CostInfoFunction costFunction; + + public CostInfo() { + this.costFunction = new CostInfoFunction(); + } + + + @Override + public String getName() { + return "cost_function"; + } + + @Override + public InfoFunction getFunction() { + return costFunction; + } + + @Override + public double getFromTime() { + return 0; + } + + @Override + public double getToTime() { + return Double.MAX_VALUE; + } + + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/examples/example/simulationTrackers/CostInfoFunction.java b/examples/example/simulationTrackers/CostInfoFunction.java new file mode 100644 index 00000000000..5d172a544b3 --- /dev/null +++ b/examples/example/simulationTrackers/CostInfoFunction.java @@ -0,0 +1,31 @@ +package example.simulationTrackers; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; + + + +public class CostInfoFunction implements InfoFunction { + + private FixedCostFunctionValue fixedValue; + private LinearCostFunctionValue linearValue; + private Collection values; + + public CostInfoFunction() { + values = new ArrayList(); + fixedValue = new FixedCostFunctionValue(); + linearValue = new LinearCostFunctionValue(); + values.add(fixedValue); + values.add(linearValue); + + } + + @Override + public Collection getValues() { + return values; + } + +} diff --git a/examples/example/simulationTrackers/DistanceAndTimeHandler.java b/examples/example/simulationTrackers/DistanceAndTimeHandler.java new file mode 100644 index 00000000000..715441f0860 --- /dev/null +++ b/examples/example/simulationTrackers/DistanceAndTimeHandler.java @@ -0,0 +1,81 @@ +package example.simulationTrackers; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; + +import lsp.events.FreightLinkEnterEvent; +import lsp.events.FreightLinkLeaveEvent; +import lsp.events.FreightLinkLeaveEventHandler; +import lsp.events.FreightVehicleLeavesTrafficEvent; +import lsp.events.FreightVehicleLeavesTrafficEventHandler; +import lsp.usecase.FreightLinkEnterEventHandler; + + +public class DistanceAndTimeHandler implements FreightLinkEnterEventHandler, FreightVehicleLeavesTrafficEventHandler, FreightLinkLeaveEventHandler { + + private Collection events; + private double distanceCosts; + private double timeCosts; + private Network network; + + public DistanceAndTimeHandler(Network network) { + this.network = network; + this.events = new ArrayList(); + } + + + @Override + public void handleEvent(FreightLinkEnterEvent event) { + events.add(event); + + } + + @Override + public void reset(int iteration) { + events.clear(); + } + + + @Override + public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } + + + @Override + public void handleEvent(FreightLinkLeaveEvent leaveEvent) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } + + public double getDistanceCosts() { + return distanceCosts; + } + + public double getTimeCosts() { + return timeCosts; + } + +} diff --git a/examples/example/simulationTrackers/ExampleSimulationTrackers.java b/examples/example/simulationTrackers/ExampleSimulationTrackers.java index 800252bd36c..4ced3d83cff 100644 --- a/examples/example/simulationTrackers/ExampleSimulationTrackers.java +++ b/examples/example/simulationTrackers/ExampleSimulationTrackers.java @@ -1,5 +1,220 @@ -package examples; +package example.simulationTrackers; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.controler.LSPModule; +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.resources.Resource; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import testLSPWithCostTracker.CollectionServiceHandler; +import testLSPWithCostTracker.DistanceAndTimeHandler; +import testLSPWithCostTracker.LinearCostTracker; +import testLSPWithCostTracker.TourStartHandler; public class ExampleSimulationTrackers { +public static LSP createLSPWithTracker(Network network) { + + //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + + Carrier carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + //The Adapter i.e. the Resource is created + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + + //The scheduler for the Resource is created and added. This is where jsprit comes into play. + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = adapterBuilder.build(); + + //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + //Create cost tracker and add it to solution + LinearCostTracker tracker = new LinearCostTracker(0.2); + tracker.getEventHandlers().add(new TourStartHandler()); + tracker.getEventHandlers().add(new CollectionServiceHandler()); + tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); + collectionSolution.addSimulationTracker(tracker); + + + //The initial plan of the lsp is generated and the assigner and the solution from above are added + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + + //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + + return collectionLSPBuilder.build(); + + } + + public static Collection createInitialLSPShipments(Network network){ + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id toLinkId = collectionLinkId; + + //Create five LSPShipments that are located in the left half of the network. + for(int i = 1; i < 6; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + shipmentList.add(builder.build()); + } + return shipmentList; + } + + + public static void main (String [] args) { + + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createLSPWithTracker(network); + Collection shipments = createInitialLSPShipments(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + //schedule the LSP with the shipments and according to the scheduler of the Resource + lsp.scheduleSoultions(); + + //Prepare LSPModule and add the LSP + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + + //Start the Mobsim one iteration is sufficient for tracking + Controler controler = new Controler(config); + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + + //Retrieve cost info from lsp + Info costInfo; + for(Info info : lsp.getSelectedPlan().getSolutions().iterator().next().getInfos()) { + if(info.getName() == "cost_function") { + costInfo = info; + for(InfoFunctionValue value : costInfo.getFunction().getValues()){ + System.out.println(value.getName() + " " + value.getValue()); + } + } + } + } } diff --git a/examples/example/simulationTrackers/FixedCostFunctionValue.java b/examples/example/simulationTrackers/FixedCostFunctionValue.java new file mode 100644 index 00000000000..cc4e56727e6 --- /dev/null +++ b/examples/example/simulationTrackers/FixedCostFunctionValue.java @@ -0,0 +1,29 @@ +package example.simulationTrackers; + +import lsp.functions.InfoFunctionValue; + +public class FixedCostFunctionValue implements InfoFunctionValue { + + private String value; + + @Override + public String getName() { + return "fixed"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + +} diff --git a/examples/example/simulationTrackers/LinearCostFunctionValue.java b/examples/example/simulationTrackers/LinearCostFunctionValue.java new file mode 100644 index 00000000000..8e8e8ba1dd9 --- /dev/null +++ b/examples/example/simulationTrackers/LinearCostFunctionValue.java @@ -0,0 +1,29 @@ +package example.simulationTrackers; + +import lsp.functions.InfoFunctionValue; + +public class LinearCostFunctionValue implements InfoFunctionValue { + + private String value; + + @Override + public String getName() { + return "linear"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + +} diff --git a/examples/example/simulationTrackers/LinearCostTracker.java b/examples/example/simulationTrackers/LinearCostTracker.java new file mode 100644 index 00000000000..eebba27fc15 --- /dev/null +++ b/examples/example/simulationTrackers/LinearCostTracker.java @@ -0,0 +1,102 @@ +package example.simulationTrackers; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.tracking.SimulationTracker; + +public class LinearCostTracker implements SimulationTracker{ + + private Collection eventHandlers; + private Collection infos; + private double distanceCosts; + private double timeCosts; + private double loadingCosts; + private double vehicleFixedCosts; + private int totalNumberOfShipments; + private int totalWeightOfShipments; + + private double fixedUnitCosts; + private double linearUnitCosts; + + private double shareOfFixedCosts; + + public LinearCostTracker(double shareOfFixedCosts) { + this.shareOfFixedCosts = shareOfFixedCosts; + CostInfo costInfo = new CostInfo(); + infos = new ArrayList(); + infos.add(costInfo); + this.eventHandlers = new ArrayList(); + } + + + @Override + public Collection getEventHandlers() { + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + for(EventHandler handler : eventHandlers) { + if(handler instanceof TourStartHandler) { + TourStartHandler startHandler = (TourStartHandler) handler; + this.vehicleFixedCosts = startHandler.getVehicleFixedCosts(); + } + if(handler instanceof DistanceAndTimeHandler) { + DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; + this.distanceCosts = distanceHandler.getDistanceCosts(); + this.timeCosts = distanceHandler.getTimeCosts(); + } + if(handler instanceof CollectionServiceHandler) { + CollectionServiceHandler collectionHandler = (CollectionServiceHandler) handler; + totalNumberOfShipments = collectionHandler.getTotalNumberOfShipments(); + System.out.println(totalNumberOfShipments); + totalWeightOfShipments = collectionHandler.getTotalWeightOfShipments(); + loadingCosts = collectionHandler.getTotalLoadingCosts(); + } + } + + double totalCosts = distanceCosts + timeCosts + loadingCosts + vehicleFixedCosts; + fixedUnitCosts = (totalCosts * shareOfFixedCosts)/totalNumberOfShipments; + linearUnitCosts = (totalCosts * (1-shareOfFixedCosts))/totalWeightOfShipments; + + CostInfo info = (CostInfo) infos.iterator().next(); + for(InfoFunctionValue value : info.getFunction().getValues()) { + if(value instanceof FixedCostFunctionValue) { + ((FixedCostFunctionValue)value).setValue(Double.toString(fixedUnitCosts)); + } + if(value instanceof LinearCostFunctionValue) { + ((LinearCostFunctionValue)value).setValue(Double.toString(linearUnitCosts)); + } + } + + + } + + + @Override + public void reset() { + distanceCosts = 0; + timeCosts = 0; + loadingCosts = 0; + vehicleFixedCosts = 0; + totalNumberOfShipments = 0; + totalWeightOfShipments = 0; + fixedUnitCosts = 0; + linearUnitCosts = 0; + + } + + + +} diff --git a/examples/example/simulationTrackers/TourStartHandler.java b/examples/example/simulationTrackers/TourStartHandler.java new file mode 100644 index 00000000000..63773d69978 --- /dev/null +++ b/examples/example/simulationTrackers/TourStartHandler.java @@ -0,0 +1,24 @@ +package example.simulationTrackers; + +import lsp.events.TourStartEvent; +import lsp.events.TourStartEventHandler; + +public class TourStartHandler implements TourStartEventHandler{ + + private double vehicleFixedCosts; + + @Override + public void reset(int iteration) { + vehicleFixedCosts = 0; + } + + @Override + public void handleEvent(TourStartEvent event) { + vehicleFixedCosts = vehicleFixedCosts + event.getVehicle().getVehicleType().getVehicleCostInformation().fix; + } + + public double getVehicleFixedCosts() { + return vehicleFixedCosts; + } + +} From 331f03042c95c4290c65b584fa5202b040a5ebba Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 14:03:07 +0100 Subject: [PATCH 0023/1340] Renamed some variables --- .../initialPlans/ExampleSchedulingOfInitialPlan.java | 8 +++++++- .../CompleteLSPSchedulingTest.java | 12 +++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java index e8027c8bb0a..465fd100b82 100644 --- a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java +++ b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java @@ -33,6 +33,7 @@ import lsp.SolutionScheduler; import lsp.resources.Resource; import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; import lsp.usecase.CollectionCarrierAdapter; @@ -178,7 +179,12 @@ public static void main(String [] args) { //print the schedules for the assigned LSPShipments for(LSPShipment shipment : shipments) { System.out.println("Shipment: " + shipment.getId()); - for(AbstractShipmentPlanElement element : shipment.getSchedule().getPlanElements().values()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement element : shipment.getSchedule().getPlanElements().values()) { System.out.println("Solution Id: " + element.getSolutionElement().getLogisticsSolution().getId() + " SolutionElement Id: " + element.getSolutionElement().getId() + " Resource Id: " + element.getResourceId() diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index 70a74fa4fca..8a2e4180d77 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -58,7 +58,6 @@ public class CompleteLSPSchedulingTest { private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP completeLSP; - private Carrier carrier; private Resource completeAdapter; private LogisticsSolutionElement completeElement; @@ -70,7 +69,6 @@ public void initialize() { new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); this.network = scenario.getNetwork(); - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); @@ -195,7 +193,7 @@ public void initialize() { CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); distributionCarrierVehicle.setVehicleType(distributionType); @@ -204,14 +202,14 @@ public void initialize() { capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); - Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); - carrier.setCarrierCapabilities(distributionCapabilities); + Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); + distributionCarrier.setCarrierCapabilities(distributionCapabilities); Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setCarrier(distributionCarrier); distributionAdapterBuilder.setLocationLinkId(distributionLinkId); Resource distributionAdapter = distributionAdapterBuilder.build(); @@ -261,7 +259,7 @@ public void initialize() { ArrayList linkList = new ArrayList(network.getLinks().values()); Random rand = new Random(1); - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 6; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); int capacityDemand = rand.nextInt(10); From f8e4221a8cad849441406f503ea7ada18c50e5b0 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Thu, 1 Mar 2018 15:51:21 +0100 Subject: [PATCH 0024/1340] Example for requirements testing added --- .../requirementsChecking/BlueInfo.java | 44 ++++ .../BlueInfoFunctionValue.java | 30 +++ .../requirementsChecking/BlueRequirement.java | 19 ++ .../ExampleCheckRequirementsOfAssigner.java | 239 ++++++++++++++++++ ...leCheckRequirementsOfOfferTransferrer.java | 236 +++++++++++++++++ .../requirementsChecking/NonsenseOffer.java | 52 ++++ .../example/requirementsChecking/RedInfo.java | 44 ++++ .../RedInfoFunctionValue.java | 30 +++ .../requirementsChecking/RedRequirement.java | 19 ++ .../RequirementsAssigner.java | 49 ++++ .../RequirementsTransferrer.java | 59 +++++ .../assignerRequirementsTest.java | 2 +- .../transferrerRequirementsTest.java | 2 +- 13 files changed, 823 insertions(+), 2 deletions(-) create mode 100644 examples/example/requirementsChecking/BlueInfo.java create mode 100644 examples/example/requirementsChecking/BlueInfoFunctionValue.java create mode 100644 examples/example/requirementsChecking/BlueRequirement.java create mode 100644 examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java create mode 100644 examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java create mode 100644 examples/example/requirementsChecking/NonsenseOffer.java create mode 100644 examples/example/requirementsChecking/RedInfo.java create mode 100644 examples/example/requirementsChecking/RedInfoFunctionValue.java create mode 100644 examples/example/requirementsChecking/RedRequirement.java create mode 100644 examples/example/requirementsChecking/RequirementsAssigner.java create mode 100644 examples/example/requirementsChecking/RequirementsTransferrer.java diff --git a/examples/example/requirementsChecking/BlueInfo.java b/examples/example/requirementsChecking/BlueInfo.java new file mode 100644 index 00000000000..0caa6c56570 --- /dev/null +++ b/examples/example/requirementsChecking/BlueInfo.java @@ -0,0 +1,44 @@ +package example.requirementsChecking; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; + +public class BlueInfo extends Info{ + + private InfoFunctionImpl blueInfoFunction; + + public BlueInfo() { + blueInfoFunction = new InfoFunctionImpl(); + blueInfoFunction.getValues().add(new BlueInfoFunctionValue()); + } + + @Override + public String getName() { + return "blue"; + } + + @Override + public InfoFunction getFunction() { + return blueInfoFunction; + } + + @Override + public double getFromTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public double getToTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/examples/example/requirementsChecking/BlueInfoFunctionValue.java b/examples/example/requirementsChecking/BlueInfoFunctionValue.java new file mode 100644 index 00000000000..c7ffddbac1c --- /dev/null +++ b/examples/example/requirementsChecking/BlueInfoFunctionValue.java @@ -0,0 +1,30 @@ +package example.requirementsChecking; + +import java.awt.Color; + +import lsp.functions.InfoFunctionValue; + +public class BlueInfoFunctionValue implements InfoFunctionValue{ + + @Override + public String getName() { + return "blue"; + } + + @Override + public Class getDataType() { + return Color.class; + } + + @Override + public String getValue() { + return "blue"; + } + + @Override + public void setValue(String value) { + // TODO Auto-generated method stub + + } + +} diff --git a/examples/example/requirementsChecking/BlueRequirement.java b/examples/example/requirementsChecking/BlueRequirement.java new file mode 100644 index 00000000000..cfa6703667a --- /dev/null +++ b/examples/example/requirementsChecking/BlueRequirement.java @@ -0,0 +1,19 @@ +package example.requirementsChecking; + +import lsp.functions.Info; +import lsp.LogisticsSolution; +import lsp.shipment.Requirement; + +public class BlueRequirement implements Requirement{ + + @Override + public boolean checkRequirement(LogisticsSolution solution) { + for(Info info : solution.getInfos()) { + if(info instanceof BlueInfo) { + return true; + } + } + return false; + } + +} diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java new file mode 100644 index 00000000000..b4a8d7ec4bb --- /dev/null +++ b/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java @@ -0,0 +1,239 @@ +package example.requirementsChecking; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import requirementsCheckerTests.BlueInfo; +import requirementsCheckerTests.BlueRequirement; +import requirementsCheckerTests.RedInfo; +import requirementsCheckerTests.RedRequirement; +import requirementsCheckerTests.RequirementsAssigner; + +public class ExampleCheckRequirementsOfAssigner { + + public static LSP createLSPWithProperties(Network network) { + + //Create red LogisticsSolution which has the corresponding info + CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); + Id redCarrierId = Id.create("RedCarrier", Carrier.class); + Id vehicleTypeId = Id.create("RedCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id redVehicleId = Id.createVehicleId("RedVehicle"); + CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId); + redVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder redCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + redCapabilitiesBuilder.addType(collectionType); + redCapabilitiesBuilder.addVehicle(redVehicle); + redCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities redCapabilities = redCapabilitiesBuilder.build(); + Carrier redCarrier = CarrierImpl.newInstance(redCarrierId); + redCarrier.setCarrierCapabilities(redCapabilities); + + Id redAdapterId = Id.create("RedCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder redAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(redAdapterId, network); + redAdapterBuilder.setCollectionScheduler(redScheduler); + redAdapterBuilder.setCarrier(redCarrier); + redAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource redAdapter = redAdapterBuilder.build(); + + Id redElementId = Id.create("RedElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder redElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(redElementId); + redElementBuilder.setResource(redAdapter); + LogisticsSolutionElement redElement = redElementBuilder.build(); + + Id redSolutionId = Id.create("RedSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder redSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(redSolutionId); + redSolutionBuilder.addSolutionElement(redElement); + LogisticsSolution redSolution = redSolutionBuilder.build(); + + //Add info that shows the world the color of the solution + redSolution.getInfos().add(new RedInfo()); + + + //Create blue LogisticsSolution which has the corresponding info + CollectionCarrierScheduler blueScheduler = new CollectionCarrierScheduler(); + Id blueCarrierId = Id.create("BlueCarrier", Carrier.class); + Id blueVehicleId = Id.createVehicleId("BlueVehicle"); + CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId); + blueVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + blueCapabilitiesBuilder.addType(collectionType); + blueCapabilitiesBuilder.addVehicle(blueVehicle); + blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); + Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); + blueCarrier.setCarrierCapabilities(blueCapabilities); + + Id blueAdapterId = Id.create("BlueCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder blueAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(blueAdapterId, network); + blueAdapterBuilder.setCollectionScheduler(blueScheduler); + blueAdapterBuilder.setCarrier(blueCarrier); + blueAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource blueAdapter = blueAdapterBuilder.build(); + + Id blueElementId = Id.create("BlueCElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder blueElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(blueElementId); + blueElementBuilder.setResource(blueAdapter); + LogisticsSolutionElement blueElement = blueElementBuilder.build(); + + Id blueSolutionId = Id.create("BlueSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder blueSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(blueSolutionId); + blueSolutionBuilder.addSolutionElement(blueElement); + LogisticsSolution blueSolution = blueSolutionBuilder.build(); + + //Add info that shows the world the color of the solution + blueSolution.getInfos().add(new BlueInfo()); + + //Create the initial plan, add assigner that checks requirements of the shipments when assigning and add both solutions (red and blue) to the + //plan. + LSPPlan plan = new LSPPlanImpl(); + ShipmentAssigner assigner = new RequirementsAssigner(); + plan.setAssigner(assigner); + plan.addSolution(redSolution); + plan.addSolution(blueSolution); + + LSPImpl.Builder lspBuilder = LSPImpl.Builder.getInstance(); + lspBuilder.setInitialPlan(plan); + Id lspId = Id.create("CollectionLSP", LSP.class); + lspBuilder.setId(lspId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(redAdapter); + resourcesList.add(blueAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + lspBuilder.setSolutionScheduler(simpleScheduler); + return lspBuilder.build(); + } + + public static Collection createShipmentsWithRequirements(Network network){ + //Create ten shipments with either a red or blue requirement, i.e. that they only can be transported in a solution with the matching color + ArrayList shipmentList = new ArrayList(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id toLinkId = collectionLinkId; + + Random rand = new Random(1); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = rand.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + boolean blue = rand.nextBoolean(); + if (blue == true) { + builder.addRequirement(new BlueRequirement()); + } + else { + builder.addRequirement(new RedRequirement()); + } + + shipmentList.add(builder.build()); + } + + return shipmentList; + } + + public static void main (String[]args) { + + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and shipments + LSP lsp = createLSPWithProperties(network); + Collection shipments = createShipmentsWithRequirements(network); + + //assign the shipments to the LSP + for(LSPShipment shipment : shipments) { + lsp.assignShipmentToLSP(shipment); + } + + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + if(solution.getId().toString() == "RedSolution") { + for(LSPShipment shipment : solution.getShipments()) { + if(!(shipment.getRequirements().iterator().next() instanceof RedRequirement)) { + break; + } + } + System.out.println("All shipments in " + solution.getId() + " are red"); + } + if(solution.getId().toString() == "BlueSolution") { + for(LSPShipment shipment : solution.getShipments()) { + if(!(shipment.getRequirements().iterator().next() instanceof BlueRequirement)) { + break; + } + } + System.out.println("All shipments in " + solution.getId() + " are blue"); + } + } + + } + +} diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java new file mode 100644 index 00000000000..d4e30b621b7 --- /dev/null +++ b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java @@ -0,0 +1,236 @@ +package example.requirementsChecking; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPPlanDecorator; +import demand.decoratedLSP.LSPPlanWithOfferTransferrer; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjectImpl; +import demand.offer.Offer; +import demand.offer.OfferFactoryImpl; +import demand.offer.OfferTransferrer; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.shipment.Requirement; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import requirementsCheckerTests.BlueInfo; +import requirementsCheckerTests.BlueRequirement; +import requirementsCheckerTests.NonsenseOffer; +import requirementsCheckerTests.RedInfo; +import requirementsCheckerTests.RedRequirement; +import requirementsCheckerTests.RequirementsTransferrer; + +public class ExampleCheckRequirementsOfOfferTransferrer { + + public static LSPDecorator createLSPWithProperties(Network network) { + + //Create red LogisticsSolution which has the corresponding info + CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); + Id redCarrierId = Id.create("RedCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id redVehicleId = Id.createVehicleId("RedVehicle"); + CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId); + redVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder redCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + redCapabilitiesBuilder.addType(collectionType); + redCapabilitiesBuilder.addVehicle(redVehicle); + redCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities redCapabilities = redCapabilitiesBuilder.build(); + Carrier redCarrier = CarrierImpl.newInstance(redCarrierId); + redCarrier.setCarrierCapabilities(redCapabilities); + + Id redAdapterId = Id.create("RedCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder redAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(redAdapterId, network); + redAdapterBuilder.setCollectionScheduler(redScheduler); + redAdapterBuilder.setCarrier(redCarrier); + redAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource redAdapter = redAdapterBuilder.build(); + + Id redElementId = Id.create("RedElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder redElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(redElementId); + redElementBuilder.setResource(redAdapter); + LogisticsSolutionElement redElement = redElementBuilder.build(); + + Id redSolutionId = Id.create("RedSolution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder redOfferSolutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(redSolutionId); + redOfferSolutionBuilder.addSolutionElement(redElement); + LogisticsSolutionDecorator redOfferSolution = redOfferSolutionBuilder.build(); + + //Add info that shows the world the color of the solution + redOfferSolution.getInfos().add(new RedInfo()); + + //Add OfferFactory that gives some nonsense offer, as in this case only the work of the transferrer i.e. the solution from which the offer + //comes is relevant + OfferFactoryImpl redOfferFactory = new OfferFactoryImpl(redOfferSolution); + redOfferFactory.addOffer(new NonsenseOffer()); + redOfferSolution.setOfferFactory(redOfferFactory); + + + //Create blue LogisticsSolution which has the corresponding info + CollectionCarrierScheduler blueScheduler = new CollectionCarrierScheduler(); + Id blueCarrierId = Id.create("BlueCarrier", Carrier.class); + Id blueVehicleId = Id.createVehicleId("BlueVehicle"); + CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId); + blueVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + blueCapabilitiesBuilder.addType(collectionType); + blueCapabilitiesBuilder.addVehicle(blueVehicle); + blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); + Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); + blueCarrier.setCarrierCapabilities(blueCapabilities); + + Id blueAdapterId = Id.create("BlueCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder blueAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(blueAdapterId, network); + blueAdapterBuilder.setCollectionScheduler(blueScheduler); + blueAdapterBuilder.setCarrier(blueCarrier); + blueAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource blueAdapter = blueAdapterBuilder.build(); + + Id blueElementId = Id.create("BlueElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder blueElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(blueElementId); + blueElementBuilder.setResource(blueAdapter); + LogisticsSolutionElement blueElement = blueElementBuilder.build(); + + Id blueSolutionId = Id.create("BlueSolution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder blueOfferSolutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(blueSolutionId); + blueOfferSolutionBuilder.addSolutionElement(blueElement); + LogisticsSolutionDecorator blueOfferSolution = blueOfferSolutionBuilder.build(); + + //Add info that shows the world the color of the solution + blueOfferSolution.getInfos().add(new BlueInfo()); + + //Add OfferFactory that gives some nonsense offer, as in this case only the work of the transferrer i.e. the solution from which the offer + //comes is relevant + OfferFactoryImpl blueOfferFactory = new OfferFactoryImpl(blueOfferSolution); + blueOfferFactory.addOffer(new NonsenseOffer()); + blueOfferSolution.setOfferFactory(blueOfferFactory); + + //Create PlanDecorator (i.e. Plan that has an OfferTransferrer) and add solutions + LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); + plan.addSolution(redOfferSolution); + plan.addSolution(blueOfferSolution); + + //Create OfferTransferrer that only gives the offer of the suitable solution with the right color to the outside + OfferTransferrer transferrer = new RequirementsTransferrer(); + plan.setOfferTransferrer(transferrer); + + LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); + offerLSPBuilder.setInitialPlan(plan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + offerLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(redAdapter); + resourcesList.add(blueAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + offerLSPBuilder.setSolutionScheduler(simpleScheduler); + return offerLSPBuilder.build(); + + } + + + public static Collection createDemandObjectsWithRequirements(){ + //Create ten demand objects with either a red or blue requirement, i.e. that they only can be transported in a solution with the matching color + ArrayList demandObjects = new ArrayList(); + + Random rand = new Random(1); + + for(int i = 1; i < 11; i++) { + Id id = Id.create(("DemandObject_" + Integer.toString(i)), DemandObject.class); + DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); + builder.setId(id); + + boolean blue = rand.nextBoolean(); + if (blue == true) { + builder.addRequirement(new BlueRequirement()); + } + else { + builder.addRequirement(new RedRequirement()); + } + + DemandObject demandObject = builder.build(); + demandObjects.add(demandObject); + } + + return demandObjects; + } + + + public static void main (String[]args) { + //Set up required MATSim classes + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + //Create LSP and demand objects + LSPDecorator lsp = createLSPWithProperties(network); + Collection demandObjects = createDemandObjectsWithRequirements(); + + for(DemandObject demandObject : demandObjects) { + Offer offer = lsp.getOffer(demandObject, "nonsense", null); + for(Requirement requirement : demandObject.getRequirements()) { + if((requirement instanceof RedRequirement) && (offer.getSolution().getId().toString() == "RedSolution")) { + System.out.println(demandObject.getId() +" is red and gets an offer from a " + offer.getSolution().getId().toString() ); + } + else if((requirement instanceof BlueRequirement) && (offer.getSolution().getId().toString() == "BlueSolution")){ + System.out.println(demandObject.getId() +" is blue and gets an offer from a " + offer.getSolution().getId().toString() ); + } + else { + System.out.println("Wrong sort of offer for " + demandObject.getId()+ ": " + offer.getSolution().getId().toString() + + " was wrong for shipment with " + requirement.getClass()); + } + } + } + + + } + +} diff --git a/examples/example/requirementsChecking/NonsenseOffer.java b/examples/example/requirementsChecking/NonsenseOffer.java new file mode 100644 index 00000000000..e117f2ee9b4 --- /dev/null +++ b/examples/example/requirementsChecking/NonsenseOffer.java @@ -0,0 +1,52 @@ +package example.requirementsChecking; + +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import lsp.LSP; +import lsp.LogisticsSolution; + +public class NonsenseOffer implements Offer{ + + private LSP lsp; + private LogisticsSolution solution; + + + @Override + public LSP getLsp() { + return lsp; + } + + @Override + public LogisticsSolution getSolution() { + return solution; + } + + @Override + public String getType() { + return "nonsense"; + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + + } + + @Override + public void setSolution(LogisticsSolution solution) { + this.solution = solution; + + } + +} diff --git a/examples/example/requirementsChecking/RedInfo.java b/examples/example/requirementsChecking/RedInfo.java new file mode 100644 index 00000000000..35655904fea --- /dev/null +++ b/examples/example/requirementsChecking/RedInfo.java @@ -0,0 +1,44 @@ +package example.requirementsChecking; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; + +public class RedInfo extends Info{ + + private InfoFunctionImpl redInfoFunction; + + public RedInfo() { + redInfoFunction = new InfoFunctionImpl(); + redInfoFunction.getValues().add(new RedInfoFunctionValue()); + } + + @Override + public String getName() { + return "red"; + } + + @Override + public InfoFunction getFunction() { + return redInfoFunction; + } + + @Override + public double getFromTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public double getToTime() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/examples/example/requirementsChecking/RedInfoFunctionValue.java b/examples/example/requirementsChecking/RedInfoFunctionValue.java new file mode 100644 index 00000000000..4462459987b --- /dev/null +++ b/examples/example/requirementsChecking/RedInfoFunctionValue.java @@ -0,0 +1,30 @@ +package example.requirementsChecking; + +import java.awt.Color; + +import lsp.functions.InfoFunctionValue; + +public class RedInfoFunctionValue implements InfoFunctionValue{ + + @Override + public String getName() { + return "red"; + } + + @Override + public Class getDataType() { + return Color.class; + } + + @Override + public String getValue() { + return "red"; + } + + @Override + public void setValue(String value) { + // TODO Auto-generated method stub + + } + +} diff --git a/examples/example/requirementsChecking/RedRequirement.java b/examples/example/requirementsChecking/RedRequirement.java new file mode 100644 index 00000000000..499858d240e --- /dev/null +++ b/examples/example/requirementsChecking/RedRequirement.java @@ -0,0 +1,19 @@ +package example.requirementsChecking; + +import lsp.functions.Info; +import lsp.LogisticsSolution; +import lsp.shipment.Requirement; + +public class RedRequirement implements Requirement{ + + @Override + public boolean checkRequirement(LogisticsSolution solution) { + for(Info info : solution.getInfos()) { + if(info instanceof RedInfo) { + return true; + } + } + return false; + } + +} diff --git a/examples/example/requirementsChecking/RequirementsAssigner.java b/examples/example/requirementsChecking/RequirementsAssigner.java new file mode 100644 index 00000000000..0926cdf5511 --- /dev/null +++ b/examples/example/requirementsChecking/RequirementsAssigner.java @@ -0,0 +1,49 @@ +package example.requirementsChecking; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.ShipmentAssigner; +import lsp.shipment.LSPShipment; +import lsp.shipment.Requirement; + +public class RequirementsAssigner implements ShipmentAssigner { + + private LSP lsp; + private Collection feasibleSolutions; + + public RequirementsAssigner() { + this.feasibleSolutions = new ArrayList(); + } + + @Override + public void assignShipment(LSPShipment shipment) { + feasibleSolutions.clear(); + + label: + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(Requirement requirement : shipment.getRequirements()) { + if(requirement.checkRequirement(solution) == false) { + + continue label; + } + } + feasibleSolutions.add(solution); + } + LogisticsSolution chosenSolution = feasibleSolutions.iterator().next(); + chosenSolution.assignShipment(shipment); + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + @Override + public LSP getLSP() { + return lsp; + } + +} diff --git a/examples/example/requirementsChecking/RequirementsTransferrer.java b/examples/example/requirementsChecking/RequirementsTransferrer.java new file mode 100644 index 00000000000..fb18f221d9c --- /dev/null +++ b/examples/example/requirementsChecking/RequirementsTransferrer.java @@ -0,0 +1,59 @@ +package example.requirementsChecking; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandObject.DemandObject; +import demand.offer.DefaultOfferImpl; +import demand.offer.Offer; +import demand.offer.OfferTransferrer; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.shipment.Requirement; + +public class RequirementsTransferrer implements OfferTransferrer{ + + private LSPDecorator lsp; + private Collection feasibleSolutions; + + public RequirementsTransferrer() { + this.feasibleSolutions = new ArrayList(); + } + + + @Override + public Offer transferOffer(DemandObject object, String type, Id solutionId) { + feasibleSolutions.clear(); + label: + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; + for(Requirement requirement : object.getRequirements()) { + if(requirement.checkRequirement(solutionWithOffers) == false) { + continue label; + } + } + feasibleSolutions.add(solutionWithOffers); + } + + LogisticsSolutionDecorator chosenSolution = feasibleSolutions.iterator().next(); + return chosenSolution.getOffer(object, type); + + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + + @Override + public LSPDecorator getLSP() { + return lsp; + } +} diff --git a/test/requirementsCheckerTests/assignerRequirementsTest.java b/test/requirementsCheckerTests/assignerRequirementsTest.java index ecf337bb423..f875aaccaa9 100644 --- a/test/requirementsCheckerTests/assignerRequirementsTest.java +++ b/test/requirementsCheckerTests/assignerRequirementsTest.java @@ -116,7 +116,7 @@ public void initialize() { CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); blueCapabilitiesBuilder.addType(collectionType); - blueCapabilitiesBuilder.addVehicle(redVehicle); + blueCapabilitiesBuilder.addVehicle(blueVehicle); blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); diff --git a/test/requirementsCheckerTests/transferrerRequirementsTest.java b/test/requirementsCheckerTests/transferrerRequirementsTest.java index d6e0fe2777c..140ba049e77 100644 --- a/test/requirementsCheckerTests/transferrerRequirementsTest.java +++ b/test/requirementsCheckerTests/transferrerRequirementsTest.java @@ -125,7 +125,7 @@ public void initialize() { CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); blueCapabilitiesBuilder.addType(collectionType); - blueCapabilitiesBuilder.addVehicle(redVehicle); + blueCapabilitiesBuilder.addVehicle(blueVehicle); blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); From 9d402ad79015a3ac7393d78d81dd3a509660539a Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 6 Mar 2018 12:25:20 +0100 Subject: [PATCH 0025/1340] Mutual Replanning of LSPs and DemandObjects tested --- examples/example/LSPScoring/TipScorer.java | 8 +- .../requirementsChecking/NonsenseOffer.java | 16 +- .../controler/InitialDemandAssigner.java | 70 +++++ .../controler/MutualControlerListener.java | 203 +++++++------- src/demand/controler/MutualModule.java | 114 -------- src/demand/controler/SupplyClearer.java | 6 +- src/demand/controler/SupplyRescheduler.java | 6 +- src/demand/decoratedLSP/LSPDecorator.java | 2 + src/demand/decoratedLSP/LSPDecorators.java | 40 +++ src/demand/decoratedLSP/LSPPlanDecorator.java | 11 +- .../LSPPlanWithOfferTransferrer.java | 33 ++- src/demand/decoratedLSP/LSPWithOffers.java | 10 +- src/demand/decoratedLSP/LSPsWithOffers.java | 40 --- .../LogisticsSolutionDecorator.java | 1 + .../LogisticsSolutionWithOffers.java | 7 +- src/demand/demandAgent/DemandAgentImpl.java | 2 +- src/demand/demandObject/DemandObjectImpl.java | 16 +- src/demand/demandObject/DemandPlan.java | 77 +----- .../demandObject/DemandPlanGenerator.java | 8 +- src/demand/demandObject/DemandPlanImpl.java | 95 +++++++ src/demand/demandObject/OfferRequester.java | 4 +- src/demand/demandObject/ShipperShipment.java | 2 + .../demandObject/ShipperShipmentImpl.java | 140 ++++++++++ .../DemandPlanStrategyImpl.java | 115 ++++++++ .../mutualReplanning/DemandReplanner.java | 12 +- .../mutualReplanning/DemandReplannerImpl.java | 64 +++++ .../LSPWithOffersReplanner.java | 19 ++ .../MutualReplanningModule.java | 12 +- .../MutualReplanningModuleImpl.java | 21 +- .../OfferReplanningStrategyModule.java | 42 ++- .../OfferReplanningStrategyModuleImpl.java | 52 ++++ src/demand/offer/DefaultOfferImpl.java | 16 +- src/demand/offer/Offer.java | 10 +- src/demand/offer/OfferFactory.java | 5 +- src/demand/offer/OfferFactoryImpl.java | 7 +- .../offer/RequirementsOfferRequester.java | 5 +- src/demand/scoring/DemandScorer.java | 2 +- .../scoring/DemandScoringModuleImpl.java | 30 --- ...ngModule.java => MutualScoringModule.java} | 3 +- .../scoring/MutualScoringModuleImpl.java | 46 ++++ .../demandObjectTests/AllOffersRequester.java | 37 +++ .../DemandObjectBuilderTest.java | 140 ++++++++++ .../FortyTwoDemandScorer.java | 19 ++ .../HalfLotSizeDemandPlanGenerator.java | 40 +++ .../InitialLSPGenerator.java | 252 ++++++++++++++++++ test/demandObjectTests/LinearOffer.java | 85 ++++++ .../SimpleOfferTransferrer.java | 30 +++ test/lspScoringTests/TrinkgeldScorer.java | 6 + .../collectionShipmentBuilderTest.java | 4 +- .../completeShipmentBuilderTest.java | 14 +- .../distributionShipmentBuilderTest.java | 8 +- .../NonsenseOffer.java | 14 +- .../AllOffersRequester.java | 37 +++ .../FortyTwoDemandScorer.java | 19 ++ .../HalfLotSizeDemandPlanGenerator.java | 40 +++ .../InitialLSPGenerator.java | 252 ++++++++++++++++++ test/testMutualReplanning/LinearOffer.java | 85 ++++++ test/testMutualReplanning/LotSizeScorer.java | 21 -- .../MutualReplanningTest.java | 237 ++++++++++++++++ test/testMutualReplanning/NonsenseOffer.java | 52 ---- .../SimpleOfferRequester.java | 35 --- .../SimpleOfferTransferrer.java | 30 +++ 62 files changed, 2265 insertions(+), 564 deletions(-) create mode 100644 src/demand/controler/InitialDemandAssigner.java delete mode 100644 src/demand/controler/MutualModule.java create mode 100644 src/demand/decoratedLSP/LSPDecorators.java delete mode 100644 src/demand/decoratedLSP/LSPsWithOffers.java create mode 100644 src/demand/demandObject/DemandPlanImpl.java create mode 100644 src/demand/demandObject/ShipperShipmentImpl.java create mode 100644 src/demand/mutualReplanning/DemandPlanStrategyImpl.java create mode 100644 src/demand/mutualReplanning/DemandReplannerImpl.java create mode 100644 src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java delete mode 100644 src/demand/scoring/DemandScoringModuleImpl.java rename src/demand/scoring/{DemandScoringModule.java => MutualScoringModule.java} (56%) create mode 100644 src/demand/scoring/MutualScoringModuleImpl.java create mode 100644 test/demandObjectTests/AllOffersRequester.java create mode 100644 test/demandObjectTests/DemandObjectBuilderTest.java create mode 100644 test/demandObjectTests/FortyTwoDemandScorer.java create mode 100644 test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java create mode 100644 test/demandObjectTests/InitialLSPGenerator.java create mode 100644 test/demandObjectTests/LinearOffer.java create mode 100644 test/demandObjectTests/SimpleOfferTransferrer.java create mode 100644 test/testMutualReplanning/AllOffersRequester.java create mode 100644 test/testMutualReplanning/FortyTwoDemandScorer.java create mode 100644 test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java create mode 100644 test/testMutualReplanning/InitialLSPGenerator.java create mode 100644 test/testMutualReplanning/LinearOffer.java delete mode 100644 test/testMutualReplanning/LotSizeScorer.java create mode 100644 test/testMutualReplanning/MutualReplanningTest.java delete mode 100644 test/testMutualReplanning/NonsenseOffer.java delete mode 100644 test/testMutualReplanning/SimpleOfferRequester.java create mode 100644 test/testMutualReplanning/SimpleOfferTransferrer.java diff --git a/examples/example/LSPScoring/TipScorer.java b/examples/example/LSPScoring/TipScorer.java index 33adc7bdf0f..583a8cd46ee 100644 --- a/examples/example/LSPScoring/TipScorer.java +++ b/examples/example/LSPScoring/TipScorer.java @@ -1,7 +1,5 @@ package example.LSPScoring; -import org.matsim.api.core.v01.population.HasPlansAndId; - import lsp.LSP; import lsp.functions.Info; import lsp.functions.InfoFunction; @@ -35,5 +33,11 @@ public double scoreCurrentPlan(LSP lsp) { return score; } + @Override + public void setLSP(LSP lsp) { + // TODO Auto-generated method stub + + } + } diff --git a/examples/example/requirementsChecking/NonsenseOffer.java b/examples/example/requirementsChecking/NonsenseOffer.java index e117f2ee9b4..6b2ed8c9544 100644 --- a/examples/example/requirementsChecking/NonsenseOffer.java +++ b/examples/example/requirementsChecking/NonsenseOffer.java @@ -1,23 +1,23 @@ package example.requirementsChecking; +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; import demand.offer.Offer; import demand.offer.OfferVisitor; -import lsp.LSP; -import lsp.LogisticsSolution; public class NonsenseOffer implements Offer{ - private LSP lsp; - private LogisticsSolution solution; + private LSPDecorator lsp; + private LogisticsSolutionDecorator solution; @Override - public LSP getLsp() { + public LSPDecorator getLsp() { return lsp; } @Override - public LogisticsSolution getSolution() { + public LogisticsSolutionDecorator getSolution() { return solution; } @@ -38,13 +38,13 @@ public void update() { } @Override - public void setLSP(LSP lsp) { + public void setLSP(LSPDecorator lsp) { this.lsp = lsp; } @Override - public void setSolution(LogisticsSolution solution) { + public void setSolution(LogisticsSolutionDecorator solution) { this.solution = solution; } diff --git a/src/demand/controler/InitialDemandAssigner.java b/src/demand/controler/InitialDemandAssigner.java new file mode 100644 index 00000000000..44da6e9494d --- /dev/null +++ b/src/demand/controler/InitialDemandAssigner.java @@ -0,0 +1,70 @@ +package demand.controler; + +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.controler.events.BeforeMobsimEvent; +import org.matsim.core.controler.events.StartupEvent; +import org.matsim.core.controler.listener.BeforeMobsimListener; +import org.matsim.core.controler.listener.StartupListener; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPDecorators; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; +import demand.demandObject.DemandPlan; +import demand.offer.Offer; +import lsp.functions.Info; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class InitialDemandAssigner implements StartupListener{ + + private DemandObjects demandObjects; + private LSPDecorators lsps; + + public InitialDemandAssigner(DemandObjects demandObjects, LSPDecorators lsps) { + this.demandObjects = demandObjects; + this.lsps = lsps; + } + + @Override + public void notifyStartup(StartupEvent event) { + + for(DemandObject demandObject : demandObjects.getDemandObjects().values()) { + if(demandObject.getSelectedPlan() == null) { + createInitialPlan(demandObject); + } + assignShipmentToLSP(demandObject); + } + + for(LSPDecorator lsp : lsps.getLSPs().values()) { + lsp.scheduleSoultions(); + } + } + + private void createInitialPlan(DemandObject demandObject) { + Collection offers = demandObject.getOfferRequester().requestOffers(lsps.getLSPs().values()); + DemandPlan initialPlan = demandObject.getDemandPlanGenerator().createDemandPlan(offers); + demandObject.setSelectedPlan(initialPlan); + } + + private void assignShipmentToLSP(DemandObject demandObject) { + Id id = Id.create(demandObject.getSelectedPlan().getShipment().getId(), LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + builder.setFromLinkId(demandObject.getFromLinkId()); + builder.setToLinkId(demandObject.getToLinkId()); + builder.setCapacityDemand((int)demandObject.getSelectedPlan().getShipment().getShipmentSize()); + builder.setServiceTime(demandObject.getSelectedPlan().getShipment().getServiceTime()); + builder.setStartTimeWindow(demandObject.getSelectedPlan().getShipment().getStartTimeWindow()); + builder.setEndTimeWindow(demandObject.getSelectedPlan().getShipment().getEndTimeWindow()); + for(Info info : demandObject.getInfos()) { + builder.addInfo(info); + } + LSPShipment lspShipment = builder.build(); + demandObject.getSelectedPlan().getLsp().assignShipmentToSolution(lspShipment, demandObject.getSelectedPlan().getSolutionId()); + demandObject.getSelectedPlan().getShipment().setLSPShipment(lspShipment); + } + + +} diff --git a/src/demand/controler/MutualControlerListener.java b/src/demand/controler/MutualControlerListener.java index dd48cf2ffed..94484f9bd3f 100644 --- a/src/demand/controler/MutualControlerListener.java +++ b/src/demand/controler/MutualControlerListener.java @@ -13,18 +13,20 @@ import org.matsim.core.controler.events.IterationEndsEvent; import org.matsim.core.controler.events.ReplanningEvent; import org.matsim.core.controler.events.ScoringEvent; +import org.matsim.core.controler.events.StartupEvent; import org.matsim.core.controler.listener.AfterMobsimListener; import org.matsim.core.controler.listener.BeforeMobsimListener; import org.matsim.core.controler.listener.IterationEndsListener; import org.matsim.core.controler.listener.ReplanningListener; import org.matsim.core.controler.listener.ScoringListener; +import org.matsim.core.controler.listener.StartupListener; import org.matsim.core.events.handler.EventHandler; -import demand.decoratedLSP.LSPsWithOffers; +import demand.decoratedLSP.LSPDecorators; import demand.demandObject.DemandObject; import demand.demandObject.DemandObjects; import demand.mutualReplanning.MutualReplanningModule; -import demand.scoring.DemandScoringModule; +import demand.scoring.MutualScoringModule; import lsp.LSP; import lsp.LSPPlan; import lsp.LogisticsSolution; @@ -37,201 +39,208 @@ import lsp.shipment.LSPShipment; import lsp.tracking.SimulationTracker; -public class MutualControlerListener implements FreightControlerListener, BeforeMobsimListener, AfterMobsimListener, ScoringListener, -ReplanningListener, IterationEndsListener { +public class MutualControlerListener implements FreightControlerListener, BeforeMobsimListener, AfterMobsimListener, + ScoringListener, ReplanningListener, IterationEndsListener, StartupListener { private CarrierResourceTracker carrierResourceTracker; - private Carriers carriers; - private LSPsWithOffers lsps; + private Carriers carriers; + private LSPDecorators lsps; private DemandObjects demandObjects; - private DemandScoringModule demandScoringModule; - private LSPScoringModule lspScoringModule; + private MutualScoringModule mutualScoringModule; private MutualReplanningModule replanningModule; - - - private ArrayList registeredHandlers; - - - @Inject EventsManager eventsManager; - @Inject Network network; - - + + private ArrayList registeredHandlers; + + @Inject + EventsManager eventsManager; @Inject - protected MutualControlerListener(LSPsWithOffers lsps, DemandObjects demandObjects, DemandScoringModule demandScoringModule, LSPScoringModule lspScoringModule, MutualReplanningModule replanningModule) { + Network network; + + @Inject + protected MutualControlerListener(LSPDecorators lsps, DemandObjects demandObjects, + MutualScoringModule demandScoringModule, MutualReplanningModule replanningModule) { this.lsps = lsps; this.demandObjects = demandObjects; - this.demandScoringModule = demandScoringModule; - this.lspScoringModule = lspScoringModule; + this.mutualScoringModule = demandScoringModule; this.replanningModule = replanningModule; this.carriers = getCarriers(); } - + public CarrierResourceTracker getCarrierResourceTracker() { return carrierResourceTracker; } @Override public void notifyIterationEnds(IterationEndsEvent event) { - + SupplyClearer supplyClearer = new SupplyClearer(lsps); supplyClearer.notifyIterationEnds(event); - - for(EventHandler handler : registeredHandlers) { + + for (EventHandler handler : registeredHandlers) { eventsManager.removeHandler(handler); } - - for(LSP lsp : lsps.getLSPs().values()) { - for(LSPShipment shipment : lsp.getShipments()) { + + for (LSP lsp : lsps.getLSPs().values()) { + for (LSPShipment shipment : lsp.getShipments()) { shipment.getEventHandlers().clear(); } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(EventHandler handler : solution.getEventHandlers()) { + + for (LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for (EventHandler handler : solution.getEventHandlers()) { handler.reset(event.getIteration()); } - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - for(EventHandler handler : element.getEventHandlers()) { + for (LogisticsSolutionElement element : solution.getSolutionElements()) { + for (EventHandler handler : element.getEventHandlers()) { handler.reset(event.getIteration()); } - for(EventHandler handler : element.getResource().getEventHandlers()) { + for (EventHandler handler : element.getResource().getEventHandlers()) { handler.reset(event.getIteration()); - } - } - } - } - + } + } + } + } + } @Override public void notifyReplanning(ReplanningEvent event) { - replanningModule.replan(event); + replanningModule.replan(event); } @Override public void notifyScoring(ScoringEvent event) { boolean score = true; - for(LSP lsp : lsps.getLSPs().values()) { - if(lsp.getScorer() == null) { + for (LSP lsp : lsps.getLSPs().values()) { + if (lsp.getScorer() == null) { score = false; } - if(score == true) { - lspScoringModule.scoreLSPs(); - } + if (score == true) { + mutualScoringModule.scoreLSPs(); + } } - - for(DemandObject demandObject : demandObjects.getDemandObjects().values()) { - if(demandObject.getScorer() == null) { + + for (DemandObject demandObject : demandObjects.getDemandObjects().values()) { + if (demandObject.getScorer() == null) { score = false; } - if(score == true) { - demandScoringModule.scoreDemandObjects(); - } + if (score == true) { + mutualScoringModule.scoreDemandObjects(); + } } } @Override public void notifyAfterMobsim(AfterMobsimEvent event) { eventsManager.removeHandler(carrierResourceTracker); - + ArrayList alreadyUpdatedTrackers = new ArrayList(); - for(LSP lsp : lsps.getLSPs().values()) { - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - for(SimulationTracker tracker : element.getResource().getSimulationTrackers()) { - if(!alreadyUpdatedTrackers.contains(tracker)) { + for (LSP lsp : lsps.getLSPs().values()) { + for (LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for (LogisticsSolutionElement element : solution.getSolutionElements()) { + for (SimulationTracker tracker : element.getResource().getSimulationTrackers()) { + if (!alreadyUpdatedTrackers.contains(tracker)) { tracker.notifyAfterMobsim(event); alreadyUpdatedTrackers.add(tracker); tracker.reset(); } } - for(SimulationTracker tracker : element.getSimulationTrackers()) { + for (SimulationTracker tracker : element.getSimulationTrackers()) { tracker.notifyAfterMobsim(event); tracker.reset(); } } - for(SimulationTracker tracker : solution.getSimulationTrackers()) { + for (SimulationTracker tracker : solution.getSimulationTrackers()) { tracker.notifyAfterMobsim(event); tracker.reset(); } } } - - for(LSP lsp : lsps.getLSPs().values()) { - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - for(Info info : element.getInfos()) { + + for (LSP lsp : lsps.getLSPs().values()) { + for (LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for (LogisticsSolutionElement element : solution.getSolutionElements()) { + for (Info info : element.getInfos()) { info.update(); } } - for(Info info : solution.getInfos()) { + for (Info info : solution.getInfos()) { info.update(); - } + } } } - + } @Override public void notifyBeforeMobsim(BeforeMobsimEvent event) { - SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); - rescheduler.notifyBeforeMobsim(event); - + carrierResourceTracker = new CarrierResourceTracker(carriers, network, this); eventsManager.addHandler(carrierResourceTracker); + + SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); + rescheduler.notifyBeforeMobsim(event); + registeredHandlers = new ArrayList(); - - for(LSP lsp : lsps.getLSPs().values()) { - for(LSPShipment shipment : lsp.getShipments()) { - for(EventHandler handler : shipment.getEventHandlers()) { + + for (LSP lsp : lsps.getLSPs().values()) { + for (LSPShipment shipment : lsp.getShipments()) { + for (EventHandler handler : shipment.getEventHandlers()) { eventsManager.addHandler(handler); registeredHandlers.add(handler); } } LSPPlan selectedPlan = lsp.getSelectedPlan(); - for(LogisticsSolution solution : selectedPlan.getSolutions()) { - for(EventHandler handler : solution.getEventHandlers()) { + for (LogisticsSolution solution : selectedPlan.getSolutions()) { + for (EventHandler handler : solution.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + for (LogisticsSolutionElement element : solution.getSolutionElements()) { + for (EventHandler handler : element.getEventHandlers()) { eventsManager.addHandler(handler); registeredHandlers.add(handler); } - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - for(EventHandler handler : element.getEventHandlers()) { + ArrayList resourceHandlers = (ArrayList) element.getResource() + .getEventHandlers(); + for (EventHandler handler : resourceHandlers) { + if (!registeredHandlers.contains(handler)) { eventsManager.addHandler(handler); registeredHandlers.add(handler); - } - ArrayList resourceHandlers = (ArrayList)element.getResource().getEventHandlers(); - for(EventHandler handler : resourceHandlers) { - if(!registeredHandlers.contains(handler)) { - eventsManager.addHandler(handler); - registeredHandlers.add(handler); - } - } } - } - } + } + } + } + } } - public void processEvent(Event event){ - eventsManager.processEvent(event); + public void processEvent(Event event) { + eventsManager.processEvent(event); } private Carriers getCarriers() { Carriers carriers = new Carriers(); - for(LSP lsp : lsps.getLSPs().values()) { + for (LSP lsp : lsps.getLSPs().values()) { LSPPlan selectedPlan = lsp.getSelectedPlan(); - for(LogisticsSolution solution : selectedPlan.getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - if(element.getResource() instanceof CarrierResource) { - + for (LogisticsSolution solution : selectedPlan.getSolutions()) { + for (LogisticsSolutionElement element : solution.getSolutionElements()) { + if (element.getResource() instanceof CarrierResource) { + CarrierResource carrierResource = (CarrierResource) element.getResource(); Carrier carrier = carrierResource.getCarrier(); - if(!carriers.getCarriers().containsKey(carrier.getId())) { + if (!carriers.getCarriers().containsKey(carrier.getId())) { carriers.addCarrier(carrier); } - } + } } } } return carriers; } - + + @Override + public void notifyStartup(StartupEvent event) { + InitialDemandAssigner initialAssigner = new InitialDemandAssigner(demandObjects, lsps); + initialAssigner.notifyStartup(event); + } + } diff --git a/src/demand/controler/MutualModule.java b/src/demand/controler/MutualModule.java deleted file mode 100644 index f2c2a41149e..00000000000 --- a/src/demand/controler/MutualModule.java +++ /dev/null @@ -1,114 +0,0 @@ -package demand.controler; - -import java.util.Collection; - -import org.matsim.contrib.freight.CarrierConfig; -import org.matsim.core.controler.AbstractModule; - -import com.google.inject.Provides; -import com.google.inject.multibindings.Multibinder; - -import demand.decoratedLSP.LSPsWithOffers; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; -import demand.mutualReplanning.MutualReplanningModule; -import demand.scoring.DemandScoringModule; -import lsp.mobsim.CarrierResourceTracker; -import lsp.mobsim.FreightQSimFactory; -import lsp.scoring.LSPScoringModule; - -public class MutualModule extends AbstractModule{ - - private LSPsWithOffers lsps; - private DemandObjects demandObjects; - private DemandScoringModule demandScoringModule; - private LSPScoringModule lspScoringModule; - private MutualReplanningModule replanningModule; - - private CarrierConfig carrierConfig = new CarrierConfig(); - - - - public static class Builder{ - - private LSPsWithOffers lsps; - private DemandObjects demandObjects; - private DemandScoringModule demandScoringModule; - private LSPScoringModule lspScoringModule; - private MutualReplanningModule replanningModule; - - public Builder newInstance() { - return new Builder(); - } - - public Builder setLsps(LSPsWithOffers lsps) { - this.lsps = lsps; - return this; - } - - public Builder setDemandScoringModule(DemandScoringModule demandScoringModule) { - this.demandScoringModule = demandScoringModule; - return this; - } - - public Builder setLSPScoringModule(LSPScoringModule lspScoringModule) { - this.lspScoringModule = lspScoringModule; - return this; - } - - public Builder setMutualReplanningModule(MutualReplanningModule replanningModule) { - this.replanningModule = replanningModule; - return this; - } - - public Builder setDemandObjects(DemandObjects demandObjects) { - this.demandObjects = demandObjects; - return this; - } - - public MutualModule build() { - return new MutualModule(this); - } - } - - private MutualModule(Builder builder) { - this.lsps = builder.lsps; - this.demandObjects = builder.demandObjects; - this.demandScoringModule = builder.demandScoringModule; - this.lspScoringModule = builder.lspScoringModule; - this.replanningModule = builder.replanningModule; - } - - - @Override - public void install() { - bind(CarrierConfig.class).toInstance(carrierConfig); - bind(LSPsWithOffers.class).toInstance(lsps); - bind(DemandObjects.class).toInstance(demandObjects); - - if(replanningModule != null) { - bind(MutualReplanningModule.class).toInstance(replanningModule); - } - if(demandScoringModule != null) { - bind(DemandScoringModule.class).toInstance(demandScoringModule); - } - if(lspScoringModule != null) { - bind(LSPScoringModule.class).toInstance(lspScoringModule); - } - bind(MutualControlerListener.class).asEagerSingleton(); - addControlerListenerBinding().to(MutualControlerListener.class); - bindMobsim().toProvider(FreightQSimFactory.class); - - } - - - @Provides - CarrierResourceTracker provideCarrierResourceTracker(MutualControlerListener mutualControlerListener) { - return mutualControlerListener.getCarrierResourceTracker(); - } - - public void setPhysicallyEnforceTimeWindowBeginnings(boolean physicallyEnforceTimeWindowBeginnings) { - this.carrierConfig.setPhysicallyEnforceTimeWindowBeginnings(physicallyEnforceTimeWindowBeginnings); - } - -} diff --git a/src/demand/controler/SupplyClearer.java b/src/demand/controler/SupplyClearer.java index 53cd95fcc34..e8ab441cebb 100644 --- a/src/demand/controler/SupplyClearer.java +++ b/src/demand/controler/SupplyClearer.java @@ -3,16 +3,16 @@ import org.matsim.core.controler.events.IterationEndsEvent; import org.matsim.core.controler.listener.IterationEndsListener; -import demand.decoratedLSP.LSPsWithOffers; +import demand.decoratedLSP.LSPDecorators; import lsp.LSP; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; public class SupplyClearer implements IterationEndsListener{ - private LSPsWithOffers lsps; + private LSPDecorators lsps; - public SupplyClearer(LSPsWithOffers lsps) { + public SupplyClearer(LSPDecorators lsps) { this.lsps = lsps; } diff --git a/src/demand/controler/SupplyRescheduler.java b/src/demand/controler/SupplyRescheduler.java index 0bd6d2c2665..d52c5e2ff3b 100644 --- a/src/demand/controler/SupplyRescheduler.java +++ b/src/demand/controler/SupplyRescheduler.java @@ -3,15 +3,15 @@ import org.matsim.core.controler.events.BeforeMobsimEvent; import org.matsim.core.controler.listener.BeforeMobsimListener; -import demand.decoratedLSP.LSPsWithOffers; +import demand.decoratedLSP.LSPDecorators; import lsp.LSP; public class SupplyRescheduler implements BeforeMobsimListener{ - private LSPsWithOffers lsps; + private LSPDecorators lsps; - public SupplyRescheduler(LSPsWithOffers lsps) { + public SupplyRescheduler(LSPDecorators lsps) { this.lsps = lsps; } diff --git a/src/demand/decoratedLSP/LSPDecorator.java b/src/demand/decoratedLSP/LSPDecorator.java index c5d6f93ebbd..7e41583b148 100644 --- a/src/demand/decoratedLSP/LSPDecorator.java +++ b/src/demand/decoratedLSP/LSPDecorator.java @@ -8,6 +8,7 @@ import demand.offer.OfferTransferrer; import demand.offer.OfferUpdater; import lsp.LSP; +import lsp.LSPPlan; import lsp.LogisticsSolution; import lsp.shipment.LSPShipment; @@ -17,4 +18,5 @@ public interface LSPDecorator extends LSP { public void assignShipmentToSolution(LSPShipment shipment, Id id); public OfferUpdater getOfferUpdater(); public void setOfferUpdater(OfferUpdater offerUpdater); + public LSPPlanDecorator getSelectedPlan(); } diff --git a/src/demand/decoratedLSP/LSPDecorators.java b/src/demand/decoratedLSP/LSPDecorators.java new file mode 100644 index 00000000000..fbdbb224df8 --- /dev/null +++ b/src/demand/decoratedLSP/LSPDecorators.java @@ -0,0 +1,40 @@ +package demand.decoratedLSP; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.matsim.api.core.v01.Id; + +import lsp.LSP; + + + +public class LSPDecorators { + + private Map, LSPDecorator> lsps = new HashMap<>(); + + public LSPDecorators(Collection lsps) { + makeMap(lsps); + } + + private void makeMap(Collection lsps) { + for (LSPDecorator c : lsps) { + this.lsps.put(c.getId(), c); + } + } + + public LSPDecorators() { + + } + + public Map, LSPDecorator> getLSPs() { + return lsps; + } + + public void addLSP(LSPDecorator lsp) { + if(!lsps.containsKey(lsp.getId())){ + lsps.put(lsp.getId(), lsp); + } + } +} diff --git a/src/demand/decoratedLSP/LSPPlanDecorator.java b/src/demand/decoratedLSP/LSPPlanDecorator.java index 79e0e2c4146..d97abba5308 100644 --- a/src/demand/decoratedLSP/LSPPlanDecorator.java +++ b/src/demand/decoratedLSP/LSPPlanDecorator.java @@ -1,13 +1,20 @@ package demand.decoratedLSP; +import java.util.Collection; + import demand.offer.OfferTransferrer; import demand.offer.OfferUpdater; +import lsp.LSP; import lsp.LSPPlan; +import lsp.LogisticsSolution; +import lsp.ShipmentAssigner; public interface LSPPlanDecorator extends LSPPlan{ public void setOfferTransferrer(OfferTransferrer transferrer); public OfferTransferrer getOfferTransferrer(); - - + public Collection getSolutionDecorators(); + public void addSolution (LogisticsSolutionDecorator solution); + public void setLSP(LSPDecorator lsp); + public LSPDecorator getLsp(); } diff --git a/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java b/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java index 633896af061..6dec808b65b 100644 --- a/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java +++ b/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java @@ -14,12 +14,12 @@ public class LSPPlanWithOfferTransferrer implements LSPPlanDecorator{ private LSPDecorator lsp; private double score; - private Collection solutions; + private Collection solutions; private ShipmentAssigner assigner; private OfferTransferrer transferrer; public LSPPlanWithOfferTransferrer() { - this.solutions = new ArrayList(); + this.solutions = new ArrayList(); this.assigner = new DefaultAssigner(this.lsp); } @@ -38,7 +38,12 @@ public void addSolution(LogisticsSolution solution) { @Override public Collection getSolutions() { - return solutions; + Collection solutionDecorators = new ArrayList(); + for(LogisticsSolution solution : solutions) { + LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; + solutionDecorators.add(solutionDecorator); + } + return solutionDecorators; } @Override @@ -63,7 +68,7 @@ public void setLSP(LSP lsp) { } @Override - public LSP getLsp() { + public LSPDecorator getLsp() { return lsp; } @@ -85,5 +90,25 @@ public void setOfferTransferrer(OfferTransferrer offerTransferrer) { this.transferrer = offerTransferrer; this.transferrer.setLSP(lsp); } + + @Override + public Collection getSolutionDecorators() { + Collection solutionDecorators = new ArrayList(); + for(LogisticsSolution solution : solutions) { + LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; + solutionDecorators.add(solutionDecorator); + } + return solutionDecorators; + } + + @Override + public void addSolution(LogisticsSolutionDecorator solution) { + this.solutions.add(solution); + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } } diff --git a/src/demand/decoratedLSP/LSPWithOffers.java b/src/demand/decoratedLSP/LSPWithOffers.java index d7f5f9e085f..82b2505b82d 100644 --- a/src/demand/decoratedLSP/LSPWithOffers.java +++ b/src/demand/decoratedLSP/LSPWithOffers.java @@ -112,7 +112,13 @@ private LSPWithOffers(LSPWithOffers.Builder builder){ this.selectedPlan.getOfferTransferrer().setLSP(this); this.resources = builder.resources; this.scorer = builder.scorer; + if(this.scorer != null) { + this.scorer.setLSP(this); + } this.replanner = builder.replanner; + if(this.replanner != null) { + this.replanner .setLSP(this); + } this.offerUpdater = builder.offerUpdater; if(offerUpdater != null) { offerUpdater.setLSP(this); @@ -158,7 +164,7 @@ public Collection getResources() { } @Override - public LSPPlan getSelectedPlan() { + public LSPPlanDecorator getSelectedPlan() { selectedPlan.setLSP(this); for(LogisticsSolution solution : selectedPlan.getSolutions()) { if(solution instanceof LogisticsSolutionWithOffers) { @@ -200,7 +206,7 @@ public void scoreSelectedPlan() { @Override public void assignShipmentToLSP(LSPShipment shipment) { - //remains empty, as assignment is done via the OfferTransferrer + this.shipments.add(shipment); } @Override diff --git a/src/demand/decoratedLSP/LSPsWithOffers.java b/src/demand/decoratedLSP/LSPsWithOffers.java deleted file mode 100644 index f0fdf0754b1..00000000000 --- a/src/demand/decoratedLSP/LSPsWithOffers.java +++ /dev/null @@ -1,40 +0,0 @@ -package demand.decoratedLSP; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.Id; - -import lsp.LSP; - - - -public class LSPsWithOffers { - - private Map, LSPWithOffers> lsps = new HashMap<>(); - - public LSPsWithOffers(Collection lsps) { - makeMap(lsps); - } - - private void makeMap(Collection lsps) { - for (LSPWithOffers c : lsps) { - this.lsps.put(c.getId(), c); - } - } - - public LSPsWithOffers() { - - } - - public Map, LSPWithOffers> getLSPs() { - return lsps; - } - - public void addLSP(LSPWithOffers lsp) { - if(!lsps.containsKey(lsp.getId())){ - lsps.put(lsp.getId(), lsp); - } - } -} diff --git a/src/demand/decoratedLSP/LogisticsSolutionDecorator.java b/src/demand/decoratedLSP/LogisticsSolutionDecorator.java index 0710f5500bf..3aeac837601 100644 --- a/src/demand/decoratedLSP/LogisticsSolutionDecorator.java +++ b/src/demand/decoratedLSP/LogisticsSolutionDecorator.java @@ -10,5 +10,6 @@ public interface LogisticsSolutionDecorator extends LogisticsSolution { public Offer getOffer(DemandObject object, String type); public void setOfferFactory(OfferFactory factory); public OfferFactory getOfferFactory(); + public LSPDecorator getLSP(); } diff --git a/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java b/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java index 02b5f34cdf8..2f5e62bedf8 100644 --- a/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java +++ b/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java @@ -118,10 +118,10 @@ public void setLSP(LSP lsp) { } @Override - public LSP getLSP() { + public LSPDecorator getLSP() { return lsp; } - + @Override public Collection getSolutionElements() { return solutionElements; @@ -134,8 +134,7 @@ public Collection getShipments() { @Override public void assignShipment(LSPShipment shipment) { - shipments.add(shipment); - getFirstElement().getIncomingShipments().addShipment(shipment.getStartTimeWindow().getStart(), shipment); + shipments.add(shipment); } private LogisticsSolutionElement getFirstElement(){ diff --git a/src/demand/demandAgent/DemandAgentImpl.java b/src/demand/demandAgent/DemandAgentImpl.java index d8bac96fa0f..e48b971d815 100644 --- a/src/demand/demandAgent/DemandAgentImpl.java +++ b/src/demand/demandAgent/DemandAgentImpl.java @@ -18,7 +18,7 @@ public static class Builder{ private Id id; private ArrayList utilityFunctions; - public Builder newInstance() { + public static Builder newInstance() { return new Builder(); } diff --git a/src/demand/demandObject/DemandObjectImpl.java b/src/demand/demandObject/DemandObjectImpl.java index 775bfa0a253..38eeae532c5 100644 --- a/src/demand/demandObject/DemandObjectImpl.java +++ b/src/demand/demandObject/DemandObjectImpl.java @@ -153,16 +153,30 @@ private DemandObjectImpl(Builder builder) { this.fromLinkId = builder.fromLinkId; this.toLinkId = builder.toLinkId; this.selectedPlan=builder.initialPlan; + if(this.selectedPlan != null) { + this.selectedPlan.setDemandObject(this); + this.selectedPlan.getShipment().setDemandObject(this); + } this.plans.add(builder.initialPlan); this.utilityFunctions = builder.utilityFunctions; this.scorer = builder.scorer; + if(this.scorer != null) { + this.scorer.setDemandObject(this); + } this.replanner = builder.replanner; + if(this.replanner != null) { + this.replanner.setDemandObject(this); + } this.requirements = builder.requirements; this.offerRequester = builder.offerRequester; if(this.offerRequester != null) { this.offerRequester.setDemandObject(this); } this.infos = builder.infos; + this.generator = builder.generator; + if(this.generator != null) { + generator.setDemandObject(this); + } } @@ -241,7 +255,7 @@ public Collection getUtilityFunctions() { } private static DemandPlan copyPlan(DemandPlan plan2copy) { - DemandPlan.Builder builder = DemandPlan.Builder.getInstance(); + DemandPlanImpl.Builder builder = DemandPlanImpl.Builder.newInstance(); builder.setLogisticsSolutionId(plan2copy.getSolutionId()); builder.setLsp(plan2copy.getLsp()); builder.setShipperShipment(plan2copy.getShipment()); diff --git a/src/demand/demandObject/DemandPlan.java b/src/demand/demandObject/DemandPlan.java index 7fe8ce0ff42..b7a5d2f2f23 100644 --- a/src/demand/demandObject/DemandPlan.java +++ b/src/demand/demandObject/DemandPlan.java @@ -3,76 +3,17 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.population.BasicPlan; -import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LSPDecorator; import lsp.LogisticsSolution; - -public class DemandPlan implements BasicPlan{ - - private double score; - private ShipperShipment shipment; - private LSPWithOffers lsp; - private Id solutionId; - - public static class Builder{ - private ShipperShipment shipment; - private LSPWithOffers lsp; - private Id solutionId; - - public static Builder getInstance(){ - return new Builder(); - } - - private Builder(){ - } - - public Builder setShipperShipment(ShipperShipment shipment){ - this.shipment = shipment; - return this; - } - - public Builder setLsp(LSPWithOffers lsp){ - this.lsp = lsp; - return this; - } - - public Builder setLogisticsSolutionId(Id solutionId){ - this.solutionId = solutionId; - return this; - } - - public DemandPlan build() { - return new DemandPlan(this); - } - - } - - private DemandPlan(Builder builder) { - this.shipment = builder.shipment; - this.lsp = builder.lsp; - this.solutionId = builder.solutionId; - } +public interface DemandPlan extends BasicPlan{ - @Override - public Double getScore() { - return score; - } - - @Override - public void setScore(Double arg0) { - this.score = arg0; - } - - public ShipperShipment getShipment() { - return shipment; - } - - public LSPWithOffers getLsp() { - return lsp; - } - - public Id getSolutionId() { - return solutionId; - } + public Double getScore(); + public void setScore(Double arg0); + public ShipperShipment getShipment(); + public LSPDecorator getLsp(); + public Id getSolutionId(); + public DemandObject getDemandObject(); + public void setDemandObject(DemandObject demandObject); } diff --git a/src/demand/demandObject/DemandPlanGenerator.java b/src/demand/demandObject/DemandPlanGenerator.java index a786f98f364..8809ff47ab7 100644 --- a/src/demand/demandObject/DemandPlanGenerator.java +++ b/src/demand/demandObject/DemandPlanGenerator.java @@ -1,7 +1,11 @@ package demand.demandObject; +import java.util.Collection; + +import demand.offer.Offer; + public interface DemandPlanGenerator { - public DemandPlan createDemandPlan(); - + public DemandPlan createDemandPlan(Collection offers); + public void setDemandObject(DemandObject demandObject); } diff --git a/src/demand/demandObject/DemandPlanImpl.java b/src/demand/demandObject/DemandPlanImpl.java new file mode 100644 index 00000000000..69856c1d343 --- /dev/null +++ b/src/demand/demandObject/DemandPlanImpl.java @@ -0,0 +1,95 @@ +package demand.demandObject; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.BasicPlan; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import lsp.LogisticsSolution; + + +public class DemandPlanImpl implements DemandPlan{ + + private double score; + private ShipperShipment shipment; + private LSPDecorator lsp; + private Id solutionId; + private DemandObject demandObject; + + public static class Builder{ + private ShipperShipment shipment; + private LSPDecorator lsp; + private Id solutionId; + private DemandObject demandObject; + + public static Builder newInstance(){ + return new Builder(); + } + + private Builder(){ + } + + public Builder setShipperShipment(ShipperShipment shipment){ + this.shipment = shipment; + return this; + } + + public Builder setLsp(LSPDecorator lsp){ + this.lsp = lsp; + return this; + } + + public Builder setDemandObject(DemandObject demandObject){ + this.demandObject = demandObject; + return this; + } + + public Builder setLogisticsSolutionId(Id solutionId){ + this.solutionId = solutionId; + return this; + } + + public DemandPlanImpl build() { + return new DemandPlanImpl(this); + } + + } + + private DemandPlanImpl(Builder builder) { + this.shipment = builder.shipment; + this.lsp = builder.lsp; + this.solutionId = builder.solutionId; + this.demandObject = builder.demandObject; + } + + @Override + public Double getScore() { + return score; + } + + @Override + public void setScore(Double arg0) { + this.score = arg0; + } + + public ShipperShipment getShipment() { + return shipment; + } + + public LSPDecorator getLsp() { + return lsp; + } + + public Id getSolutionId() { + return solutionId; + } + + public DemandObject getDemandObject() { + return demandObject; + } + + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/src/demand/demandObject/OfferRequester.java b/src/demand/demandObject/OfferRequester.java index 82418cca139..3286fa9a118 100644 --- a/src/demand/demandObject/OfferRequester.java +++ b/src/demand/demandObject/OfferRequester.java @@ -2,11 +2,11 @@ import java.util.Collection; -import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LSPDecorator; import demand.offer.Offer; public interface OfferRequester { - public Collection requestOffers(Collection lsps); + public Collection requestOffers(Collection lsps); public void setDemandObject(DemandObject demandObject); } diff --git a/src/demand/demandObject/ShipperShipment.java b/src/demand/demandObject/ShipperShipment.java index 2d3a98980a5..3910ca5e883 100644 --- a/src/demand/demandObject/ShipperShipment.java +++ b/src/demand/demandObject/ShipperShipment.java @@ -12,7 +12,9 @@ public interface ShipperShipment { public Id getId(); public double getShipmentSize(); public TimeWindow getStartTimeWindow(); + public void setStartTimeWindow(TimeWindow timeWindow); public TimeWindow getEndTimeWindow(); + public void setEndTimeWindow(TimeWindow timeWindow); public double getServiceTime(); public void setLSPShipment(LSPShipment lspShipment); public LSPShipment getLSPShipment(); diff --git a/src/demand/demandObject/ShipperShipmentImpl.java b/src/demand/demandObject/ShipperShipmentImpl.java new file mode 100644 index 00000000000..c673bfdfd1b --- /dev/null +++ b/src/demand/demandObject/ShipperShipmentImpl.java @@ -0,0 +1,140 @@ +package demand.demandObject; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.TimeWindow; + +import lsp.shipment.LSPShipment; + +public class ShipperShipmentImpl implements ShipperShipment{ + + private Id id; + private double shipmentSize; + private TimeWindow startTimeWindow; + private TimeWindow endTimeWindow; + private double serviceTime; + private LSPShipment lspShipment; + private DemandObject demandObject; + + public static class Builder{ + private Id id; + private double shipmentSize; + private TimeWindow startTimeWindow; + private TimeWindow endTimeWindow; + private double serviceTime; + private DemandObject demandObject; + + public static Builder newInstance() { + return new Builder(); + } + + public Builder setId(Id id) { + this.id = id; + return this; + } + + public Builder setShipmentSize(double shipmentSize) { + this.shipmentSize = shipmentSize; + return this; + } + + public Builder setStartTimeWindow(TimeWindow startTimeWindow) { + this.startTimeWindow = startTimeWindow; + return this; + } + + public Builder setEndTimeWindow(TimeWindow endTimeWindow) { + this.endTimeWindow = endTimeWindow; + return this; + } + + public Builder setServiceTime(double serviceTime) { + this.serviceTime = serviceTime; + return this; + } + + public Builder setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + return this; + } + + public ShipperShipment build() { + return new ShipperShipmentImpl(this); + } + } + + private ShipperShipmentImpl(Builder builder) { + this.id = builder.id; + this.shipmentSize = builder.shipmentSize; + if(builder.startTimeWindow == null) { + this.startTimeWindow = TimeWindow.newInstance(0, Double.MAX_VALUE); + } + else { + this.startTimeWindow = builder.startTimeWindow; + } + if(builder.endTimeWindow == null) { + this.endTimeWindow = TimeWindow.newInstance(0, Double.MAX_VALUE); + } + else { + this.endTimeWindow = builder.endTimeWindow; + } + this.serviceTime = builder.serviceTime; + this.demandObject = builder.demandObject; + } + + @Override + public Id getId() { + return id; + } + + @Override + public double getShipmentSize() { + return shipmentSize; + } + + @Override + public TimeWindow getStartTimeWindow() { + return startTimeWindow; + } + + @Override + public TimeWindow getEndTimeWindow() { + return endTimeWindow; + } + + @Override + public double getServiceTime() { + return serviceTime; + } + + @Override + public void setLSPShipment(LSPShipment lspShipment) { + this.lspShipment = lspShipment; + } + + @Override + public LSPShipment getLSPShipment() { + return lspShipment; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + + @Override + public DemandObject getDemandObject() { + return demandObject; + } + + @Override + public void setStartTimeWindow(TimeWindow timeWindow) { + this.startTimeWindow = timeWindow; + } + + @Override + public void setEndTimeWindow(TimeWindow timeWindow) { + this.endTimeWindow = timeWindow; + } + + +} diff --git a/src/demand/mutualReplanning/DemandPlanStrategyImpl.java b/src/demand/mutualReplanning/DemandPlanStrategyImpl.java new file mode 100644 index 00000000000..7f037c3b019 --- /dev/null +++ b/src/demand/mutualReplanning/DemandPlanStrategyImpl.java @@ -0,0 +1,115 @@ +package demand.mutualReplanning; + +import java.util.ArrayList; + +import org.apache.log4j.Logger; +import org.matsim.api.core.v01.population.HasPlansAndId; +import org.matsim.core.replanning.GenericPlanStrategy; +import org.matsim.core.replanning.PlanStrategyImpl; +import org.matsim.core.replanning.ReplanningContext; +import org.matsim.core.replanning.modules.GenericPlanStrategyModule; +import org.matsim.core.replanning.selectors.PlanSelector; +import org.matsim.core.replanning.selectors.RandomUnscoredPlanSelector; + +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; + +public class DemandPlanStrategyImpl implements GenericPlanStrategy { + + private PlanSelector planSelector = null; + private OfferReplanningStrategyModule firstModule = null; + private final ArrayList plans = new ArrayList<>(); + private DemandObject demandObject; + + public DemandPlanStrategyImpl(final PlanSelector planSelector) { + this.planSelector = planSelector; + } + + public DemandPlanStrategyImpl(final PlanSelector planSelector, DemandObject demandObject) { + this.planSelector = planSelector; + this.demandObject = demandObject; + } + + public void addStrategyModule(final GenericPlanStrategyModule module) { + try { + OfferReplanningStrategyModule offerModule = (OfferReplanningStrategyModule) module; + offerModule.setDemandObject(demandObject); + this.firstModule = offerModule; + } + catch(ClassCastException e) { + System.out.println("DemandPlanStrategyImpl expects a module of instance OfferReplanningStrategyModule and not any GenericPlanStrategyModule"); + System.exit(1); + } + } + + public int getNumberOfStrategyModules() { + return 1; + } + + @Override + public void run(final HasPlansAndId person) { + + + // if there is at least one unscored plan, find that one: + DemandPlan plan = new RandomUnscoredPlanSelector().selectPlan(person) ; + + // otherwise, find one according to selector (often defined in PlanStrategy ctor): + if (plan == null) { + plan = this.planSelector.selectPlan(person); + } + + // "select" that plan: + if ( plan != null ) { + person.setSelectedPlan(plan); + } + + // if there is a "module" (i.e. "innovation"): + if (this.firstModule != null) { + + // set the working plan to a copy of the selected plan: + plan = person.createCopyOfSelectedPlanAndMakeSelected(); + + // add new plan to container that contains the plans that are handled by this PlanStrategy: + this.plans.add(plan); + + // start working on this new plan: + this.firstModule.handlePlan(plan); + } + + } + + @Override + public void init(ReplanningContext replanningContext0) { + + if (this.firstModule != null) { + this.firstModule.prepareReplanning(replanningContext0); + } + } + + @Override + public void finish() { + if (this.firstModule != null) { + this.firstModule.finishReplanning(); + + } + this.plans.clear(); + } + + public PlanSelector getPlanSelector() { + return planSelector; + } + + public OfferReplanningStrategyModule getModule() { + return firstModule; + } + + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + + public DemandObject getDemandObject() { + return demandObject; + } +} + + diff --git a/src/demand/mutualReplanning/DemandReplanner.java b/src/demand/mutualReplanning/DemandReplanner.java index eaf89c157be..84bef2c7a9f 100644 --- a/src/demand/mutualReplanning/DemandReplanner.java +++ b/src/demand/mutualReplanning/DemandReplanner.java @@ -5,11 +5,13 @@ import org.matsim.core.controler.events.ReplanningEvent; import org.matsim.core.replanning.GenericStrategyManager; -import lsp.LSP; -import lsp.LSPPlanImpl; +import demand.decoratedLSP.LSPDecorator; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; public interface DemandReplanner { - public void replan(Collection lsps, ReplanningEvent event); - public GenericStrategyManager getStrategyManager(); - public void setStrategyManager(GenericStrategyManager manager); + public void replan(Collection lsps, ReplanningEvent event); + public void addStrategy(DemandPlanStrategyImpl strategy); + public void setDemandObject(DemandObject demandObject); + public DemandObject getDemandObject(); } diff --git a/src/demand/mutualReplanning/DemandReplannerImpl.java b/src/demand/mutualReplanning/DemandReplannerImpl.java new file mode 100644 index 00000000000..11001b2f664 --- /dev/null +++ b/src/demand/mutualReplanning/DemandReplannerImpl.java @@ -0,0 +1,64 @@ +package demand.mutualReplanning; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.replanning.GenericPlanStrategy; +import org.matsim.core.replanning.GenericStrategyManager; + +import demand.decoratedLSP.LSPDecorator; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; + +public class DemandReplannerImpl implements DemandReplanner{ + + private DemandObject demandObject; + private GenericStrategyManager strategyManager; + + + public DemandReplannerImpl(DemandObject demandObject) { + this.demandObject = demandObject; + this.strategyManager = new GenericStrategyManager(); + } + + public DemandReplannerImpl() { + this.strategyManager = new GenericStrategyManager(); + } + + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + + @Override + public void replan(Collection lsps, ReplanningEvent event) { + for(GenericPlanStrategy strategy : strategyManager.getStrategies(null)) { + DemandPlanStrategyImpl demandPlanStrategy = (DemandPlanStrategyImpl) strategy; + demandPlanStrategy.setDemandObject(demandObject); + demandPlanStrategy.getModule().setDemandObject(demandObject); + demandPlanStrategy.getModule().setLSPS(lsps); + } + + if(strategyManager != null) { + ArrayList demandObjectList = new ArrayList <>(); + demandObjectList.add(demandObject); + strategyManager.run(demandObjectList, null, event.getIteration(), event.getReplanningContext()); + } + + } + + + @Override + public void addStrategy(DemandPlanStrategyImpl strategy) { + strategy.setDemandObject(demandObject); + strategyManager.addStrategy(strategy, null, 1); + } + + @Override + public DemandObject getDemandObject() { + return demandObject; + } + +} diff --git a/src/demand/mutualReplanning/LSPWithOffersReplanner.java b/src/demand/mutualReplanning/LSPWithOffersReplanner.java index 59059ebb55c..6f4f2ac160b 100644 --- a/src/demand/mutualReplanning/LSPWithOffersReplanner.java +++ b/src/demand/mutualReplanning/LSPWithOffersReplanner.java @@ -22,6 +22,10 @@ public LSPWithOffersReplanner(LSPDecorator lsp) { this.lsp = lsp; } + public LSPWithOffersReplanner() { + + } + @Override public void replan(ReplanningEvent event) { if(strategyManager != null) { @@ -52,4 +56,19 @@ public void setOfferUpdater(OfferUpdater offerUpdater) { public OfferUpdater getOfferUpdater() { return offerUpdater; } + + @Override + public void setLSP(LSP lsp) { + try { + this.lsp = (LSPWithOffers) lsp; + } + catch(ClassCastException e) { + System.out.println("The class " + this.toString() + " expects an LSPWithOffers and not any other implementation of LSP"); + System.exit(1); + } + } + + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } } diff --git a/src/demand/mutualReplanning/MutualReplanningModule.java b/src/demand/mutualReplanning/MutualReplanningModule.java index d3f0a02137e..4a8a23034a0 100644 --- a/src/demand/mutualReplanning/MutualReplanningModule.java +++ b/src/demand/mutualReplanning/MutualReplanningModule.java @@ -5,18 +5,18 @@ import org.matsim.core.controler.events.ReplanningEvent; import org.matsim.core.controler.listener.ReplanningListener; +import demand.decoratedLSP.LSPDecorator; import demand.demandObject.DemandObject; import demand.demandObject.DemandObjects; -import lsp.LSP; public abstract class MutualReplanningModule implements ReplanningListener{ - protected Collection lsps; + protected Collection lsps; protected Collection demandObjects; - public MutualReplanningModule(Collection lsps, DemandObjects demandObjects ) { + public MutualReplanningModule(Collection lsps, Collection demandObjects) { this.lsps = lsps; - this.demandObjects = demandObjects.getDemandObjects().values(); + this.demandObjects = demandObjects; } public void notifyReplanning(ReplanningEvent event) { @@ -25,12 +25,12 @@ public void notifyReplanning(ReplanningEvent event) { public void replan(ReplanningEvent arg0) { replanLSPs(arg0); - replanDemandObjects(arg0); + replanDemandObjects(arg0, lsps); } abstract void replanLSPs(ReplanningEvent event); - abstract void replanDemandObjects(ReplanningEvent event); + abstract void replanDemandObjects(ReplanningEvent event, Collection lsps); } diff --git a/src/demand/mutualReplanning/MutualReplanningModuleImpl.java b/src/demand/mutualReplanning/MutualReplanningModuleImpl.java index 0870e77fbfa..e9f0b4ce598 100644 --- a/src/demand/mutualReplanning/MutualReplanningModuleImpl.java +++ b/src/demand/mutualReplanning/MutualReplanningModuleImpl.java @@ -4,6 +4,8 @@ import org.matsim.core.controler.events.ReplanningEvent; +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPDecorators; import demand.decoratedLSP.LSPWithOffers; import demand.demandObject.DemandObject; import demand.demandObject.DemandObjects; @@ -11,27 +13,24 @@ public class MutualReplanningModuleImpl extends MutualReplanningModule{ - public MutualReplanningModuleImpl(Collection lsps, DemandObjects demandObjects) { + public MutualReplanningModuleImpl(Collection lsps, Collection demandObjects) { super(lsps, demandObjects); } @Override void replanLSPs(ReplanningEvent event) { - for(LSP lsp : lsps) { - if(lsp instanceof LSPWithOffers) { - LSPWithOffers lspWithOffers = (LSPWithOffers)lsp; - if(lspWithOffers.getReplanner()!= null) { - lspWithOffers.getReplanner().replan(event); - } - if(lspWithOffers.getOfferUpdater()!= null) { - lspWithOffers.getOfferUpdater().updateOffers(); - } + for(LSPDecorator lsp : lsps) { + if(lsp.getReplanner()!= null) { + lsp.getReplanner().replan(event); + } + if(lsp.getOfferUpdater()!= null) { + lsp.getOfferUpdater().updateOffers(); } } } @Override - void replanDemandObjects(ReplanningEvent event) { + void replanDemandObjects(ReplanningEvent event, Collection lsps) { for(DemandObject demandObject : demandObjects) { if(demandObject.getReplanner()!= null) { demandObject.getReplanner().replan(lsps, event); diff --git a/src/demand/mutualReplanning/OfferReplanningStrategyModule.java b/src/demand/mutualReplanning/OfferReplanningStrategyModule.java index 25d68dd2eac..496d25ddc61 100644 --- a/src/demand/mutualReplanning/OfferReplanningStrategyModule.java +++ b/src/demand/mutualReplanning/OfferReplanningStrategyModule.java @@ -5,9 +5,10 @@ import org.matsim.api.core.v01.Id; import org.matsim.core.replanning.modules.GenericPlanStrategyModule; -import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LSPDecorator; import demand.demandObject.DemandObject; import demand.demandObject.DemandPlan; +import demand.demandObject.DemandPlanImpl; import demand.offer.Offer; import lsp.functions.Info; import lsp.shipment.LSPShipment; @@ -16,25 +17,30 @@ public abstract class OfferReplanningStrategyModule implements GenericPlanStrategyModule{ protected DemandObject demandObject; - protected Collection lsps; + protected Collection lsps; + protected DemandPlan plan; - public OfferReplanningStrategyModule(DemandObject demandObject, Collection lsps) { - this.demandObject = demandObject; - this.lsps = lsps; - } + public OfferReplanningStrategyModule() { + + } + public OfferReplanningStrategyModule(DemandObject demandObject) { + this.demandObject = demandObject; + } + @Override public void handlePlan(DemandPlan demandPlan) { Collection offers = recieveOffers(lsps); - DemandPlan plan = createPlan(offers); - assignShipmentToLSP(plan); + plan = createPlan(demandPlan, offers); + demandObject.setSelectedPlan(plan); } - protected abstract Collection recieveOffers(Collection lsps); - protected abstract DemandPlan createPlan(Collection offers); - - private void assignShipmentToLSP(DemandPlan plan) { + protected abstract Collection recieveOffers(Collection lsps); + protected abstract DemandPlan createPlan(DemandPlan demandPlan, Collection offers); + + @Override + public void finishReplanning() { Id id = Id.create(plan.getShipment().getId(), LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); builder.setFromLinkId(demandObject.getFromLinkId()); @@ -49,7 +55,17 @@ private void assignShipmentToLSP(DemandPlan plan) { LSPShipment lspShipment = builder.build(); plan.getLsp().assignShipmentToSolution(lspShipment, plan.getSolutionId()); plan.getShipment().setLSPShipment(lspShipment); - + } + + public void setLSPS(Collection lsps) { + this.lsps = lsps; } + public void setDemandObject (DemandObject demandObject) { + this.demandObject = demandObject; + } + + public DemandObject getDemandObject () { + return demandObject; + } } diff --git a/src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java b/src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java new file mode 100644 index 00000000000..39291971562 --- /dev/null +++ b/src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java @@ -0,0 +1,52 @@ +package demand.mutualReplanning; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.replanning.ReplanningContext; +import org.matsim.core.replanning.modules.GenericPlanStrategyModule; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; +import demand.demandObject.DemandPlanImpl; +import demand.offer.Offer; +import lsp.functions.Info; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class OfferReplanningStrategyModuleImpl extends OfferReplanningStrategyModule{ + + + public OfferReplanningStrategyModuleImpl(DemandObject demandObject) { + super(demandObject); + } + + public OfferReplanningStrategyModuleImpl() { + super(); + } + + @Override + public void handlePlan(DemandPlan demandPlan) { + Collection offers = recieveOffers(lsps); + plan = createPlan(demandPlan, offers); + demandObject.setSelectedPlan(plan); + } + + protected Collection recieveOffers(Collection lsps){ + return demandObject.getOfferRequester().requestOffers(lsps); + } + + protected DemandPlan createPlan(DemandPlan demandPlan, Collection offers) { + return demandObject.getDemandPlanGenerator().createDemandPlan(offers); + } + + @Override + public void prepareReplanning(ReplanningContext replanningContext) { + + } + + +} diff --git a/src/demand/offer/DefaultOfferImpl.java b/src/demand/offer/DefaultOfferImpl.java index 633479e5544..b3acf2745cd 100644 --- a/src/demand/offer/DefaultOfferImpl.java +++ b/src/demand/offer/DefaultOfferImpl.java @@ -1,25 +1,27 @@ package demand.offer; +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; import lsp.LSP; import lsp.LogisticsSolution; public class DefaultOfferImpl implements Offer { - private LSP lsp; - private LogisticsSolution solution; + private LSPDecorator lsp; + private LogisticsSolutionDecorator solution; - public DefaultOfferImpl(LSP lsp, LogisticsSolution logisticsSolution) { + public DefaultOfferImpl(LSPDecorator lsp, LogisticsSolutionDecorator logisticsSolution) { this.lsp = lsp; this.solution = logisticsSolution; } @Override - public LSP getLsp() { + public LSPDecorator getLsp() { return lsp; } @Override - public LogisticsSolution getSolution() { + public LogisticsSolutionDecorator getSolution() { return solution; } @@ -38,12 +40,12 @@ public void accept(OfferVisitor visitor) { } @Override - public void setLSP(LSP lsp) { + public void setLSP(LSPDecorator lsp) { this.lsp = lsp; } @Override - public void setSolution(LogisticsSolution solution) { + public void setSolution(LogisticsSolutionDecorator solution) { this.solution = solution; } diff --git a/src/demand/offer/Offer.java b/src/demand/offer/Offer.java index f1326920eed..dcee02dcd3d 100644 --- a/src/demand/offer/Offer.java +++ b/src/demand/offer/Offer.java @@ -1,15 +1,17 @@ package demand.offer; +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; import lsp.LSP; import lsp.LogisticsSolution; public interface Offer { - public LSP getLsp(); - public LogisticsSolution getSolution(); + public LSPDecorator getLsp(); + public LogisticsSolutionDecorator getSolution(); public String getType(); public void accept(OfferVisitor visitor); public void update(); - public void setLSP (LSP lsp); - public void setSolution(LogisticsSolution solution); + public void setLSP (LSPDecorator lsp); + public void setSolution(LogisticsSolutionDecorator solution); } diff --git a/src/demand/offer/OfferFactory.java b/src/demand/offer/OfferFactory.java index b7d7b4e8523..68738c5cdc2 100644 --- a/src/demand/offer/OfferFactory.java +++ b/src/demand/offer/OfferFactory.java @@ -3,6 +3,7 @@ import java.util.Collection; import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.decoratedLSP.LSPDecorator; import demand.decoratedLSP.LSPWithOffers; import demand.decoratedLSP.LogisticsSolutionDecorator; import demand.demandObject.DemandObject; @@ -13,9 +14,9 @@ public interface OfferFactory { public Offer makeOffer(DemandObject object, String offerType); public Collection getOffers(); - public LSP getLSP(); + public LSPDecorator getLSP(); public LogisticsSolutionDecorator getLogisticsSolution(); public void setLogisticsSolution(LogisticsSolutionDecorator solution); - public void setLSP(LSP lsp); + public void setLSP(LSPDecorator lsp); public void addOffer(Offer offer); } diff --git a/src/demand/offer/OfferFactoryImpl.java b/src/demand/offer/OfferFactoryImpl.java index 9255623be3e..71b9d20bb26 100644 --- a/src/demand/offer/OfferFactoryImpl.java +++ b/src/demand/offer/OfferFactoryImpl.java @@ -19,7 +19,7 @@ public class OfferFactoryImpl implements OfferFactory{ private ArrayList offerList; private LogisticsSolutionDecorator solution; - private LSP lsp; + private LSPDecorator lsp; public OfferFactoryImpl(LogisticsSolutionDecorator solution) { this.solution = solution; @@ -44,7 +44,7 @@ public Collection getOffers() { } @Override - public LSP getLSP() { + public LSPDecorator getLSP() { return lsp; } @@ -59,7 +59,7 @@ public void setLogisticsSolution(LogisticsSolutionDecorator solution) { } @Override - public void setLSP(LSP lsp) { + public void setLSP(LSPDecorator lsp) { this.lsp = lsp; } @@ -69,5 +69,6 @@ public void addOffer(Offer offer) { offer.setSolution(solution); offerList.add(offer); } + } diff --git a/src/demand/offer/RequirementsOfferRequester.java b/src/demand/offer/RequirementsOfferRequester.java index e2f84b74366..30902a80bbf 100644 --- a/src/demand/offer/RequirementsOfferRequester.java +++ b/src/demand/offer/RequirementsOfferRequester.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collection; +import demand.decoratedLSP.LSPDecorator; import demand.decoratedLSP.LSPWithOffers; import demand.demandObject.DemandObject; import demand.demandObject.OfferRequester; @@ -13,9 +14,9 @@ public class RequirementsOfferRequester implements OfferRequester { private DemandObject demandObject; @Override - public Collection requestOffers(Collection lsps) { + public Collection requestOffers(Collection lsps) { ArrayList offerList = new ArrayList(); - for(LSPWithOffers lsp : lsps) { + for(LSPDecorator lsp : lsps) { for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions() ) { offerList.add(lsp.getOffer(demandObject, "linear", solution.getId())); } diff --git a/src/demand/scoring/DemandScorer.java b/src/demand/scoring/DemandScorer.java index 20d1a0d9e99..5ef870fba78 100644 --- a/src/demand/scoring/DemandScorer.java +++ b/src/demand/scoring/DemandScorer.java @@ -6,5 +6,5 @@ public interface DemandScorer extends Scorer{ public double scoreCurrentPlan(DemandObject demandObject); - + public void setDemandObject(DemandObject demandObject); } diff --git a/src/demand/scoring/DemandScoringModuleImpl.java b/src/demand/scoring/DemandScoringModuleImpl.java deleted file mode 100644 index 3a3e638d609..00000000000 --- a/src/demand/scoring/DemandScoringModuleImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package demand.scoring; - -import java.util.Collection; - -import org.matsim.core.controler.events.ScoringEvent; - -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; - - -public class DemandScoringModuleImpl implements DemandScoringModule{ - - private Collection demandObjects; - - public DemandScoringModuleImpl(DemandObjects demandObjects) { - this.demandObjects = demandObjects.getDemandObjects().values(); - } - - @Override - public void notifyScoring(ScoringEvent arg0) { - scoreDemandObjects(); - } - - @Override - public void scoreDemandObjects() { - for(DemandObject demandObject : demandObjects) { - demandObject.scoreSelectedPlan(); - } - } -} diff --git a/src/demand/scoring/DemandScoringModule.java b/src/demand/scoring/MutualScoringModule.java similarity index 56% rename from src/demand/scoring/DemandScoringModule.java rename to src/demand/scoring/MutualScoringModule.java index 90c63159402..a42e4ac3196 100644 --- a/src/demand/scoring/DemandScoringModule.java +++ b/src/demand/scoring/MutualScoringModule.java @@ -2,7 +2,8 @@ import org.matsim.core.controler.listener.ScoringListener; -public interface DemandScoringModule extends ScoringListener{ +public interface MutualScoringModule extends ScoringListener{ public void scoreDemandObjects(); + public void scoreLSPs(); } diff --git a/src/demand/scoring/MutualScoringModuleImpl.java b/src/demand/scoring/MutualScoringModuleImpl.java new file mode 100644 index 00000000000..f12122f10b5 --- /dev/null +++ b/src/demand/scoring/MutualScoringModuleImpl.java @@ -0,0 +1,46 @@ +package demand.scoring; + +import java.util.Collection; + +import org.matsim.core.controler.events.ScoringEvent; + +import demand.decoratedLSP.LSPDecorator; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjects; + + +public class MutualScoringModuleImpl implements MutualScoringModule{ + + private Collection demandObjects; + private Collection lsps; + + public MutualScoringModuleImpl(Collection demandObjects, Collection lsps) { + this.demandObjects = demandObjects; + this.lsps = lsps; + } + + @Override + public void notifyScoring(ScoringEvent arg0) { + scoreDemandObjects(); + scoreLSPs(); + } + + @Override + public void scoreDemandObjects() { + for(DemandObject demandObject : demandObjects) { + if(demandObject.getScorer() != null) { + demandObject.scoreSelectedPlan(); + } + } + } + + @Override + public void scoreLSPs() { + for(LSPDecorator lsp : lsps) { + if(lsp.getScorer() != null) { + lsp.scoreSelectedPlan(); + } + } + + } +} diff --git a/test/demandObjectTests/AllOffersRequester.java b/test/demandObjectTests/AllOffersRequester.java new file mode 100644 index 00000000000..290217dd392 --- /dev/null +++ b/test/demandObjectTests/AllOffersRequester.java @@ -0,0 +1,37 @@ +package demandObjectTests; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.demandObject.DemandObject; +import demand.demandObject.OfferRequester; +import demand.offer.Offer; + +public class AllOffersRequester implements OfferRequester{ + + private DemandObject demandObject; + + public AllOffersRequester() { + + } + + @Override + public Collection requestOffers(Collection lsps) { + ArrayList offers = new ArrayList(); + for(LSPDecorator lsp : lsps) { + for(LogisticsSolutionDecorator solution : lsp.getSelectedPlan().getSolutionDecorators()) { + offers.add(lsp.getOffer(demandObject, "linear", solution.getId())); + } + } + return offers; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/test/demandObjectTests/DemandObjectBuilderTest.java b/test/demandObjectTests/DemandObjectBuilderTest.java new file mode 100644 index 00000000000..7ade5976153 --- /dev/null +++ b/test/demandObjectTests/DemandObjectBuilderTest.java @@ -0,0 +1,140 @@ +package demandObjectTests; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.replanning.modules.GenericPlanStrategyModule; +import org.matsim.core.replanning.selectors.BestPlanSelector; +import org.matsim.core.scenario.ScenarioUtils; + +import demand.decoratedLSP.LSPDecorator; +import demand.demandAgent.DemandAgent; +import demand.demandAgent.DemandAgentImpl; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjectImpl; +import demand.demandObject.DemandPlan; +import demand.demandObject.DemandPlanImpl; +import demand.demandObject.OfferRequester; +import demand.demandObject.ShipperShipment; +import demand.demandObject.ShipperShipmentImpl; +import demand.mutualReplanning.DemandPlanStrategyImpl; +import demand.mutualReplanning.DemandReplannerImpl; +import demand.mutualReplanning.OfferReplanningStrategyModule; +import demand.mutualReplanning.OfferReplanningStrategyModuleImpl; +import demand.offer.Offer; + +public class DemandObjectBuilderTest { + + private Network network; + private ArrayList demandObjects; + private OfferRequester offerRequester; + private LSPDecorator lsp; + private DemandReplannerImpl replanner; + private DemandPlanStrategyImpl planStrategy; + private OfferReplanningStrategyModule offerModule ; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + this.demandObjects = new ArrayList(); + Random random = new Random(1); + lsp = new InitialLSPGenerator().createInitialLSP(); + + + for(int i = 1; i < 11 ; i++) { + DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); + builder.setId(Id.create("DemandObject_" + i, DemandObject.class)); + DemandAgentImpl.Builder shipperBuilder = DemandAgentImpl.Builder.newInstance(); + shipperBuilder.setId(Id.create("DemandObject_" + i+ "_Shipper", DemandAgent.class)); + builder.setShipper(shipperBuilder.build()); + DemandAgentImpl.Builder recipientBuilder = DemandAgentImpl.Builder.newInstance(); + recipientBuilder.setId(Id.create("DemandObject_" + i+ "_Recipient", DemandAgent.class)); + builder.setRecipient(recipientBuilder.build()); + double shipmentSize= 5 + random.nextDouble()*5; + builder.setStrengthOfFlow(shipmentSize); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + } + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); + ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); + shipmentBuilder.setId(Id.create("DemandObject_" + i+ "_Shipment", ShipperShipment.class)); + shipmentBuilder.setShipmentSize(shipmentSize); + shipmentBuilder.setServiceTime(shipmentSize * 60); + planBuilder.setShipperShipment(shipmentBuilder.build()); + planBuilder.setLsp(lsp); + planBuilder.setLogisticsSolutionId(lsp.getSelectedPlan().getSolutions().iterator().next().getId()); + builder.setInitialPlan(planBuilder.build()); + builder.setScorer(new FortyTwoDemandScorer()); + replanner = new DemandReplannerImpl(); + planStrategy = new DemandPlanStrategyImpl(new BestPlanSelector()); + offerModule = new OfferReplanningStrategyModuleImpl(); + planStrategy.addStrategyModule(offerModule); + replanner.addStrategy(planStrategy); + builder.setReplanner(replanner); + builder.setOfferRequester(new AllOffersRequester()); + builder.setDemandPlanGenerator(new HalfLotSizeDemandPlanGenerator()); + demandObjects.add(builder.build()); + } + + } + + @Test + public void testDemandObjectBuilding() { + for(DemandObject demandObject : demandObjects) { + Offer offer = lsp.getOffer(demandObject, "linear", lsp.getSelectedPlan().getSolutions().iterator().next().getId()); + CollectionofferList= new ArrayList<>(); + offerList.add(offer); + DemandPlan newPlan = demandObject.getDemandPlanGenerator().createDemandPlan(offerList); + DemandPlan oldPlan = demandObject.getSelectedPlan(); + assertTrue(newPlan.getLsp() == oldPlan.getLsp()); + assertTrue(newPlan.getSolutionId() == oldPlan.getSolutionId()); + assertTrue(newPlan.getShipment().getShipmentSize() == oldPlan.getShipment().getShipmentSize()/2); + assertNotNull(demandObject.getOfferRequester()); + assertNotNull(demandObject.getReplanner()); + + } + } + +} diff --git a/test/demandObjectTests/FortyTwoDemandScorer.java b/test/demandObjectTests/FortyTwoDemandScorer.java new file mode 100644 index 00000000000..9a18c6c432c --- /dev/null +++ b/test/demandObjectTests/FortyTwoDemandScorer.java @@ -0,0 +1,19 @@ +package demandObjectTests; + +import demand.demandObject.DemandObject; +import demand.scoring.DemandScorer; + +public class FortyTwoDemandScorer implements DemandScorer { + + @Override + public double scoreCurrentPlan(DemandObject demandObject) { + return 42; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + // TODO Auto-generated method stub + + } + +} diff --git a/test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java b/test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java new file mode 100644 index 00000000000..bd4fd139232 --- /dev/null +++ b/test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java @@ -0,0 +1,40 @@ +package demandObjectTests; + +import java.util.Collection; + +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; +import demand.demandObject.DemandPlanGenerator; +import demand.demandObject.DemandPlanImpl; +import demand.demandObject.ShipperShipmentImpl; +import demand.offer.Offer; + +public class HalfLotSizeDemandPlanGenerator implements DemandPlanGenerator{ + + private DemandObject demandObject; + + @Override + public DemandPlan createDemandPlan(Collection offers) { + Offer singleOffer = offers.iterator().next(); + DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); + planBuilder.setLsp(singleOffer.getLsp()); + planBuilder.setLogisticsSolutionId(singleOffer.getSolution().getId()); + planBuilder.setDemandObject(demandObject); + + ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); + shipmentBuilder.setDemandObject(demandObject); + shipmentBuilder.setId(demandObject.getSelectedPlan().getShipment().getId()); + shipmentBuilder.setEndTimeWindow(demandObject.getSelectedPlan().getShipment().getEndTimeWindow()); + shipmentBuilder.setStartTimeWindow(demandObject.getSelectedPlan().getShipment().getStartTimeWindow()); + shipmentBuilder.setServiceTime(demandObject.getSelectedPlan().getShipment().getServiceTime()); + shipmentBuilder.setShipmentSize(demandObject.getSelectedPlan().getShipment().getShipmentSize()/2); + planBuilder.setShipperShipment(shipmentBuilder.build()); + return planBuilder.build(); + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/test/demandObjectTests/InitialLSPGenerator.java b/test/demandObjectTests/InitialLSPGenerator.java new file mode 100644 index 00000000000..ba525e74a58 --- /dev/null +++ b/test/demandObjectTests/InitialLSPGenerator.java @@ -0,0 +1,252 @@ +package demandObjectTests; + +import java.util.ArrayList; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPPlanDecorator; +import demand.decoratedLSP.LSPPlanWithOfferTransferrer; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.offer.OfferFactoryImpl; +import demand.offer.OfferTransferrer; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import requirementsCheckerTests.BlueInfo; +import requirementsCheckerTests.NonsenseOffer; +import requirementsCheckerTests.RedInfo; +import requirementsCheckerTests.RequirementsTransferrer; + +public class InitialLSPGenerator { + + + public LSPDecorator createInitialLSP() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(20); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(collectionCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("Solution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); + solutionBuilder.addSolutionElement(collectionElement); + solutionBuilder.addSolutionElement(firstReloadElement); + solutionBuilder.addSolutionElement(mainRunElement); + solutionBuilder.addSolutionElement(secondReloadElement); + solutionBuilder.addSolutionElement(distributionElement); + LogisticsSolutionDecorator solution = solutionBuilder.build(); + + OfferFactoryImpl offerFactory = new OfferFactoryImpl(solution); + offerFactory.addOffer(new LinearOffer(solution)); + solution.setOfferFactory(offerFactory); + + LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); + plan.addSolution(solution); + + OfferTransferrer transferrer = new SimpleOfferTransferrer(); + plan.setOfferTransferrer(transferrer); + + LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); + offerLSPBuilder.setInitialPlan(plan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + offerLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + offerLSPBuilder.setSolutionScheduler(simpleScheduler); + return offerLSPBuilder.build(); + } + +} diff --git a/test/demandObjectTests/LinearOffer.java b/test/demandObjectTests/LinearOffer.java new file mode 100644 index 00000000000..248f1f78576 --- /dev/null +++ b/test/demandObjectTests/LinearOffer.java @@ -0,0 +1,85 @@ +package demandObjectTests; + +import java.util.Random; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import example.simulationTrackers.CostInfo; +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.LSP; +import lsp.LogisticsSolution; + + +public class LinearOffer implements Offer{ + + private LSPDecorator lsp; + private LogisticsSolutionDecorator solution; + private String type; + private double fix; + private double linear; + + public LinearOffer(LogisticsSolutionDecorator solution) { + this.lsp = solution.getLSP(); + this.solution = solution; + this.type = "linear"; + Random random = new Random(1); + fix = random.nextDouble() * 10; + linear = random.nextDouble() * 10; + } + + @Override + public LSPDecorator getLsp() { + return lsp; + } + + @Override + public LogisticsSolutionDecorator getSolution() { + return solution; + } + + @Override + public String getType() { + return type; + } + + public double getFix() { + return fix; + } + + public void setFix(double fix) { + this.fix = fix; + } + + public double getLinear() { + return linear; + } + + public void setLinear(double linear) { + this.linear = linear; + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void update() { + + + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public void setSolution(LogisticsSolutionDecorator solution) { + this.solution = solution; + } + +} diff --git a/test/demandObjectTests/SimpleOfferTransferrer.java b/test/demandObjectTests/SimpleOfferTransferrer.java new file mode 100644 index 00000000000..4efbfd7bdae --- /dev/null +++ b/test/demandObjectTests/SimpleOfferTransferrer.java @@ -0,0 +1,30 @@ +package demandObjectTests; + +import org.matsim.api.core.v01.Id; + +import demand.decoratedLSP.LSPDecorator; +import demand.demandObject.DemandObject; +import demand.offer.Offer; +import demand.offer.OfferTransferrer; +import lsp.LogisticsSolution; + +public class SimpleOfferTransferrer implements OfferTransferrer{ + + private LSPDecorator lsp; + + @Override + public Offer transferOffer(DemandObject object, String type, Id solutionId) { + return lsp.getSelectedPlan().getSolutionDecorators().iterator().next().getOffer(object, type); + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public LSPDecorator getLSP() { + return lsp; + } + +} diff --git a/test/lspScoringTests/TrinkgeldScorer.java b/test/lspScoringTests/TrinkgeldScorer.java index a5841a1f92b..75c569d1b0f 100644 --- a/test/lspScoringTests/TrinkgeldScorer.java +++ b/test/lspScoringTests/TrinkgeldScorer.java @@ -35,5 +35,11 @@ public double scoreCurrentPlan(LSP lsp) { return score; } + @Override + public void setLSP(LSP lsp) { + // TODO Auto-generated method stub + + } + } diff --git a/test/lspShipmentTest/collectionShipmentBuilderTest.java b/test/lspShipmentTest/collectionShipmentBuilderTest.java index d6108428897..3ae181f7c88 100644 --- a/test/lspShipmentTest/collectionShipmentBuilderTest.java +++ b/test/lspShipmentTest/collectionShipmentBuilderTest.java @@ -91,8 +91,8 @@ public void testShipments() { assertTrue(shipment.getSchedule().getPlanElements().isEmpty()); Link link = network.getLinks().get(shipment.getFromLinkId()); - assertTrue(link.getFromNode().getCoord().getX() <= 4); - assertTrue(link.getFromNode().getCoord().getY() <= 4); + assertTrue(link.getFromNode().getCoord().getX() <= 4000); + assertTrue(link.getFromNode().getCoord().getY() <= 4000); } } diff --git a/test/lspShipmentTest/completeShipmentBuilderTest.java b/test/lspShipmentTest/completeShipmentBuilderTest.java index 139550eb08f..f1d771e61db 100644 --- a/test/lspShipmentTest/completeShipmentBuilderTest.java +++ b/test/lspShipmentTest/completeShipmentBuilderTest.java @@ -19,6 +19,7 @@ import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; +import demand.demandAgent.DemandAgent; import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; @@ -80,6 +81,7 @@ public void initialize(){ } } + @Test public void testShipments() { assertTrue(shipments.size() == 10); @@ -102,14 +104,14 @@ public void testShipments() { assertEquals(shipment.getSchedule().getShipment(), shipment); assertTrue(shipment.getSchedule().getPlanElements().isEmpty()); Link link = network.getLinks().get(shipment.getToLinkId()); - assertTrue(link.getFromNode().getCoord().getX() <= 18); - assertTrue(link.getFromNode().getCoord().getX() >= 14); - assertTrue(link.getToNode().getCoord().getX() <= 18); - assertTrue(link.getToNode().getCoord().getX() >= 14); + assertTrue(link.getFromNode().getCoord().getX() <= 18000); + assertTrue(link.getFromNode().getCoord().getX() >= 14000); + assertTrue(link.getToNode().getCoord().getX() <= 18000); + assertTrue(link.getToNode().getCoord().getX() >= 14000); link = network.getLinks().get(shipment.getFromLinkId()); - assertTrue(link.getFromNode().getCoord().getX() <= 4); - assertTrue(link.getFromNode().getCoord().getY() <= 4); + assertTrue(link.getFromNode().getCoord().getX() <= 4000); + assertTrue(link.getFromNode().getCoord().getY() <= 4000); } } } diff --git a/test/lspShipmentTest/distributionShipmentBuilderTest.java b/test/lspShipmentTest/distributionShipmentBuilderTest.java index f52e19fbadf..b2959ac3c71 100644 --- a/test/lspShipmentTest/distributionShipmentBuilderTest.java +++ b/test/lspShipmentTest/distributionShipmentBuilderTest.java @@ -94,10 +94,10 @@ public void testShipments() { assertEquals(shipment.getSchedule().getShipment(), shipment); assertTrue(shipment.getSchedule().getPlanElements().isEmpty()); Link link = network.getLinks().get(shipment.getToLinkId()); - assertTrue(link.getFromNode().getCoord().getX() <= 18); - assertTrue(link.getFromNode().getCoord().getX() >= 14); - assertTrue(link.getToNode().getCoord().getX() <= 18); - assertTrue(link.getToNode().getCoord().getX() >= 14); + assertTrue(link.getFromNode().getCoord().getX() <= 18000); + assertTrue(link.getFromNode().getCoord().getX() >= 14000); + assertTrue(link.getToNode().getCoord().getX() <= 18000); + assertTrue(link.getToNode().getCoord().getX() >= 14000); } } } diff --git a/test/requirementsCheckerTests/NonsenseOffer.java b/test/requirementsCheckerTests/NonsenseOffer.java index 87379a9e098..3836f65b71f 100644 --- a/test/requirementsCheckerTests/NonsenseOffer.java +++ b/test/requirementsCheckerTests/NonsenseOffer.java @@ -1,5 +1,7 @@ package requirementsCheckerTests; +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; import demand.offer.Offer; import demand.offer.OfferVisitor; import lsp.LSP; @@ -7,17 +9,17 @@ public class NonsenseOffer implements Offer{ - private LSP lsp; - private LogisticsSolution solution; + private LSPDecorator lsp; + private LogisticsSolutionDecorator solution; @Override - public LSP getLsp() { + public LSPDecorator getLsp() { return lsp; } @Override - public LogisticsSolution getSolution() { + public LogisticsSolutionDecorator getSolution() { return solution; } @@ -38,13 +40,13 @@ public void update() { } @Override - public void setLSP(LSP lsp) { + public void setLSP(LSPDecorator lsp) { this.lsp = lsp; } @Override - public void setSolution(LogisticsSolution solution) { + public void setSolution(LogisticsSolutionDecorator solution) { this.solution = solution; } diff --git a/test/testMutualReplanning/AllOffersRequester.java b/test/testMutualReplanning/AllOffersRequester.java new file mode 100644 index 00000000000..d1cc91c5b96 --- /dev/null +++ b/test/testMutualReplanning/AllOffersRequester.java @@ -0,0 +1,37 @@ +package testMutualReplanning; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.demandObject.DemandObject; +import demand.demandObject.OfferRequester; +import demand.offer.Offer; + +public class AllOffersRequester implements OfferRequester{ + + private DemandObject demandObject; + + public AllOffersRequester() { + + } + + @Override + public Collection requestOffers(Collection lsps) { + ArrayList offers = new ArrayList(); + for(LSPDecorator lsp : lsps) { + for(LogisticsSolutionDecorator solution : lsp.getSelectedPlan().getSolutionDecorators()) { + offers.add(lsp.getOffer(demandObject, "linear", solution.getId())); + } + } + return offers; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/test/testMutualReplanning/FortyTwoDemandScorer.java b/test/testMutualReplanning/FortyTwoDemandScorer.java new file mode 100644 index 00000000000..c4dcd847d54 --- /dev/null +++ b/test/testMutualReplanning/FortyTwoDemandScorer.java @@ -0,0 +1,19 @@ +package testMutualReplanning; + +import demand.demandObject.DemandObject; +import demand.scoring.DemandScorer; + +public class FortyTwoDemandScorer implements DemandScorer { + + @Override + public double scoreCurrentPlan(DemandObject demandObject) { + return 42; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + // TODO Auto-generated method stub + + } + +} diff --git a/test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java b/test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java new file mode 100644 index 00000000000..036702b453f --- /dev/null +++ b/test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java @@ -0,0 +1,40 @@ +package testMutualReplanning; + +import java.util.Collection; + +import demand.demandObject.DemandObject; +import demand.demandObject.DemandPlan; +import demand.demandObject.DemandPlanGenerator; +import demand.demandObject.DemandPlanImpl; +import demand.demandObject.ShipperShipmentImpl; +import demand.offer.Offer; + +public class HalfLotSizeDemandPlanGenerator implements DemandPlanGenerator{ + + private DemandObject demandObject; + + @Override + public DemandPlan createDemandPlan(Collection offers) { + Offer singleOffer = offers.iterator().next(); + DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); + planBuilder.setLsp(singleOffer.getLsp()); + planBuilder.setLogisticsSolutionId(singleOffer.getSolution().getId()); + planBuilder.setDemandObject(demandObject); + + ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); + shipmentBuilder.setDemandObject(demandObject); + shipmentBuilder.setId(demandObject.getSelectedPlan().getShipment().getId()); + shipmentBuilder.setEndTimeWindow(demandObject.getSelectedPlan().getShipment().getEndTimeWindow()); + shipmentBuilder.setStartTimeWindow(demandObject.getSelectedPlan().getShipment().getStartTimeWindow()); + shipmentBuilder.setServiceTime(demandObject.getSelectedPlan().getShipment().getServiceTime()); + shipmentBuilder.setShipmentSize(demandObject.getSelectedPlan().getShipment().getShipmentSize()/2); + planBuilder.setShipperShipment(shipmentBuilder.build()); + return planBuilder.build(); + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/test/testMutualReplanning/InitialLSPGenerator.java b/test/testMutualReplanning/InitialLSPGenerator.java new file mode 100644 index 00000000000..dfa8285099a --- /dev/null +++ b/test/testMutualReplanning/InitialLSPGenerator.java @@ -0,0 +1,252 @@ +package testMutualReplanning; + +import java.util.ArrayList; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPPlanDecorator; +import demand.decoratedLSP.LSPPlanWithOfferTransferrer; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.offer.OfferFactoryImpl; +import demand.offer.OfferTransferrer; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import requirementsCheckerTests.BlueInfo; +import requirementsCheckerTests.NonsenseOffer; +import requirementsCheckerTests.RedInfo; +import requirementsCheckerTests.RequirementsTransferrer; + +public class InitialLSPGenerator { + + + public LSPDecorator createInitialLSP() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(20); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(collectionCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("Solution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); + solutionBuilder.addSolutionElement(collectionElement); + solutionBuilder.addSolutionElement(firstReloadElement); + solutionBuilder.addSolutionElement(mainRunElement); + solutionBuilder.addSolutionElement(secondReloadElement); + solutionBuilder.addSolutionElement(distributionElement); + LogisticsSolutionDecorator solution = solutionBuilder.build(); + + OfferFactoryImpl offerFactory = new OfferFactoryImpl(solution); + offerFactory.addOffer(new LinearOffer(solution)); + solution.setOfferFactory(offerFactory); + + LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); + plan.addSolution(solution); + + OfferTransferrer transferrer = new SimpleOfferTransferrer(); + plan.setOfferTransferrer(transferrer); + + LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); + offerLSPBuilder.setInitialPlan(plan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + offerLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + offerLSPBuilder.setSolutionScheduler(simpleScheduler); + return offerLSPBuilder.build(); + } + +} diff --git a/test/testMutualReplanning/LinearOffer.java b/test/testMutualReplanning/LinearOffer.java new file mode 100644 index 00000000000..ed53d10a50e --- /dev/null +++ b/test/testMutualReplanning/LinearOffer.java @@ -0,0 +1,85 @@ +package testMutualReplanning; + +import java.util.Random; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import example.simulationTrackers.CostInfo; +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.LSP; +import lsp.LogisticsSolution; + + +public class LinearOffer implements Offer{ + + private LSPDecorator lsp; + private LogisticsSolutionDecorator solution; + private String type; + private double fix; + private double linear; + + public LinearOffer(LogisticsSolutionDecorator solution) { + this.lsp = solution.getLSP(); + this.solution = solution; + this.type = "linear"; + Random random = new Random(1); + fix = random.nextDouble() * 10; + linear = random.nextDouble() * 10; + } + + @Override + public LSPDecorator getLsp() { + return lsp; + } + + @Override + public LogisticsSolutionDecorator getSolution() { + return solution; + } + + @Override + public String getType() { + return type; + } + + public double getFix() { + return fix; + } + + public void setFix(double fix) { + this.fix = fix; + } + + public double getLinear() { + return linear; + } + + public void setLinear(double linear) { + this.linear = linear; + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void update() { + + + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public void setSolution(LogisticsSolutionDecorator solution) { + this.solution = solution; + } + +} diff --git a/test/testMutualReplanning/LotSizeScorer.java b/test/testMutualReplanning/LotSizeScorer.java deleted file mode 100644 index 777f6ae9e8d..00000000000 --- a/test/testMutualReplanning/LotSizeScorer.java +++ /dev/null @@ -1,21 +0,0 @@ -package testMutualReplanning; - -import demand.demandObject.DemandObject; -import demand.scoring.DemandScorer; -import testDemandObjectsWithLotsizes.LotSizeShipment; - -public class LotSizeScorer implements DemandScorer{ - - - - - - @Override - public double scoreCurrentPlan(DemandObject demandObject) { - if(demandObject.getSelectedPlan().getShipment() instanceof LotSizeShipment) { - - } - return 0; - } - -} diff --git a/test/testMutualReplanning/MutualReplanningTest.java b/test/testMutualReplanning/MutualReplanningTest.java new file mode 100644 index 00000000000..67221556f01 --- /dev/null +++ b/test/testMutualReplanning/MutualReplanningTest.java @@ -0,0 +1,237 @@ +package testMutualReplanning; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.replanning.selectors.BestPlanSelector; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPPlanDecorator; +import demand.decoratedLSP.LSPPlanWithOfferTransferrer; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LSPDecorators; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandAgent.DemandAgent; +import demand.demandAgent.DemandAgentImpl; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjectImpl; +import demand.demandObject.DemandObjects; +import demand.demandObject.DemandPlanImpl; +import demand.demandObject.ShipperShipment; +import demand.demandObject.ShipperShipmentImpl; +import demand.mobsim.MutualModule; +import demand.mutualReplanning.DemandPlanStrategyImpl; +import demand.mutualReplanning.DemandReplannerImpl; +import demand.mutualReplanning.MutualReplanningModule; +import demand.mutualReplanning.MutualReplanningModuleImpl; +import demand.mutualReplanning.OfferReplanningStrategyModuleImpl; +import demand.offer.OfferFactoryImpl; +import demand.offer.OfferTransferrer; +import demand.scoring.MutualScoringModule; +import demand.scoring.MutualScoringModuleImpl; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import testLSPWithCostTracker.CollectionServiceHandler; +import testLSPWithCostTracker.DistanceAndTimeHandler; +import testLSPWithCostTracker.LinearCostTracker; +import testLSPWithCostTracker.TourStartHandler; + +public class MutualReplanningTest { + + private LSPDecorator lsp; + private Collection demandObjects; + + + @Before + public void initialize(){ + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Random random = new Random(1); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(20); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + Id solutionId = Id.create("Solution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); + solutionBuilder.addSolutionElement(collectionElement); + LogisticsSolutionDecorator solution = solutionBuilder.build(); + + LinearCostTracker tracker = new LinearCostTracker(0.2); + tracker.getEventHandlers().add(new TourStartHandler()); + tracker.getEventHandlers().add(new CollectionServiceHandler()); + tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); + solution.addSimulationTracker(tracker); + + + OfferFactoryImpl offerFactory = new OfferFactoryImpl(solution); + offerFactory.addOffer(new LinearOffer(solution)); + solution.setOfferFactory(offerFactory); + + LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); + plan.addSolution(solution); + + OfferTransferrer transferrer = new SimpleOfferTransferrer(); + plan.setOfferTransferrer(transferrer); + + LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); + offerLSPBuilder.setInitialPlan(plan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + offerLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + offerLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = offerLSPBuilder.build(); + + demandObjects = new ArrayList<>(); + for(int i = 1; i < 11 ; i++) { + DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); + builder.setId(Id.create("DemandObject_" + i, DemandObject.class)); + DemandAgentImpl.Builder shipperBuilder = DemandAgentImpl.Builder.newInstance(); + shipperBuilder.setId(Id.create("DemandObject_" + i+ "_Shipper", DemandAgent.class)); + builder.setShipper(shipperBuilder.build()); + DemandAgentImpl.Builder recipientBuilder = DemandAgentImpl.Builder.newInstance(); + recipientBuilder.setId(Id.create("DemandObject_" + i+ "_Recipient", DemandAgent.class)); + builder.setRecipient(recipientBuilder.build()); + double shipmentSize= 5 + random.nextDouble()*5; + builder.setStrengthOfFlow(shipmentSize); + builder.setToLinkId(collectionLinkId); + + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); + ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); + shipmentBuilder.setId(Id.create("DemandObject_" + i+ "_Shipment", ShipperShipment.class)); + shipmentBuilder.setShipmentSize(shipmentSize); + shipmentBuilder.setServiceTime(shipmentSize * 60); + planBuilder.setShipperShipment(shipmentBuilder.build()); + planBuilder.setLsp(lsp); + planBuilder.setLogisticsSolutionId(lsp.getSelectedPlan().getSolutions().iterator().next().getId()); + builder.setInitialPlan(planBuilder.build()); + builder.setScorer(new FortyTwoDemandScorer()); + DemandReplannerImpl replanner = new DemandReplannerImpl(); + DemandPlanStrategyImpl planStrategy = new DemandPlanStrategyImpl(new BestPlanSelector()); + planStrategy.addStrategyModule(new OfferReplanningStrategyModuleImpl()); + replanner.addStrategy(planStrategy); + builder.setReplanner(replanner); + builder.setOfferRequester(new AllOffersRequester()); + builder.setDemandPlanGenerator(new HalfLotSizeDemandPlanGenerator()); + DemandObject demandObject = builder.build(); + demandObjects.add(demandObject); + + } + + + Collectionlsps = new ArrayList<>(); + lsps.add(lsp); + MutualScoringModule mutScoreModule = new MutualScoringModuleImpl(demandObjects, lsps); + + MutualReplanningModule mutReplanModule = new MutualReplanningModuleImpl( lsps, demandObjects); + + MutualModule.Builder moduleBuilder = MutualModule.Builder.newInstance(); + moduleBuilder.setDemandObjects(new DemandObjects(demandObjects)); + moduleBuilder.setLsps(new LSPDecorators(lsps)); + moduleBuilder.setMutualReplanningModule(mutReplanModule); + moduleBuilder.setMutualScoringModule(mutScoreModule); + MutualModule mutualModule = moduleBuilder.build(); + + Controler controler = new Controler(config); + controler.addOverridingModule(mutualModule); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testReplanning() { + for(DemandObject demandObject : demandObjects) { + assertEquals((demandObject.getStrengthOfFlow()/2), demandObject.getSelectedPlan().getShipment().getShipmentSize(), 0.1); + } + + } + +} diff --git a/test/testMutualReplanning/NonsenseOffer.java b/test/testMutualReplanning/NonsenseOffer.java deleted file mode 100644 index 7e3f9664f67..00000000000 --- a/test/testMutualReplanning/NonsenseOffer.java +++ /dev/null @@ -1,52 +0,0 @@ -package testMutualReplanning; - -import demand.offer.Offer; -import demand.offer.OfferVisitor; -import lsp.LSP; -import lsp.LogisticsSolution; - -public class NonsenseOffer implements Offer{ - - private LSP lsp; - private LogisticsSolution solution; - - - @Override - public LSP getLsp() { - return lsp; - } - - @Override - public LogisticsSolution getSolution() { - return solution; - } - - @Override - public String getType() { - return "nonsense"; - } - - @Override - public void accept(OfferVisitor visitor) { - visitor.visit(this); - } - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - @Override - public void setLSP(LSP lsp) { - this.lsp = lsp; - - } - - @Override - public void setSolution(LogisticsSolution solution) { - this.solution = solution; - - } - -} diff --git a/test/testMutualReplanning/SimpleOfferRequester.java b/test/testMutualReplanning/SimpleOfferRequester.java deleted file mode 100644 index 777cb0ed224..00000000000 --- a/test/testMutualReplanning/SimpleOfferRequester.java +++ /dev/null @@ -1,35 +0,0 @@ -package testMutualReplanning; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPWithOffers; -import demand.demandObject.DemandObject; -import demand.demandObject.OfferRequester; -import demand.offer.Offer; -import lsp.LogisticsSolution; - -public class SimpleOfferRequester implements OfferRequester{ - - private DemandObject demandObject; - - - @Override - public Collection requestOffers(Collection lsps) { - ArrayList offerList = new ArrayList(); - for(LSPWithOffers lsp : lsps) { - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - Offer offer = lsp.getOffer(demandObject, "nonsense", solution.getId()); - offerList.add(offer); - } - } - return offerList; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - - } - -} diff --git a/test/testMutualReplanning/SimpleOfferTransferrer.java b/test/testMutualReplanning/SimpleOfferTransferrer.java new file mode 100644 index 00000000000..808a6c85dea --- /dev/null +++ b/test/testMutualReplanning/SimpleOfferTransferrer.java @@ -0,0 +1,30 @@ +package testMutualReplanning; + +import org.matsim.api.core.v01.Id; + +import demand.decoratedLSP.LSPDecorator; +import demand.demandObject.DemandObject; +import demand.offer.Offer; +import demand.offer.OfferTransferrer; +import lsp.LogisticsSolution; + +public class SimpleOfferTransferrer implements OfferTransferrer{ + + private LSPDecorator lsp; + + @Override + public Offer transferOffer(DemandObject object, String type, Id solutionId) { + return lsp.getSelectedPlan().getSolutionDecorators().iterator().next().getOffer(object, type); + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public LSPDecorator getLSP() { + return lsp; + } + +} From 64534e1f52d5683fcf1c5969f66b5fe9a92d42b4 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 6 Mar 2018 18:27:18 +0100 Subject: [PATCH 0026/1340] OfferUpdater test added --- .../LSPWithOffersReplanner.java | 6 + src/demand/offer/OfferUpdaterImpl.java | 5 +- .../offer/RequirementsOfferRequester.java | 31 -- .../transferrerRequirementsTest.java | 8 - .../AllOffersRequester.java | 37 +++ .../CollectionServiceHandler.java | 87 ++++++ .../CostInfo.java | 42 +++ .../CostInfoFunction.java | 29 ++ .../DistanceAndTimeHandler.java | 82 +++++ .../FixedCostFunctionValue.java | 29 ++ .../LinearCostFunctionValue.java | 29 ++ .../LinearCostTracker.java | 104 +++++++ .../LinearOffer.java | 98 ++++++ .../LinearOfferFactoryImpl.java | 74 +++++ .../LinearOfferVisitor.java | 35 +++ .../MutualReplanningAndOfferUpdateTest.java | 291 ++++++++++++++++++ .../TourStartHandler.java | 24 ++ 17 files changed, 970 insertions(+), 41 deletions(-) delete mode 100644 src/demand/offer/RequirementsOfferRequester.java create mode 100644 test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java create mode 100644 test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java create mode 100644 test/testMutualreplanningWithOfferUpdate/CostInfo.java create mode 100644 test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java create mode 100644 test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java create mode 100644 test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java create mode 100644 test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java create mode 100644 test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java create mode 100644 test/testMutualreplanningWithOfferUpdate/LinearOffer.java create mode 100644 test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java create mode 100644 test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java create mode 100644 test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java create mode 100644 test/testMutualreplanningWithOfferUpdate/TourStartHandler.java diff --git a/src/demand/mutualReplanning/LSPWithOffersReplanner.java b/src/demand/mutualReplanning/LSPWithOffersReplanner.java index 6f4f2ac160b..e96f32c14d9 100644 --- a/src/demand/mutualReplanning/LSPWithOffersReplanner.java +++ b/src/demand/mutualReplanning/LSPWithOffersReplanner.java @@ -61,6 +61,9 @@ public OfferUpdater getOfferUpdater() { public void setLSP(LSP lsp) { try { this.lsp = (LSPWithOffers) lsp; + if(this.lsp.getOfferUpdater() != null) { + this.offerUpdater = this.lsp.getOfferUpdater(); + } } catch(ClassCastException e) { System.out.println("The class " + this.toString() + " expects an LSPWithOffers and not any other implementation of LSP"); @@ -70,5 +73,8 @@ public void setLSP(LSP lsp) { public void setLSP(LSPDecorator lsp) { this.lsp = lsp; + if(this.lsp.getOfferUpdater() != null) { + this.offerUpdater = this.lsp.getOfferUpdater(); + } } } diff --git a/src/demand/offer/OfferUpdaterImpl.java b/src/demand/offer/OfferUpdaterImpl.java index 554b2d27d82..d57c88f47c9 100644 --- a/src/demand/offer/OfferUpdaterImpl.java +++ b/src/demand/offer/OfferUpdaterImpl.java @@ -4,6 +4,7 @@ import java.util.Collection; import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; import demand.decoratedLSP.LogisticsSolutionWithOffers; import lsp.LogisticsSolution; @@ -20,8 +21,8 @@ public OfferUpdaterImpl() { @Override public void updateOffers() { for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - if(solution instanceof LogisticsSolutionWithOffers) { - LogisticsSolutionWithOffers offerSolution = (LogisticsSolutionWithOffers) solution; + if(solution instanceof LogisticsSolutionDecorator) { + LogisticsSolutionDecorator offerSolution = (LogisticsSolutionDecorator) solution; for(OfferVisitor visitor : visitors) { if(visitor.getLogisticsSolution() == solution) { for(Offer offer : offerSolution.getOfferFactory().getOffers()) { diff --git a/src/demand/offer/RequirementsOfferRequester.java b/src/demand/offer/RequirementsOfferRequester.java deleted file mode 100644 index 30902a80bbf..00000000000 --- a/src/demand/offer/RequirementsOfferRequester.java +++ /dev/null @@ -1,31 +0,0 @@ -package demand.offer; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.demandObject.DemandObject; -import demand.demandObject.OfferRequester; -import lsp.LogisticsSolution; - -public class RequirementsOfferRequester implements OfferRequester { - - private DemandObject demandObject; - - @Override - public Collection requestOffers(Collection lsps) { - ArrayList offerList = new ArrayList(); - for(LSPDecorator lsp : lsps) { - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions() ) { - offerList.add(lsp.getOffer(demandObject, "linear", solution.getId())); - } - } - return offerList; - } - - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/test/requirementsCheckerTests/transferrerRequirementsTest.java b/test/requirementsCheckerTests/transferrerRequirementsTest.java index 140ba049e77..9bf6c2eb76a 100644 --- a/test/requirementsCheckerTests/transferrerRequirementsTest.java +++ b/test/requirementsCheckerTests/transferrerRequirementsTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; -import java.util.Collections; import java.util.Random; import org.junit.Before; @@ -17,7 +16,6 @@ import org.matsim.contrib.freight.carrier.CarrierImpl; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; @@ -36,17 +34,11 @@ import demand.offer.OfferFactoryImpl; import demand.offer.OfferTransferrer; import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlan; -import lsp.LSPPlanImpl; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; import lsp.SolutionScheduler; import lsp.resources.Resource; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; import lsp.shipment.Requirement; import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; diff --git a/test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java b/test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java new file mode 100644 index 00000000000..7c436f015c3 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java @@ -0,0 +1,37 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.demandObject.DemandObject; +import demand.demandObject.OfferRequester; +import demand.offer.Offer; + +public class AllOffersRequester implements OfferRequester{ + + private DemandObject demandObject; + + public AllOffersRequester() { + + } + + @Override + public Collection requestOffers(Collection lsps) { + ArrayList offers = new ArrayList(); + for(LSPDecorator lsp : lsps) { + for(LogisticsSolutionDecorator solution : lsp.getSelectedPlan().getSolutionDecorators()) { + offers.add(lsp.getOffer(demandObject, "linear", solution.getId())); + } + } + return offers; + } + + @Override + public void setDemandObject(DemandObject demandObject) { + this.demandObject = demandObject; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java b/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java new file mode 100644 index 00000000000..a54a6c02a99 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java @@ -0,0 +1,87 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.events.ServiceBeginsEvent; +import lsp.events.ServiceBeginsEventHandler; +import lsp.events.ServiceCompletedEvent; +import lsp.events.ServiceCompletedEventHandler; + + +public class CollectionServiceHandler implements ServiceBeginsEventHandler, ServiceCompletedEventHandler{ + + + + private class ServiceTuple { + private CarrierService service; + private double startTime; + + public ServiceTuple(CarrierService service, double startTime) { + this.service = service; + this.startTime = startTime; + } + + public CarrierService getService() { + return service; + } + + public double getStartTime() { + return startTime; + } + + } + + private Collection tuples; + private double totalLoadingCosts; + private int totalNumberOfShipments; + private int totalWeightOfShipments; + + public CollectionServiceHandler() { + this.tuples = new ArrayList(); + } + + @Override + public void reset(int iteration) { + tuples.clear(); + totalNumberOfShipments = 0; + totalWeightOfShipments = 0; + totalLoadingCosts = 0; + } + + @Override + public void handleEvent(ServiceCompletedEvent event) { + double loadingCosts = 0; + for(ServiceTuple tuple : tuples) { + if(tuple.getService() == event.getService()) { + double serviceDuration = event.getTime() - tuple.getStartTime(); + loadingCosts = serviceDuration * event.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; + totalLoadingCosts = totalLoadingCosts + loadingCosts; + tuples.remove(tuple); + break; + } + } + } + + @Override + public void handleEvent(ServiceBeginsEvent event) { + totalNumberOfShipments++; + totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); + tuples.add(new ServiceTuple(event.getService(), event.getTime())); + } + + public double getTotalLoadingCosts() { + return totalLoadingCosts; + } + + public int getTotalNumberOfShipments() { + return totalNumberOfShipments; + } + + public int getTotalWeightOfShipments() { + return totalWeightOfShipments; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/CostInfo.java b/test/testMutualreplanningWithOfferUpdate/CostInfo.java new file mode 100644 index 00000000000..f81982df75a --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/CostInfo.java @@ -0,0 +1,42 @@ +package testMutualreplanningWithOfferUpdate; + +import lsp.functions.Info; +import lsp.functions.InfoFunction; + +public class CostInfo extends Info { + + private CostInfoFunction costFunction; + + public CostInfo() { + this.costFunction = new CostInfoFunction(); + } + + + @Override + public String getName() { + return "cost_function"; + } + + @Override + public InfoFunction getFunction() { + return costFunction; + } + + @Override + public double getFromTime() { + return 0; + } + + @Override + public double getToTime() { + return Double.MAX_VALUE; + } + + + @Override + public void update() { + // TODO Auto-generated method stub + + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java b/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java new file mode 100644 index 00000000000..5f917bdf1e4 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java @@ -0,0 +1,29 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.ArrayList; +import java.util.Collection; + +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionValue; + +public class CostInfoFunction implements InfoFunction { + + private FixedCostFunctionValue fixedValue; + private LinearCostFunctionValue linearValue; + private Collection values; + + public CostInfoFunction() { + values = new ArrayList(); + fixedValue = new FixedCostFunctionValue(); + linearValue = new LinearCostFunctionValue(); + values.add(fixedValue); + values.add(linearValue); + + } + + @Override + public Collection getValues() { + return values; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java b/test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java new file mode 100644 index 00000000000..5303f78faf1 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java @@ -0,0 +1,82 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; + +import lsp.events.FreightLinkEnterEvent; +import lsp.events.FreightLinkLeaveEvent; +import lsp.events.FreightLinkLeaveEventHandler; +import lsp.events.FreightVehicleLeavesTrafficEvent; +import lsp.events.FreightVehicleLeavesTrafficEventHandler; +import lsp.usecase.FreightLinkEnterEventHandler; + +public class DistanceAndTimeHandler implements FreightLinkEnterEventHandler, FreightVehicleLeavesTrafficEventHandler, FreightLinkLeaveEventHandler { + + private Collection events; + private double distanceCosts; + private double timeCosts; + private Network network; + + public DistanceAndTimeHandler(Network network) { + this.network = network; + this.events = new ArrayList(); + } + + + @Override + public void handleEvent(FreightLinkEnterEvent event) { + events.add(event); + + } + + @Override + public void reset(int iteration) { + events.clear(); + distanceCosts = 0; + timeCosts = 0; + } + + + @Override + public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } + + + @Override + public void handleEvent(FreightLinkLeaveEvent leaveEvent) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } + + public double getDistanceCosts() { + return distanceCosts; + } + + public double getTimeCosts() { + return timeCosts; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java b/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java new file mode 100644 index 00000000000..5f03fb25ff5 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java @@ -0,0 +1,29 @@ +package testMutualreplanningWithOfferUpdate; + +import lsp.functions.InfoFunctionValue; + +public class FixedCostFunctionValue implements InfoFunctionValue { + + private String value; + + @Override + public String getName() { + return "fixed"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java b/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java new file mode 100644 index 00000000000..407e3108a34 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java @@ -0,0 +1,29 @@ +package testMutualreplanningWithOfferUpdate; + +import lsp.functions.InfoFunctionValue; + +public class LinearCostFunctionValue implements InfoFunctionValue { + + private String value; + + @Override + public String getName() { + return "linear"; + } + + @Override + public Class getDataType() { + return Double.class; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java b/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java new file mode 100644 index 00000000000..92c65730858 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java @@ -0,0 +1,104 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.core.controler.events.AfterMobsimEvent; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; +import lsp.tracking.SimulationTracker; + +public class LinearCostTracker implements SimulationTracker{ + + private Collection eventHandlers; + private Collection infos; + private double distanceCosts; + private double timeCosts; + private double loadingCosts; + private double vehicleFixedCosts; + private int totalNumberOfShipments; + private int totalWeightOfShipments; + + private double fixedUnitCosts; + private double linearUnitCosts; + + private double shareOfFixedCosts; + + public LinearCostTracker(double shareOfFixedCosts) { + this.shareOfFixedCosts = shareOfFixedCosts; + CostInfo costInfo = new CostInfo(); + infos = new ArrayList(); + infos.add(costInfo); + this.eventHandlers = new ArrayList(); + } + + + @Override + public Collection getEventHandlers() { + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void notifyAfterMobsim(AfterMobsimEvent event) { + + for(EventHandler handler : eventHandlers) { + if(handler instanceof TourStartHandler) { + TourStartHandler startHandler = (TourStartHandler) handler; + this.vehicleFixedCosts = startHandler.getVehicleFixedCosts(); + } + if(handler instanceof DistanceAndTimeHandler) { + DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; + this.distanceCosts = distanceHandler.getDistanceCosts(); + this.timeCosts = distanceHandler.getTimeCosts(); + } + if(handler instanceof CollectionServiceHandler) { + CollectionServiceHandler collectionHandler = (CollectionServiceHandler) handler; + totalNumberOfShipments = collectionHandler.getTotalNumberOfShipments(); + totalWeightOfShipments = collectionHandler.getTotalWeightOfShipments(); + loadingCosts = collectionHandler.getTotalLoadingCosts(); + } + } + + double totalCosts = distanceCosts + timeCosts + loadingCosts + vehicleFixedCosts; + fixedUnitCosts = (totalCosts * shareOfFixedCosts)/totalNumberOfShipments; + linearUnitCosts = (totalCosts * (1-shareOfFixedCosts))/totalWeightOfShipments; + + CostInfo info = (CostInfo) infos.iterator().next(); + for(InfoFunctionValue value : info.getFunction().getValues()) { + if(value instanceof FixedCostFunctionValue) { + ((FixedCostFunctionValue)value).setValue(Double.toString(fixedUnitCosts)); + } + if(value instanceof LinearCostFunctionValue) { + ((LinearCostFunctionValue)value).setValue(Double.toString(linearUnitCosts)); + } + } + + + } + + + @Override + public void reset() { + for(EventHandler eventHandler : eventHandlers) { + eventHandler.reset(0); + } + distanceCosts = 0; + timeCosts = 0; + loadingCosts = 0; + vehicleFixedCosts = 0; + totalNumberOfShipments = 0; + totalWeightOfShipments = 0; + fixedUnitCosts = 0; + linearUnitCosts = 0; + } + + + +} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOffer.java b/test/testMutualreplanningWithOfferUpdate/LinearOffer.java new file mode 100644 index 00000000000..fd5ab8938bb --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/LinearOffer.java @@ -0,0 +1,98 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.Random; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import lsp.functions.Info; +import lsp.functions.InfoFunctionValue; + + +public class LinearOffer implements Offer{ + + private LSPDecorator lsp; + private LogisticsSolutionDecorator solution; + private String type; + private double fix; + private double linear; + + public LinearOffer(LogisticsSolutionDecorator solution) { + this.lsp = solution.getLSP(); + this.solution = solution; + this.type = "linear"; + Random random = new Random(1); + fix = random.nextDouble() * 10; + linear = random.nextDouble() * 10; + } + + @Override + public LSPDecorator getLsp() { + return lsp; + } + + @Override + public LogisticsSolutionDecorator getSolution() { + return solution; + } + + @Override + public String getType() { + return type; + } + + public double getFix() { + return fix; + } + + public void setFix(double fix) { + this.fix = fix; + } + + public double getLinear() { + return linear; + } + + public void setLinear(double linear) { + this.linear = linear; + } + + @Override + public void accept(OfferVisitor visitor) { + visitor.visit(this); + } + + @Override + public void update() { + for(Info info : solution.getInfos()) { + if(info instanceof CostInfo) { + CostInfo costInfo = (CostInfo) info; + CostInfoFunction costFunction = (CostInfoFunction) costInfo.getFunction(); + FixedCostFunctionValue fixedValue; + LinearCostFunctionValue linearValue; + for(InfoFunctionValue value : costFunction.getValues()) { + if(value instanceof FixedCostFunctionValue) { + fixedValue = (FixedCostFunctionValue) value; + this.fix = Double.parseDouble(fixedValue.getValue()); + } + if(value instanceof LinearCostFunctionValue) { + linearValue = (LinearCostFunctionValue) value; + this.linear = Double.parseDouble(linearValue.getValue()); + } + } + } + } + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public void setSolution(LogisticsSolutionDecorator solution) { + this.solution = solution; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java b/test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java new file mode 100644 index 00000000000..f08a357df04 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java @@ -0,0 +1,74 @@ +package testMutualreplanningWithOfferUpdate; + +import java.util.ArrayList; +import java.util.Collection; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandObject.DemandObject; +import demand.offer.DefaultOfferImpl; +import demand.offer.Offer; +import demand.offer.OfferFactory; +import lsp.LSP; +import lsp.LogisticsSolution; + +public class LinearOfferFactoryImpl implements OfferFactory{ + + + private ArrayList offerList; + private LogisticsSolutionDecorator solution; + private LSPDecorator lsp; + + public LinearOfferFactoryImpl(LogisticsSolutionDecorator solution) { + this.solution = solution; + this.lsp = solution.getLSP(); + offerList = new ArrayList(); + offerList.add(new LinearOffer(solution)); + } + + @Override + public Offer makeOffer(DemandObject object, String offerType) { + for(Offer offer : offerList) { + if(offer.getType() == offerType) { + offer.setLSP(lsp); + return offer; + } + } + return new DefaultOfferImpl(this.lsp, this.solution); + } + + @Override + public Collection getOffers() { + return offerList; + } + + @Override + public LSPDecorator getLSP() { + return lsp; + } + + @Override + public LogisticsSolutionDecorator getLogisticsSolution() { + return solution; + } + + @Override + public void setLogisticsSolution(LogisticsSolutionDecorator solution) { + this.solution = solution; + } + + @Override + public void setLSP(LSPDecorator lsp) { + this.lsp = lsp; + } + + @Override + public void addOffer(Offer offer) { + // TODO Auto-generated method stub + + } + + +} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java b/test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java new file mode 100644 index 00000000000..4cec7cb4e93 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java @@ -0,0 +1,35 @@ +package testMutualreplanningWithOfferUpdate; + +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.offer.Offer; +import demand.offer.OfferVisitor; +import lsp.LogisticsSolution; + +public class LinearOfferVisitor implements OfferVisitor { + + private LogisticsSolutionDecorator solution; + + public LinearOfferVisitor(LogisticsSolutionDecorator solution) { + this.solution = solution; + } + + + @Override + public void visit(Offer offer) { + if(offer instanceof LinearOffer) { + LinearOffer linearOffer = (LinearOffer) offer; + linearOffer.update(); + } + } + + @Override + public Class getOfferClass(){ + return LinearOffer.class; + } + + @Override + public LogisticsSolution getLogisticsSolution() { + return solution; + } + +} diff --git a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java new file mode 100644 index 00000000000..126e0d1253c --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java @@ -0,0 +1,291 @@ +package testMutualreplanningWithOfferUpdate; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.replanning.selectors.BestPlanSelector; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import demand.decoratedLSP.LSPDecorator; +import demand.decoratedLSP.LSPDecorators; +import demand.decoratedLSP.LSPPlanDecorator; +import demand.decoratedLSP.LSPPlanWithOfferTransferrer; +import demand.decoratedLSP.LSPWithOffers; +import demand.decoratedLSP.LogisticsSolutionDecorator; +import demand.decoratedLSP.LogisticsSolutionWithOffers; +import demand.demandAgent.DemandAgent; +import demand.demandAgent.DemandAgentImpl; +import demand.demandObject.DemandObject; +import demand.demandObject.DemandObjectImpl; +import demand.demandObject.DemandObjects; +import demand.demandObject.DemandPlanImpl; +import demand.demandObject.ShipperShipment; +import demand.demandObject.ShipperShipmentImpl; +import demand.mobsim.MutualModule; +import demand.mutualReplanning.DemandPlanStrategyImpl; +import demand.mutualReplanning.DemandReplannerImpl; +import demand.mutualReplanning.LSPWithOffersReplanner; +import demand.mutualReplanning.MutualReplanningModule; +import demand.mutualReplanning.MutualReplanningModuleImpl; +import demand.mutualReplanning.OfferReplanningStrategyModuleImpl; +import demand.offer.Offer; +import demand.offer.OfferFactoryImpl; +import demand.offer.OfferTransferrer; +import demand.offer.OfferUpdater; +import demand.offer.OfferUpdaterImpl; +import demand.scoring.MutualScoringModule; +import demand.scoring.MutualScoringModuleImpl; +import lsp.functions.Info; +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import testMutualReplanning.FortyTwoDemandScorer; +import testMutualReplanning.HalfLotSizeDemandPlanGenerator; +import testMutualReplanning.SimpleOfferTransferrer; + + +public class MutualReplanningAndOfferUpdateTest { + + private LSPDecorator lsp; + private Collection demandObjects; + private OfferFactoryImpl offerFactory; + private LinearCostTracker tracker; + private LinearOfferVisitor linearVisitor; + private LSPPlanDecorator collectionPlan; + private LogisticsSolutionDecorator solution; + private double initialFixed; + private + double initialVariable; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + Network network = scenario.getNetwork(); + ArrayList linkList = new ArrayList(network.getLinks().values()); + Random random = new Random(1); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(20); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionElementBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); + + Id solutionId = Id.create("Solution", LogisticsSolution.class); + LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); + solutionBuilder.addSolutionElement(collectionElement); + solution = solutionBuilder.build(); + + tracker = new LinearCostTracker(0.2); + tracker.getEventHandlers().add(new TourStartHandler()); + tracker.getEventHandlers().add(new CollectionServiceHandler()); + tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); + solution.addSimulationTracker(tracker); + + offerFactory = new OfferFactoryImpl(solution); + LinearOffer offer = new LinearOffer(solution); + initialFixed = offer.getFix(); + initialVariable = offer.getLinear(); + offerFactory.addOffer(offer); + solution.setOfferFactory(offerFactory); + + LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); + plan.addSolution(solution); + + OfferTransferrer transferrer = new SimpleOfferTransferrer(); + plan.setOfferTransferrer(transferrer); + + LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); + offerLSPBuilder.setInitialPlan(plan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + offerLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + offerLSPBuilder.setSolutionScheduler(simpleScheduler); + + lsp = offerLSPBuilder.build(); + + LSPWithOffersReplanner replanner = new LSPWithOffersReplanner(lsp); + lsp.setReplanner(replanner); + + OfferUpdater updater = new OfferUpdaterImpl(); + lsp.setOfferUpdater(updater); + replanner.setOfferUpdater(updater); + linearVisitor = new LinearOfferVisitor(solution); + updater.getOfferVisitors().add(linearVisitor); + + + ArrayListdemandObjects = new ArrayList(); + + for(int i = 1; i < 11 ; i++) { + DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); + builder.setId(Id.create("DemandObject_" + i, DemandObject.class)); + DemandAgentImpl.Builder shipperBuilder = DemandAgentImpl.Builder.newInstance(); + shipperBuilder.setId(Id.create("DemandObject_" + i+ "_Shipper", DemandAgent.class)); + builder.setShipper(shipperBuilder.build()); + DemandAgentImpl.Builder recipientBuilder = DemandAgentImpl.Builder.newInstance(); + recipientBuilder.setId(Id.create("DemandObject_" + i+ "_Recipient", DemandAgent.class)); + builder.setRecipient(recipientBuilder.build()); + double shipmentSize= 5 + random.nextDouble()*5; + builder.setStrengthOfFlow(shipmentSize); + builder.setToLinkId(collectionLinkId); + + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); + ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); + shipmentBuilder.setId(Id.create("DemandObject_" + i+ "_Shipment", ShipperShipment.class)); + shipmentBuilder.setShipmentSize(shipmentSize); + shipmentBuilder.setServiceTime(shipmentSize * 60); + planBuilder.setShipperShipment(shipmentBuilder.build()); + planBuilder.setLsp(lsp); + planBuilder.setLogisticsSolutionId(lsp.getSelectedPlan().getSolutions().iterator().next().getId()); + builder.setInitialPlan(planBuilder.build()); + builder.setScorer(new FortyTwoDemandScorer()); + DemandReplannerImpl demandReplanner = new DemandReplannerImpl(); + DemandPlanStrategyImpl planStrategy = new DemandPlanStrategyImpl(new BestPlanSelector()); + planStrategy.addStrategyModule(new OfferReplanningStrategyModuleImpl()); + demandReplanner.addStrategy(planStrategy); + builder.setReplanner(demandReplanner); + builder.setOfferRequester(new AllOffersRequester()); + builder.setDemandPlanGenerator(new HalfLotSizeDemandPlanGenerator()); + DemandObject demandObject = builder.build(); + demandObjects.add(demandObject); + + } + + ArrayList lspList = new ArrayList<>(); + lspList.add(lsp); + + Controler controler = new Controler(config); + + MutualScoringModule mutScoreModule = new MutualScoringModuleImpl(demandObjects, lspList); + + MutualReplanningModule mutReplanModule = new MutualReplanningModuleImpl(lspList, demandObjects); + + MutualModule.Builder moduleBuilder = MutualModule.Builder.newInstance(); + moduleBuilder.setDemandObjects(new DemandObjects(demandObjects)); + moduleBuilder.setLsps(new LSPDecorators(lspList)); + moduleBuilder.setMutualReplanningModule(mutReplanModule); + moduleBuilder.setMutualScoringModule(mutScoreModule); + MutualModule mutualModule = moduleBuilder.build(); + + controler.addOverridingModule(mutualModule); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(2); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + + + } + + @Test + public void testOfferUpdater() { + + assertTrue(tracker == solution.getSimulationTrackers().iterator().next()); + int numberOfHandlers = 0; + for(EventHandler solutionHandler : solution.getEventHandlers()) { + for(EventHandler trackerHandler : tracker.getEventHandlers()) { + if(solutionHandler == trackerHandler) { + numberOfHandlers++; + } + } + } + assertTrue(numberOfHandlers == tracker.getEventHandlers().size()); + + for(Info solutionInfo : solution.getInfos()) { + for(Info trackerInfo : tracker.getInfos()) { + assertTrue(solutionInfo == trackerInfo); + } + } + + + assertTrue(offerFactory.getOffers().size() == 1 ); + for(Offer offer : offerFactory.getOffers()) { + assertTrue(offer instanceof LinearOffer); + LinearOffer linearOffer = (LinearOffer) offer; + assertTrue(linearOffer.getSolution() == solution); + assertTrue(linearOffer.getSolution().getLSP() == solution.getLSP()); + assertTrue(linearOffer.getSolution().getLSP() == lsp); + assertTrue(linearOffer.getLsp() == lsp); + assertTrue(linearOffer.getFix() != initialFixed); + assertTrue(linearOffer.getLinear() != initialVariable); + } + + } +} diff --git a/test/testMutualreplanningWithOfferUpdate/TourStartHandler.java b/test/testMutualreplanningWithOfferUpdate/TourStartHandler.java new file mode 100644 index 00000000000..2b47b2412e1 --- /dev/null +++ b/test/testMutualreplanningWithOfferUpdate/TourStartHandler.java @@ -0,0 +1,24 @@ +package testMutualreplanningWithOfferUpdate; + +import lsp.events.TourStartEvent; +import lsp.events.TourStartEventHandler; + +public class TourStartHandler implements TourStartEventHandler{ + + private double vehicleFixedCosts; + + @Override + public void reset(int iteration) { + vehicleFixedCosts = 0; + } + + @Override + public void handleEvent(TourStartEvent event) { + vehicleFixedCosts = vehicleFixedCosts + event.getVehicle().getVehicleType().getVehicleCostInformation().fix; + } + + public double getVehicleFixedCosts() { + return vehicleFixedCosts; + } + +} From fa58b50360d6ad505db9f754c25e0198abaa16da Mon Sep 17 00:00:00 2001 From: kturner Date: Fri, 9 Mar 2018 16:30:16 +0100 Subject: [PATCH 0027/1340] pom adjustments to MATSim 0.11.0-SNAPSHOT --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a5349d2d8aa..7c54cd0211a 100644 --- a/pom.xml +++ b/pom.xml @@ -27,12 +27,12 @@ org.matsim matsim - 0.10.0-SNAPSHOT + 0.11.0-SNAPSHOT org.matsim.contrib freight - 0.10.0-SNAPSHOT + 0.11.0-SNAPSHOT From 13d6dfb2ca19cdc5734b77ca518cf718a674dd7a Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 13 Mar 2018 16:03:32 +0100 Subject: [PATCH 0028/1340] Double count of traversed links in the handling LinkLeaveEvent removed --- test/lspSchedulingTests/CollectionLSPSchedulingTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index 533a3a81a7b..7e6028b5893 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -132,7 +132,7 @@ public void initialize() { Id toLinkId = collectionLinkId; - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); Random random = new Random(1); From ff2cc0ad97fd069d276ec60ff5f8a3cd1e3b1d4e Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 27 Mar 2018 17:10:30 +0200 Subject: [PATCH 0029/1340] Customized events are now created without having to open the class "CarrierResourceAgent" every time. Instead, EventCreators are injected to the LSPModule via the constructor. Creators of events that are often used are entered with the static method of EventUtils. This makes the code closed for changes and open for extensions, however the runtime is now longer, as all EventCreators are now checked in the CarrierResourceTracker after they were forwarded from the CarrierResourceAgent and only the CustomizedEvent(s) that apply are created. --- .../LSPReplanning/ExampleLSPReplanning.java | 3 +- .../example/LSPScoring/ExampleLSPScoring.java | 3 +- .../example/LSPScoring/TipEventHandler.java | 12 +- .../ExampleMobsimOfSimpleLSP.java | 3 +- .../ExampleMobsimOfTransportChain.java | 3 +- .../CollectionServiceHandler.java | 14 +- .../ExampleSimulationTrackers.java | 5 +- .../controler/MutualControlerListener.java | 106 +++++++------- test/cascadingInfoTest/CascadingInfoTest.java | 3 +- test/cascadingInfoTest/TimeSpanHandler.java | 8 +- .../CollectionLSPMobsimTest.java | 8 +- .../lspMobsimTests/CompleteLSPMobsimTest.java | 19 +-- .../FirstReloadLSPMobsimTest.java | 10 +- test/lspMobsimTests/MainRunLSPMobsimTest.java | 3 +- .../MainRunOnlyLSPMobsimTest.java | 3 +- .../SecondReloadLSPMobsimTest.java | 5 +- .../CollectionLSPReplanningTest.java | 3 +- .../CollectionLSPSchedulingTest.java | 5 +- .../CompleteLSPSchedulingTest.java | 4 +- .../CollectionLSPScoringTest.java | 3 +- .../TrinkgeldEventHandler.java | 12 +- .../CollectionServiceHandler.java | 14 +- .../CollectionTrackerTest.java | 138 ++++++++++++++++-- .../DistanceAndTimeHandler.java | 47 +++--- .../CollectionServiceHandler.java | 14 +- 25 files changed, 291 insertions(+), 157 deletions(-) diff --git a/examples/example/LSPReplanning/ExampleLSPReplanning.java b/examples/example/LSPReplanning/ExampleLSPReplanning.java index efa1eabbb6e..5ba93effc40 100644 --- a/examples/example/LSPReplanning/ExampleLSPReplanning.java +++ b/examples/example/LSPReplanning/ExampleLSPReplanning.java @@ -43,6 +43,7 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.replanning.LSPReplannerImpl; import lsp.replanning.LSPReplanningModuleImpl; import lsp.resources.Resource; @@ -194,7 +195,7 @@ public static void main(String[]args) { ArrayList lspList = new ArrayList(); lspList.add(lsp); LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); //Start the Mobsim two iterations are necessary for replanning Controler controler = new Controler(config); diff --git a/examples/example/LSPScoring/ExampleLSPScoring.java b/examples/example/LSPScoring/ExampleLSPScoring.java index 3de573ef0b9..7ba728b7685 100644 --- a/examples/example/LSPScoring/ExampleLSPScoring.java +++ b/examples/example/LSPScoring/ExampleLSPScoring.java @@ -35,6 +35,7 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.replanning.LSPReplanningModuleImpl; import lsp.resources.Resource; import lsp.scoring.LSPScoringModuleImpl; @@ -206,7 +207,7 @@ public static void main(String []args) { ArrayList lspList = new ArrayList(); lspList.add(lsp); LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); //Start the Mobsim one iteration is sufficient for scoring Controler controler = new Controler(config); diff --git a/examples/example/LSPScoring/TipEventHandler.java b/examples/example/LSPScoring/TipEventHandler.java index 57d683ce7c3..f42d967b53a 100644 --- a/examples/example/LSPScoring/TipEventHandler.java +++ b/examples/example/LSPScoring/TipEventHandler.java @@ -2,12 +2,12 @@ import java.util.Random; -import lsp.events.ServiceBeginsEvent; -import lsp.events.ServiceBeginsEventHandler; -import lsp.events.ServiceCompletedEvent; -import lsp.events.ServiceCompletedEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; -public class TipEventHandler implements ServiceCompletedEventHandler{ +public class TipEventHandler implements ServiceEndEventHandler{ private double trinkgeldSum; private Random trinkgeldRandom; @@ -23,7 +23,7 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceCompletedEvent event) { + public void handleEvent(ServiceEndEvent event) { double trinkgeld = trinkgeldRandom.nextDouble() * 5; System.out.println("ServiceEvent " + trinkgeld); trinkgeldSum += trinkgeld; diff --git a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java index c867d056f50..96c4d08d160 100644 --- a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java +++ b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java @@ -35,6 +35,7 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.replanning.LSPReplanningModuleImpl; import lsp.resources.Resource; import lsp.scoring.LSPScoringModuleImpl; @@ -183,7 +184,7 @@ public static void main (String[]args) { ArrayList lspList = new ArrayList(); lspList.add(lsp); LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); Controler controler = new Controler(config); controler.addOverridingModule(module); diff --git a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java index 49b2601b361..f7e792760de 100644 --- a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java +++ b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java @@ -35,6 +35,7 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.replanning.LSPReplanningModuleImpl; import lsp.resources.Resource; import lsp.scoring.LSPScoringModuleImpl; @@ -348,7 +349,7 @@ public static void main (String[]args) { ArrayList lspList = new ArrayList(); lspList.add(lsp); LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); Controler controler = new Controler(config); controler.addOverridingModule(module); diff --git a/examples/example/simulationTrackers/CollectionServiceHandler.java b/examples/example/simulationTrackers/CollectionServiceHandler.java index 86e8f08cb0c..bed8728b61c 100644 --- a/examples/example/simulationTrackers/CollectionServiceHandler.java +++ b/examples/example/simulationTrackers/CollectionServiceHandler.java @@ -5,13 +5,13 @@ import org.matsim.contrib.freight.carrier.CarrierService; -import lsp.events.ServiceBeginsEvent; -import lsp.events.ServiceBeginsEventHandler; -import lsp.events.ServiceCompletedEvent; -import lsp.events.ServiceCompletedEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; -public class CollectionServiceHandler implements ServiceBeginsEventHandler, ServiceCompletedEventHandler{ +public class CollectionServiceHandler implements ServiceStartEventHandler, ServiceEndEventHandler{ @@ -51,7 +51,7 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceCompletedEvent event) { + public void handleEvent(ServiceEndEvent event) { System.out.println("Service Ends"); double loadingCosts = 0; for(ServiceTuple tuple : tuples) { @@ -66,7 +66,7 @@ public void handleEvent(ServiceCompletedEvent event) { } @Override - public void handleEvent(ServiceBeginsEvent event) { + public void handleEvent(ServiceStartEvent event) { totalNumberOfShipments++; totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); tuples.add(new ServiceTuple(event.getService(), event.getTime())); diff --git a/examples/example/simulationTrackers/ExampleSimulationTrackers.java b/examples/example/simulationTrackers/ExampleSimulationTrackers.java index 4ced3d83cff..bacdc941059 100644 --- a/examples/example/simulationTrackers/ExampleSimulationTrackers.java +++ b/examples/example/simulationTrackers/ExampleSimulationTrackers.java @@ -35,6 +35,7 @@ import lsp.ShipmentAssigner; import lsp.SolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.functions.Info; import lsp.functions.InfoFunctionValue; import lsp.replanning.LSPReplanningModuleImpl; @@ -122,7 +123,7 @@ public static LSP createLSPWithTracker(Network network) { Id collectionLSPId = Id.create("CollectionLSP", LSP.class); collectionLSPBuilder.setId(collectionLSPId); - //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder + //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); @@ -195,7 +196,7 @@ public static void main (String [] args) { ArrayList lspList = new ArrayList(); lspList.add(lsp); LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); //Start the Mobsim one iteration is sufficient for tracking Controler controler = new Controler(config); diff --git a/src/demand/controler/MutualControlerListener.java b/src/demand/controler/MutualControlerListener.java index 94484f9bd3f..87490c72b7f 100644 --- a/src/demand/controler/MutualControlerListener.java +++ b/src/demand/controler/MutualControlerListener.java @@ -1,6 +1,8 @@ package demand.controler; import java.util.ArrayList; +import java.util.Collection; + import javax.inject.Inject; import org.matsim.api.core.v01.events.Event; @@ -32,6 +34,7 @@ import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.controler.FreightControlerListener; +import lsp.events.EventCreator; import lsp.functions.Info; import lsp.mobsim.CarrierResourceTracker; import lsp.resources.CarrierResource; @@ -48,28 +51,68 @@ public class MutualControlerListener implements FreightControlerListener, Before private DemandObjects demandObjects; private MutualScoringModule mutualScoringModule; private MutualReplanningModule replanningModule; - + private Collection creators; private ArrayList registeredHandlers; - @Inject - EventsManager eventsManager; - @Inject - Network network; + @Inject EventsManager eventsManager; + @Inject Network network; @Inject protected MutualControlerListener(LSPDecorators lsps, DemandObjects demandObjects, - MutualScoringModule demandScoringModule, MutualReplanningModule replanningModule) { + MutualScoringModule demandScoringModule, MutualReplanningModule replanningModule, Collection creators) { this.lsps = lsps; this.demandObjects = demandObjects; this.mutualScoringModule = demandScoringModule; this.replanningModule = replanningModule; + this.creators = creators; this.carriers = getCarriers(); } - public CarrierResourceTracker getCarrierResourceTracker() { - return carrierResourceTracker; + + @Override + public void notifyBeforeMobsim(BeforeMobsimEvent event) { + + carrierResourceTracker = new CarrierResourceTracker(carriers, network, this, creators); + eventsManager.addHandler(carrierResourceTracker); + + SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); + rescheduler.notifyBeforeMobsim(event); + + registeredHandlers = new ArrayList(); + + for (LSP lsp : lsps.getLSPs().values()) { + for (LSPShipment shipment : lsp.getShipments()) { + for (EventHandler handler : shipment.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + } + LSPPlan selectedPlan = lsp.getSelectedPlan(); + for (LogisticsSolution solution : selectedPlan.getSolutions()) { + for (EventHandler handler : solution.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + for (LogisticsSolutionElement element : solution.getSolutionElements()) { + for (EventHandler handler : element.getEventHandlers()) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + ArrayList resourceHandlers = (ArrayList) element.getResource() + .getEventHandlers(); + for (EventHandler handler : resourceHandlers) { + if (!registeredHandlers.contains(handler)) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + } + } + } + } } + + @Override public void notifyIterationEnds(IterationEndsEvent event) { @@ -171,48 +214,7 @@ public void notifyAfterMobsim(AfterMobsimEvent event) { } - @Override - public void notifyBeforeMobsim(BeforeMobsimEvent event) { - - carrierResourceTracker = new CarrierResourceTracker(carriers, network, this); - eventsManager.addHandler(carrierResourceTracker); - - SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); - rescheduler.notifyBeforeMobsim(event); - - registeredHandlers = new ArrayList(); - - for (LSP lsp : lsps.getLSPs().values()) { - for (LSPShipment shipment : lsp.getShipments()) { - for (EventHandler handler : shipment.getEventHandlers()) { - eventsManager.addHandler(handler); - registeredHandlers.add(handler); - } - } - LSPPlan selectedPlan = lsp.getSelectedPlan(); - for (LogisticsSolution solution : selectedPlan.getSolutions()) { - for (EventHandler handler : solution.getEventHandlers()) { - eventsManager.addHandler(handler); - registeredHandlers.add(handler); - } - for (LogisticsSolutionElement element : solution.getSolutionElements()) { - for (EventHandler handler : element.getEventHandlers()) { - eventsManager.addHandler(handler); - registeredHandlers.add(handler); - } - ArrayList resourceHandlers = (ArrayList) element.getResource() - .getEventHandlers(); - for (EventHandler handler : resourceHandlers) { - if (!registeredHandlers.contains(handler)) { - eventsManager.addHandler(handler); - registeredHandlers.add(handler); - } - } - } - } - } - } - + public void processEvent(Event event) { eventsManager.processEvent(event); } @@ -243,4 +245,8 @@ public void notifyStartup(StartupEvent event) { initialAssigner.notifyStartup(event); } + public CarrierResourceTracker getCarrierResourceTracker() { + return carrierResourceTracker; + } + } diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java index 9be1eee7a7a..7e5e996e1c6 100644 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -28,6 +28,7 @@ import org.matsim.vehicles.VehicleType; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -183,7 +184,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); diff --git a/test/cascadingInfoTest/TimeSpanHandler.java b/test/cascadingInfoTest/TimeSpanHandler.java index 0f2438f86fd..645009b65e3 100644 --- a/test/cascadingInfoTest/TimeSpanHandler.java +++ b/test/cascadingInfoTest/TimeSpanHandler.java @@ -3,14 +3,14 @@ import java.util.ArrayList; import java.util.Collection; -import lsp.events.ServiceBeginsEvent; -import lsp.events.ServiceBeginsEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; import lsp.events.TourStartEvent; import lsp.events.TourStartEventHandler; -public class TimeSpanHandler implements TourStartEventHandler, ServiceBeginsEventHandler{ +public class TimeSpanHandler implements TourStartEventHandler, ServiceStartEventHandler{ private int numberOfStops; private double totalTime; @@ -28,7 +28,7 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceBeginsEvent event) { + public void handleEvent(ServiceStartEvent event) { numberOfStops++; for(TourStartEvent startEvent : startEvents) { if(startEvent.getDriverId() == event.getDriverId()) { diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java index a419124d7f9..f3cff2ecb81 100644 --- a/test/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -32,6 +32,7 @@ import lsp.usecase.DeterministicShipmentAssigner; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -168,11 +169,11 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); + config.controler().setLastIteration(2); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -180,9 +181,6 @@ public void initialize() { @Test public void testCollectionLSPMobsim() { - - - for(LSPShipment shipment : collectionLSP.getShipments()) { assertFalse(shipment.getLog().getPlanElements().isEmpty()); assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/test/lspMobsimTests/CompleteLSPMobsimTest.java index 2c083d1c9b3..e39b5f8c0e6 100644 --- a/test/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/test/lspMobsimTests/CompleteLSPMobsimTest.java @@ -39,6 +39,7 @@ import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -64,10 +65,7 @@ public class CompleteLSPMobsimTest { private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP completeLSP; - private Carrier carrier; - private Resource completeAdapter; - private LogisticsSolutionElement completeElement; - + @Before public void initialize() { Config config = new Config(); @@ -272,15 +270,15 @@ public void initialize() { completeLSP = completeLSPBuilder.build(); ArrayList linkList = new ArrayList(network.getLinks().values()); - + Random rand = new Random(1); for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(4); + int capacityDemand = rand.nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { - Collections.shuffle(linkList); + Collections.shuffle(linkList,rand); Link pendingToLink = linkList.get(0); if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && @@ -295,7 +293,7 @@ public void initialize() { } while(true) { - Collections.shuffle(linkList); + Collections.shuffle(linkList, rand); Link pendingFromLink = linkList.get(0); if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && @@ -323,11 +321,11 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); + config.controler().setLastIteration(10); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -337,7 +335,6 @@ public void initialize() { public void testFirstReloadLSPMobsim() { for(LSPShipment shipment : completeLSP.getShipments()) { assertFalse(shipment.getLog().getPlanElements().isEmpty()); - //assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); diff --git a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java index 807093d22a0..7e47245b4c9 100644 --- a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -35,6 +35,7 @@ import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -158,11 +159,12 @@ public void initialize() { for(int i = 1; i < 4; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(4); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { - Collections.shuffle(linkList); + Collections.shuffle(linkList, random); Link pendingToLink = linkList.get(0); if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && @@ -177,7 +179,7 @@ public void initialize() { } while(true) { - Collections.shuffle(linkList); + Collections.shuffle(linkList, random); Link pendingFromLink = linkList.get(0); if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && @@ -205,7 +207,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); diff --git a/test/lspMobsimTests/MainRunLSPMobsimTest.java b/test/lspMobsimTests/MainRunLSPMobsimTest.java index 1bb2e48f8a0..fcf4183258d 100644 --- a/test/lspMobsimTests/MainRunLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunLSPMobsimTest.java @@ -37,6 +37,7 @@ import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -249,7 +250,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); diff --git a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java index e9a7bc84b0d..dd29037e73c 100644 --- a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -37,6 +37,7 @@ import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -189,7 +190,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); diff --git a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java index 1932422bf09..3361390a03d 100644 --- a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java @@ -29,6 +29,7 @@ import org.matsim.vehicles.VehicleType; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -277,11 +278,11 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); + config.controler().setLastIteration(4); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); diff --git a/test/lspReplanningTests/CollectionLSPReplanningTest.java b/test/lspReplanningTests/CollectionLSPReplanningTest.java index 16d15d77d8d..3ac15215ab4 100644 --- a/test/lspReplanningTests/CollectionLSPReplanningTest.java +++ b/test/lspReplanningTests/CollectionLSPReplanningTest.java @@ -33,6 +33,7 @@ import lsp.usecase.DeterministicShipmentAssigner; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlan; @@ -184,7 +185,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index 533a3a81a7b..789c7ab4cea 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -21,6 +21,7 @@ import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.carrier.ScheduledTour; import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.Tour; import org.matsim.contrib.freight.carrier.Tour.Leg; import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; import org.matsim.contrib.freight.carrier.Tour.TourElement; @@ -227,8 +228,6 @@ public void testCollectionLSPScheduling() { assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); assertTrue(endHandler.getLspShipment() == shipment); assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); - } - + } } - } diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index 8a2e4180d77..94672294684 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -259,10 +259,10 @@ public void initialize() { ArrayList linkList = new ArrayList(network.getLinks().values()); Random rand = new Random(1); - for(int i = 1; i < 6; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(10); + int capacityDemand = rand.nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java index 3aad1bbd429..2ddc63e1416 100644 --- a/test/lspScoringTests/CollectionLSPScoringTest.java +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -32,6 +32,7 @@ import lsp.usecase.DeterministicShipmentAssigner; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -186,7 +187,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); diff --git a/test/lspScoringTests/TrinkgeldEventHandler.java b/test/lspScoringTests/TrinkgeldEventHandler.java index 823e5880023..2d81845abbb 100644 --- a/test/lspScoringTests/TrinkgeldEventHandler.java +++ b/test/lspScoringTests/TrinkgeldEventHandler.java @@ -2,12 +2,12 @@ import java.util.Random; -import lsp.events.ServiceBeginsEvent; -import lsp.events.ServiceBeginsEventHandler; -import lsp.events.ServiceCompletedEvent; -import lsp.events.ServiceCompletedEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; -public class TrinkgeldEventHandler implements ServiceCompletedEventHandler{ +public class TrinkgeldEventHandler implements ServiceEndEventHandler{ private double trinkgeldSum; private Random trinkgeldRandom; @@ -23,7 +23,7 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceCompletedEvent event) { + public void handleEvent(ServiceEndEvent event) { double trinkgeld = trinkgeldRandom.nextDouble() * 5; System.out.println("ServiceEvent " + trinkgeld); trinkgeldSum += trinkgeld; diff --git a/test/testLSPWithCostTracker/CollectionServiceHandler.java b/test/testLSPWithCostTracker/CollectionServiceHandler.java index e458f1aa765..daba8d97718 100644 --- a/test/testLSPWithCostTracker/CollectionServiceHandler.java +++ b/test/testLSPWithCostTracker/CollectionServiceHandler.java @@ -5,13 +5,13 @@ import org.matsim.contrib.freight.carrier.CarrierService; -import lsp.events.ServiceBeginsEvent; -import lsp.events.ServiceBeginsEventHandler; -import lsp.events.ServiceCompletedEvent; -import lsp.events.ServiceCompletedEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; -public class CollectionServiceHandler implements ServiceBeginsEventHandler, ServiceCompletedEventHandler{ +public class CollectionServiceHandler implements ServiceStartEventHandler, ServiceEndEventHandler{ @@ -51,7 +51,7 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceCompletedEvent event) { + public void handleEvent(ServiceEndEvent event) { System.out.println("Service Ends"); double loadingCosts = 0; for(ServiceTuple tuple : tuples) { @@ -66,7 +66,7 @@ public void handleEvent(ServiceCompletedEvent event) { } @Override - public void handleEvent(ServiceBeginsEvent event) { + public void handleEvent(ServiceStartEvent event) { totalNumberOfShipments++; totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); tuples.add(new ServiceTuple(event.getService(), event.getTime())); diff --git a/test/testLSPWithCostTracker/CollectionTrackerTest.java b/test/testLSPWithCostTracker/CollectionTrackerTest.java index ff6b375406c..fbb1e4ea03c 100644 --- a/test/testLSPWithCostTracker/CollectionTrackerTest.java +++ b/test/testLSPWithCostTracker/CollectionTrackerTest.java @@ -1,5 +1,6 @@ package testLSPWithCostTracker; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -15,19 +16,33 @@ import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierCapabilities; import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierPlan; +import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.ScheduledTour; import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.End; +import org.matsim.contrib.freight.carrier.Tour.Leg; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.Start; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; +import org.matsim.contrib.freight.jsprit.NetworkRouter; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.events.handler.EventHandler; import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; import lsp.controler.LSPModule; +import lsp.events.EventUtils; import lsp.functions.Info; import lsp.functions.InfoFunctionValue; import lsp.LSP; @@ -45,6 +60,7 @@ import lsp.scoring.LSPScoringModuleImpl; import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; +import lsp.tracking.SimulationTracker; import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; import lsp.usecase.DeterministicShipmentAssigner; @@ -60,6 +76,7 @@ public class CollectionTrackerTest { private Resource collectionAdapter; private LogisticsSolutionElement collectionElement; private LogisticsSolution collectionSolution; + private double shareOfFixedCosts; @Before public void initialize() { @@ -114,8 +131,8 @@ public void initialize() { collectionSolutionBuilder.addSolutionElement(collectionElement); collectionSolution = collectionSolutionBuilder.build(); - - LinearCostTracker tracker = new LinearCostTracker(0.2); + shareOfFixedCosts = 0.2; + LinearCostTracker tracker = new LinearCostTracker(shareOfFixedCosts); tracker.getEventHandlers().add(new TourStartHandler()); tracker.getEventHandlers().add(new CollectionServiceHandler()); tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); @@ -180,7 +197,7 @@ public void initialize() { Controler controler = new Controler(config); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps)); + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); @@ -192,6 +209,102 @@ public void initialize() { @Test public void testCollectionTracker() { + assertTrue(collectionSolution.getSimulationTrackers().size() == 1); + SimulationTracker tracker = collectionSolution.getSimulationTrackers().iterator().next(); + assertTrue(tracker instanceof LinearCostTracker); + LinearCostTracker linearTracker = (LinearCostTracker) tracker; + double totalScheduledCosts = 0; + double totalTrackedCosts = 0; + double totalScheduledWeight = 0; + double totalTrackedWeight = 0; + int totalNumberOfScheduledShipments = 0; + int totalNumberOfTrackedShipments = 0; + for(EventHandler handler : linearTracker.getEventHandlers()) { + if(handler instanceof TourStartHandler) { + TourStartHandler startHandler = (TourStartHandler) handler; + double scheduledCosts = 0; + for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { + scheduledCosts += scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().fix; + totalScheduledCosts += scheduledCosts; + } + double trackedCosts = startHandler.getVehicleFixedCosts(); + totalTrackedCosts += trackedCosts; + assertEquals(trackedCosts, scheduledCosts, 0.1); + } + if(handler instanceof CollectionServiceHandler) { + CollectionServiceHandler serviceHandler = (CollectionServiceHandler) handler; + totalTrackedWeight = serviceHandler.getTotalWeightOfShipments(); + totalNumberOfTrackedShipments = serviceHandler.getTotalNumberOfShipments(); + double scheduledCosts = 0; + for(ScheduledTour scheduledTour: carrier.getSelectedPlan().getScheduledTours()) { + Tour tour = scheduledTour.getTour(); + for(TourElement element : tour.getTourElements()) { + if(element instanceof ServiceActivity){ + ServiceActivity activity = (ServiceActivity) element; + scheduledCosts += activity.getService().getServiceDuration() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; + totalScheduledCosts += scheduledCosts; + totalScheduledWeight += activity.getService().getCapacityDemand(); + totalNumberOfScheduledShipments++; + } + } + } + double trackedCosts = serviceHandler.getTotalLoadingCosts(); + totalTrackedCosts += trackedCosts; + assertEquals(trackedCosts, scheduledCosts, 0.1); + } + if(handler instanceof DistanceAndTimeHandler) { + DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; + double trackedTimeCosts = distanceHandler.getTimeCosts(); + totalTrackedCosts += trackedTimeCosts; + double scheduledTimeCosts = 0; + for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { + Tour tour = scheduledTour.getTour(); + for(TourElement element : tour.getTourElements() ) { + if(element instanceof Leg) { + Leg leg = (Leg) element; + scheduledTimeCosts += leg.getExpectedTransportTime() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; + } + } + } + totalScheduledCosts += scheduledTimeCosts; + assertEquals(scheduledTimeCosts, trackedTimeCosts, Math.max(scheduledTimeCosts,trackedTimeCosts)*0.01); + + double scheduledDistanceCosts = 0; + double trackedDistanceCosts = distanceHandler.getDistanceCosts(); + totalTrackedCosts += trackedDistanceCosts; + for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { + scheduledDistanceCosts += network.getLinks().get(scheduledTour.getTour().getEndLinkId()).getLength() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit; + for(TourElement element : scheduledTour.getTour().getTourElements()) { + System.out.println(element); + if(element instanceof Leg) { + Leg leg = (Leg) element; + NetworkRoute linkRoute = (NetworkRoute) leg.getRoute(); + for(Id linkId: linkRoute.getLinkIds()) { + scheduledDistanceCosts += network.getLinks().get(linkId).getLength() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit; + } + } + if(element instanceof ServiceActivity) { + ServiceActivity activity = (ServiceActivity) element; + scheduledDistanceCosts += network.getLinks().get(activity.getLocation()).getLength() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit; + } + } + } + totalScheduledCosts += scheduledDistanceCosts; + assertEquals(scheduledDistanceCosts, trackedDistanceCosts, Math.max(scheduledDistanceCosts,trackedDistanceCosts)*0.01); + } + } + + double linearTrackedCostsPerShipment = (totalTrackedCosts * (1-shareOfFixedCosts))/totalTrackedWeight; + double linearScheduledCostsPerShipment = (totalScheduledCosts * (1-shareOfFixedCosts))/totalScheduledWeight; + double fixedTrackedCostsPerShipment = (totalTrackedCosts * shareOfFixedCosts)/totalNumberOfTrackedShipments; + double fixedScheduledCostsPerShipment = (totalScheduledCosts * shareOfFixedCosts)/totalNumberOfScheduledShipments; + + assertEquals(totalTrackedWeight, totalTrackedWeight, 0); + assertEquals(totalNumberOfTrackedShipments, totalNumberOfScheduledShipments, 0); + assertEquals(totalTrackedCosts, totalScheduledCosts, Math.max(totalScheduledCosts, totalTrackedCosts)*0.01); + assertEquals(linearTrackedCostsPerShipment, linearScheduledCostsPerShipment, Math.max(linearTrackedCostsPerShipment, linearScheduledCostsPerShipment)*0.01); + assertEquals(fixedScheduledCostsPerShipment, fixedTrackedCostsPerShipment, Math.max(fixedTrackedCostsPerShipment, fixedScheduledCostsPerShipment)*0.01); + assertTrue(collectionSolution.getInfos().size() == 1); Info info = collectionSolution.getInfos().iterator().next(); assertTrue(info instanceof CostInfo); @@ -199,12 +312,17 @@ public void testCollectionTracker() { assertTrue(costInfo.getFunction() instanceof CostInfoFunction); CostInfoFunction function = (CostInfoFunction) costInfo.getFunction(); ArrayList values = new ArrayList(function.getValues()); - assertTrue(values.get(0).getDataType() == Double.class); - assertTrue(Double.valueOf(values.get(0).getValue()) > 0); - System.out.println(Double.valueOf(values.get(0).getValue())); - assertTrue(values.get(1).getDataType() == Double.class); - assertTrue(Double.valueOf(values.get(1).getValue()) > 0); - System.out.println(Double.valueOf(values.get(0).getValue())); + for(InfoFunctionValue value : values) { + if(value instanceof LinearCostFunctionValue) { + LinearCostFunctionValue linearValue = (LinearCostFunctionValue) value; + assertEquals(Double.parseDouble(linearValue.getValue()),linearTrackedCostsPerShipment, Math.max(linearTrackedCostsPerShipment,Double.parseDouble(linearValue.getValue())) * 0.01 ); + assertEquals(Double.parseDouble(linearValue.getValue()),linearScheduledCostsPerShipment, Math.max(linearScheduledCostsPerShipment,Double.parseDouble(linearValue.getValue())) * 0.01 ); + } + if(value instanceof FixedCostFunctionValue) { + FixedCostFunctionValue fixedValue = (FixedCostFunctionValue) value; + assertEquals(Double.parseDouble(fixedValue.getValue()),fixedTrackedCostsPerShipment, Math.max(fixedTrackedCostsPerShipment,Double.parseDouble(fixedValue.getValue())) * 0.01 ); + assertEquals(Double.parseDouble(fixedValue.getValue()),fixedScheduledCostsPerShipment, Math.max(fixedScheduledCostsPerShipment,Double.parseDouble(fixedValue.getValue())) * 0.01 ); + } + } } - } diff --git a/test/testLSPWithCostTracker/DistanceAndTimeHandler.java b/test/testLSPWithCostTracker/DistanceAndTimeHandler.java index d5b1d27b3b8..bd7877eaacd 100644 --- a/test/testLSPWithCostTracker/DistanceAndTimeHandler.java +++ b/test/testLSPWithCostTracker/DistanceAndTimeHandler.java @@ -30,7 +30,6 @@ public DistanceAndTimeHandler(Network network) { @Override public void handleEvent(FreightLinkEnterEvent event) { events.add(event); - } @Override @@ -42,32 +41,36 @@ public void reset(int iteration) { @Override public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } + if(enterEvent != null) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } + } + } } - + @Override public void handleEvent(FreightLinkLeaveEvent leaveEvent) { - for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; + if(events.size() > 0) { + for(FreightLinkEnterEvent enterEvent : events) { + if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && + (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { + double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); + timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); + double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); + distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); + events.remove(enterEvent); + break; + } } - } + } } public double getDistanceCosts() { diff --git a/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java b/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java index a54a6c02a99..3a758440b5c 100644 --- a/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java +++ b/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java @@ -5,13 +5,13 @@ import org.matsim.contrib.freight.carrier.CarrierService; -import lsp.events.ServiceBeginsEvent; -import lsp.events.ServiceBeginsEventHandler; -import lsp.events.ServiceCompletedEvent; -import lsp.events.ServiceCompletedEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; -public class CollectionServiceHandler implements ServiceBeginsEventHandler, ServiceCompletedEventHandler{ +public class CollectionServiceHandler implements ServiceStartEventHandler, ServiceEndEventHandler{ @@ -52,7 +52,7 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceCompletedEvent event) { + public void handleEvent(ServiceEndEvent event) { double loadingCosts = 0; for(ServiceTuple tuple : tuples) { if(tuple.getService() == event.getService()) { @@ -66,7 +66,7 @@ public void handleEvent(ServiceCompletedEvent event) { } @Override - public void handleEvent(ServiceBeginsEvent event) { + public void handleEvent(ServiceStartEvent event) { totalNumberOfShipments++; totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); tuples.add(new ServiceTuple(event.getService(), event.getTime())); From 18b1dec61e4b3770822c7ceeee5e1c0b090a0372 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Mon, 9 Apr 2018 16:17:38 +0200 Subject: [PATCH 0030/1340] Moved from package demand.mobsim which has been deleted --- src/demand/controler/MutualModule.java | 112 +++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/demand/controler/MutualModule.java diff --git a/src/demand/controler/MutualModule.java b/src/demand/controler/MutualModule.java new file mode 100644 index 00000000000..bddb1cd1cd1 --- /dev/null +++ b/src/demand/controler/MutualModule.java @@ -0,0 +1,112 @@ +package demand.controler; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.contrib.freight.CarrierConfig; +import org.matsim.core.controler.AbstractModule; + +import com.google.inject.Provides; + +import demand.decoratedLSP.LSPDecorators; +import demand.demandObject.DemandObjects; +import demand.mutualReplanning.MutualReplanningModule; +import demand.scoring.MutualScoringModule; +import lsp.events.EventCreator; +import lsp.mobsim.CarrierResourceTracker; +import lsp.mobsim.FreightQSimFactory; +import lsp.scoring.LSPScoringModule; + +public class MutualModule extends AbstractModule{ + + private LSPDecorators lsps; + private DemandObjects demandObjects; + private MutualScoringModule mutualScoringModule; + private MutualReplanningModule replanningModule; + private CarrierConfig carrierConfig = new CarrierConfig(); + private Collection creators; + + public static class Builder{ + + private LSPDecorators lsps; + private DemandObjects demandObjects; + private MutualScoringModule mutualScoringModule; + private MutualReplanningModule replanningModule; + private Collection creators; + + public static Builder newInstance() { + return new Builder(); + } + + public Builder setLsps(LSPDecorators lsps) { + this.lsps = lsps; + return this; + } + + public Builder setMutualScoringModule(MutualScoringModule demandScoringModule) { + this.mutualScoringModule = demandScoringModule; + return this; + } + + public Builder setMutualReplanningModule(MutualReplanningModule replanningModule) { + this.replanningModule = replanningModule; + return this; + } + + public Builder setDemandObjects(DemandObjects demandObjects) { + this.demandObjects = demandObjects; + return this; + } + + public Builder setEventCreators(Collection creators) { + this.creators = creators; + return this; + } + + public MutualModule build() { + return new MutualModule(this); + } + } + + private MutualModule(Builder builder) { + this.lsps = builder.lsps; + this.demandObjects = builder.demandObjects; + this.mutualScoringModule = builder.mutualScoringModule; + this.replanningModule = builder.replanningModule; + this.creators = builder.creators; + } + + + @Override + public void install() { + bind(CarrierConfig.class).toInstance(carrierConfig); + bind(LSPDecorators.class).toInstance(lsps); + bind(DemandObjects.class).toInstance(demandObjects); + + if(replanningModule != null) { + bind(MutualReplanningModule.class).toInstance(replanningModule); + } + if(mutualScoringModule != null) { + bind(MutualScoringModule.class).toInstance(mutualScoringModule); + } + bind(MutualControlerListener.class).asEagerSingleton(); + addControlerListenerBinding().to(MutualControlerListener.class); + bindMobsim().toProvider(FreightQSimFactory.class); + + } + + @Provides + Collection provideEventCreators(){ + return this.creators; + } + + @Provides + CarrierResourceTracker provideCarrierResourceTracker(MutualControlerListener mutualControlerListener) { + return mutualControlerListener.getCarrierResourceTracker(); + } + + public void setPhysicallyEnforceTimeWindowBeginnings(boolean physicallyEnforceTimeWindowBeginnings) { + this.carrierConfig.setPhysicallyEnforceTimeWindowBeginnings(physicallyEnforceTimeWindowBeginnings); + } + +} From 07abd4c8a418a3920b43632f306e5b0dc3bd3cc5 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Fri, 20 Apr 2018 17:34:13 +0200 Subject: [PATCH 0031/1340] Changed Info to work with generics instead of using Strings for the input and output of the valued and a class wildcard to describe the class of the stored value. This comes at the price of having a Collection of InfoFunctionValues parameterized with a wildcard and the typecast that comes along with it. --- .../LSPReplanning/ExampleLSPReplanning.java | 7 +- .../example/LSPScoring/ExampleLSPScoring.java | 10 ++- .../example/LSPScoring/TipEventHandler.java | 21 +++-- examples/example/LSPScoring/TipInfo.java | 12 ++- .../example/LSPScoring/TipInfoFunction.java | 23 ------ .../LSPScoring/TipInfoFunctionValue.java | 35 --------- examples/example/LSPScoring/TipScorer.java | 6 +- .../LSPScoring/TipSimulationTracker.java | 8 +- .../requirementsChecking/BlueInfo.java | 13 +++- .../BlueInfoFunctionValue.java | 30 ------- .../example/requirementsChecking/RedInfo.java | 14 +++- .../RedInfoFunctionValue.java | 30 ------- .../example/simulationTrackers/CostInfo.java | 10 ++- .../simulationTrackers/CostInfoFunction.java | 8 +- .../FixedCostFunctionValue.java | 19 ++--- .../LinearCostFunctionValue.java | 16 ++-- .../simulationTrackers/LinearCostTracker.java | 12 ++- .../controler/MutualControlerListener.java | 78 +++++++++++-------- src/demand/controler/SupplyClearer.java | 8 ++ test/cascadingInfoTest/AverageTimeInfo.java | 26 +++++-- .../AverageTimeInfoFunction.java | 6 +- .../AverageTimeInfoFunctionValue.java | 19 ++--- .../cascadingInfoTest/AverageTimeTracker.java | 2 +- test/cascadingInfoTest/CascadingInfoTest.java | 4 +- .../CollectionLSPMobsimTest.java | 2 +- .../CollectionLSPReplanningTest.java | 7 -- .../CollectionLSPScoringTest.java | 34 ++++---- test/lspScoringTests/TipEventHandler.java | 35 +++++++++ .../{TrinkgeldInfo.java => TipInfo.java} | 14 +++- .../{TrinkgeldScorer.java => TipScorer.java} | 18 ++--- ...Tracker.java => TipSimulationTracker.java} | 16 ++-- .../TrinkgeldEventHandler.java | 35 --------- .../TrinkgeldInfoFunction.java | 23 ------ .../TrinkgeldInfoFunctionValue.java | 35 --------- .../CompleteLSPShipmentAssignerTest.java | 2 +- test/requirementsCheckerTests/BlueInfo.java | 12 ++- .../BlueInfoFunctionValue.java | 30 ------- test/requirementsCheckerTests/RedInfo.java | 12 ++- .../RedInfoFunctionValue.java | 30 ------- .../CollectionTrackerTest.java | 12 +-- test/testLSPWithCostTracker/CostInfo.java | 7 ++ .../CostInfoFunction.java | 6 +- .../FixedCostFunctionValue.java | 19 ++--- .../LinearCostFunctionValue.java | 16 ++-- .../LinearCostTracker.java | 4 +- .../MutualReplanningTest.java | 6 +- .../CostInfo.java | 7 ++ .../CostInfoFunction.java | 6 +- .../FixedCostFunctionValue.java | 13 +--- .../LinearCostFunctionValue.java | 13 +--- .../LinearCostTracker.java | 4 +- .../LinearOffer.java | 4 +- .../MutualReplanningAndOfferUpdateTest.java | 6 +- 53 files changed, 339 insertions(+), 506 deletions(-) delete mode 100644 examples/example/LSPScoring/TipInfoFunction.java delete mode 100644 examples/example/LSPScoring/TipInfoFunctionValue.java delete mode 100644 examples/example/requirementsChecking/BlueInfoFunctionValue.java delete mode 100644 examples/example/requirementsChecking/RedInfoFunctionValue.java create mode 100644 test/lspScoringTests/TipEventHandler.java rename test/lspScoringTests/{TrinkgeldInfo.java => TipInfo.java} (62%) rename test/lspScoringTests/{TrinkgeldScorer.java => TipScorer.java} (50%) rename test/lspScoringTests/{TrinkgeldSimulationTracker.java => TipSimulationTracker.java} (63%) delete mode 100644 test/lspScoringTests/TrinkgeldEventHandler.java delete mode 100644 test/lspScoringTests/TrinkgeldInfoFunction.java delete mode 100644 test/lspScoringTests/TrinkgeldInfoFunctionValue.java delete mode 100644 test/requirementsCheckerTests/BlueInfoFunctionValue.java delete mode 100644 test/requirementsCheckerTests/RedInfoFunctionValue.java diff --git a/examples/example/LSPReplanning/ExampleLSPReplanning.java b/examples/example/LSPReplanning/ExampleLSPReplanning.java index 5ba93effc40..b2531c475f5 100644 --- a/examples/example/LSPReplanning/ExampleLSPReplanning.java +++ b/examples/example/LSPReplanning/ExampleLSPReplanning.java @@ -25,12 +25,7 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import example.LSPScoring.TipEventHandler; -import example.LSPScoring.TipInfo; -import example.LSPScoring.TipInfoFunction; -import example.LSPScoring.TipInfoFunctionValue; -import example.LSPScoring.TipScorer; -import example.LSPScoring.TipSimulationTracker; + import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlan; diff --git a/examples/example/LSPScoring/ExampleLSPScoring.java b/examples/example/LSPScoring/ExampleLSPScoring.java index 7ba728b7685..96a83eeecfe 100644 --- a/examples/example/LSPScoring/ExampleLSPScoring.java +++ b/examples/example/LSPScoring/ExampleLSPScoring.java @@ -36,6 +36,10 @@ import lsp.SolutionScheduler; import lsp.controler.LSPModule; import lsp.events.EventUtils; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; import lsp.replanning.LSPReplanningModuleImpl; import lsp.resources.Resource; import lsp.scoring.LSPScoringModuleImpl; @@ -127,12 +131,10 @@ public static LSP createLSPWithScorer(Network network) { TipEventHandler handler = new TipEventHandler(); //Create Info for the SimulationTracker which the scorer needs - TipInfoFunctionValue value = new TipInfoFunctionValue(); - TipInfoFunction function = new TipInfoFunction(); - function.getValues().add(value); + InfoFunction function = new InfoFunctionImpl(); TipInfo info = new TipInfo(function); - //Create SimulationTracker foe the information that the Scorer needs + //Create SimulationTracker for the information that the Scorer needs TipSimulationTracker tracker = new TipSimulationTracker(handler,info); //add SimulationTracker to the Resource collectionAdapter.addSimulationTracker(tracker); diff --git a/examples/example/LSPScoring/TipEventHandler.java b/examples/example/LSPScoring/TipEventHandler.java index f42d967b53a..a95e4dcfdc4 100644 --- a/examples/example/LSPScoring/TipEventHandler.java +++ b/examples/example/LSPScoring/TipEventHandler.java @@ -2,34 +2,31 @@ import java.util.Random; -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; import lsp.events.ServiceEndEvent; import lsp.events.ServiceEndEventHandler; public class TipEventHandler implements ServiceEndEventHandler{ - private double trinkgeldSum; - private Random trinkgeldRandom; + private double tipSum; + private Random tipRandom; public TipEventHandler() { - trinkgeldRandom = new Random(1); - trinkgeldSum = 0; + tipRandom = new Random(1); + tipSum = 0; } @Override public void reset(int iteration) { - trinkgeldSum = 0; + tipSum = 0; } @Override public void handleEvent(ServiceEndEvent event) { - double trinkgeld = trinkgeldRandom.nextDouble() * 5; - System.out.println("ServiceEvent " + trinkgeld); - trinkgeldSum += trinkgeld; + double tip = tipRandom.nextDouble() * 5; + tipSum += tip; } - public double getTrinkgeld() { - return trinkgeldSum; + public double getTip() { + return tipSum; } } diff --git a/examples/example/LSPScoring/TipInfo.java b/examples/example/LSPScoring/TipInfo.java index 688cf57e566..2692f2ed676 100644 --- a/examples/example/LSPScoring/TipInfo.java +++ b/examples/example/LSPScoring/TipInfo.java @@ -5,10 +5,10 @@ public class TipInfo extends Info{ - private TipInfoFunction function; - private String name = "TRINKGELDINFO"; + private InfoFunction function; + private String name = "TIPINFO"; - public TipInfo (TipInfoFunction function) { + public TipInfo (InfoFunction function) { this.function = function; } @@ -38,4 +38,10 @@ public void update() { } + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/examples/example/LSPScoring/TipInfoFunction.java b/examples/example/LSPScoring/TipInfoFunction.java deleted file mode 100644 index 82a0b36960a..00000000000 --- a/examples/example/LSPScoring/TipInfoFunction.java +++ /dev/null @@ -1,23 +0,0 @@ -package example.LSPScoring; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; - -public class TipInfoFunction implements InfoFunction{ - - private Collection values; - - public TipInfoFunction() { - this.values = new ArrayList(); - } - - - @Override - public Collection getValues() { - return values; - } - -} diff --git a/examples/example/LSPScoring/TipInfoFunctionValue.java b/examples/example/LSPScoring/TipInfoFunctionValue.java deleted file mode 100644 index d6afbfab183..00000000000 --- a/examples/example/LSPScoring/TipInfoFunctionValue.java +++ /dev/null @@ -1,35 +0,0 @@ -package example.LSPScoring; - -import lsp.functions.InfoFunctionValue; - -public class TipInfoFunctionValue implements InfoFunctionValue{ - - private String name = "TRINKGELD IN EUR"; - private Class type; - private double value; - - public TipInfoFunctionValue() { - this.type = double.class; - } - - @Override - public String getName() { - return name; - } - - @Override - public Class getDataType() { - return type; - } - - @Override - public String getValue() { - return String.valueOf(value); - } - - @Override - public void setValue(String value) { - this.value = Double.valueOf(value).doubleValue(); - } - -} diff --git a/examples/example/LSPScoring/TipScorer.java b/examples/example/LSPScoring/TipScorer.java index 583a8cd46ee..04b22a75744 100644 --- a/examples/example/LSPScoring/TipScorer.java +++ b/examples/example/LSPScoring/TipScorer.java @@ -20,11 +20,11 @@ public TipScorer(LSP lsp, TipSimulationTracker tracker) { public double scoreCurrentPlan(LSP lsp) { double score = 0; for(Info info : tracker.getInfos()) { - if(info.getName() == "TRINKGELDINFO") { + if(info instanceof TipInfo) { InfoFunction function = info.getFunction(); for(InfoFunctionValue value : function.getValues()) { - if(value.getName() == "TRINKGELD IN EUR") { - double trinkgeldValue = Double.parseDouble(value.getValue()); + if(value.getName() == "TIP IN EUR" && value.getValue() instanceof Double) { + double trinkgeldValue = (Double) value.getValue(); score += trinkgeldValue; } } diff --git a/examples/example/LSPScoring/TipSimulationTracker.java b/examples/example/LSPScoring/TipSimulationTracker.java index 363e17de872..7c4fe527367 100644 --- a/examples/example/LSPScoring/TipSimulationTracker.java +++ b/examples/example/LSPScoring/TipSimulationTracker.java @@ -8,6 +8,7 @@ import lsp.functions.Info; import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; import lsp.tracking.SimulationTracker; public class TipSimulationTracker implements SimulationTracker { @@ -36,9 +37,10 @@ public Collection getInfos() { @Override public void notifyAfterMobsim(AfterMobsimEvent event) { - double trinkgeld = handler.getTrinkgeld(); - InfoFunctionValue value = info.getFunction().getValues().iterator().next(); - value.setValue(String.valueOf(trinkgeld)); + double tip = handler.getTip(); + InfoFunctionValue value = new InfoFunctionValueImpl<>("TIP IN EUR"); + value.setValue(tip); + info.getFunction().getValues().add(value); } @Override diff --git a/examples/example/requirementsChecking/BlueInfo.java b/examples/example/requirementsChecking/BlueInfo.java index 0caa6c56570..ad3dc608343 100644 --- a/examples/example/requirementsChecking/BlueInfo.java +++ b/examples/example/requirementsChecking/BlueInfo.java @@ -3,14 +3,18 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; public class BlueInfo extends Info{ - private InfoFunctionImpl blueInfoFunction; +private InfoFunctionImpl blueInfoFunction; public BlueInfo() { blueInfoFunction = new InfoFunctionImpl(); - blueInfoFunction.getValues().add(new BlueInfoFunctionValue()); + InfoFunctionValue value = new InfoFunctionValueImpl("blue"); + value.setValue("blue"); + blueInfoFunction.getValues().add(value); } @Override @@ -41,4 +45,9 @@ public void update() { } + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } } diff --git a/examples/example/requirementsChecking/BlueInfoFunctionValue.java b/examples/example/requirementsChecking/BlueInfoFunctionValue.java deleted file mode 100644 index c7ffddbac1c..00000000000 --- a/examples/example/requirementsChecking/BlueInfoFunctionValue.java +++ /dev/null @@ -1,30 +0,0 @@ -package example.requirementsChecking; - -import java.awt.Color; - -import lsp.functions.InfoFunctionValue; - -public class BlueInfoFunctionValue implements InfoFunctionValue{ - - @Override - public String getName() { - return "blue"; - } - - @Override - public Class getDataType() { - return Color.class; - } - - @Override - public String getValue() { - return "blue"; - } - - @Override - public void setValue(String value) { - // TODO Auto-generated method stub - - } - -} diff --git a/examples/example/requirementsChecking/RedInfo.java b/examples/example/requirementsChecking/RedInfo.java index 35655904fea..fce91143619 100644 --- a/examples/example/requirementsChecking/RedInfo.java +++ b/examples/example/requirementsChecking/RedInfo.java @@ -3,14 +3,18 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; public class RedInfo extends Info{ - private InfoFunctionImpl redInfoFunction; +private InfoFunctionImpl redInfoFunction; public RedInfo() { redInfoFunction = new InfoFunctionImpl(); - redInfoFunction.getValues().add(new RedInfoFunctionValue()); + InfoFunctionValue value = new InfoFunctionValueImpl("red"); + value.setValue("red"); + redInfoFunction.getValues().add(value); } @Override @@ -41,4 +45,10 @@ public void update() { } + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/examples/example/requirementsChecking/RedInfoFunctionValue.java b/examples/example/requirementsChecking/RedInfoFunctionValue.java deleted file mode 100644 index 4462459987b..00000000000 --- a/examples/example/requirementsChecking/RedInfoFunctionValue.java +++ /dev/null @@ -1,30 +0,0 @@ -package example.requirementsChecking; - -import java.awt.Color; - -import lsp.functions.InfoFunctionValue; - -public class RedInfoFunctionValue implements InfoFunctionValue{ - - @Override - public String getName() { - return "red"; - } - - @Override - public Class getDataType() { - return Color.class; - } - - @Override - public String getValue() { - return "red"; - } - - @Override - public void setValue(String value) { - // TODO Auto-generated method stub - - } - -} diff --git a/examples/example/simulationTrackers/CostInfo.java b/examples/example/simulationTrackers/CostInfo.java index 55a607e5353..5d2eb0ccbbc 100644 --- a/examples/example/simulationTrackers/CostInfo.java +++ b/examples/example/simulationTrackers/CostInfo.java @@ -2,10 +2,11 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; +import testLSPWithCostTracker.CostInfoFunction; public class CostInfo extends Info { - private CostInfoFunction costFunction; +private CostInfoFunction costFunction; public CostInfo() { this.costFunction = new CostInfoFunction(); @@ -39,4 +40,11 @@ public void update() { } + + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/examples/example/simulationTrackers/CostInfoFunction.java b/examples/example/simulationTrackers/CostInfoFunction.java index 5d172a544b3..7cf9ba62e63 100644 --- a/examples/example/simulationTrackers/CostInfoFunction.java +++ b/examples/example/simulationTrackers/CostInfoFunction.java @@ -5,6 +5,8 @@ import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionValue; +import testLSPWithCostTracker.FixedCostFunctionValue; +import testLSPWithCostTracker.LinearCostFunctionValue; @@ -12,10 +14,10 @@ public class CostInfoFunction implements InfoFunction { private FixedCostFunctionValue fixedValue; private LinearCostFunctionValue linearValue; - private Collection values; + private Collection> values; public CostInfoFunction() { - values = new ArrayList(); + values = new ArrayList>(); fixedValue = new FixedCostFunctionValue(); linearValue = new LinearCostFunctionValue(); values.add(fixedValue); @@ -24,7 +26,7 @@ public CostInfoFunction() { } @Override - public Collection getValues() { + public Collection> getValues() { return values; } diff --git a/examples/example/simulationTrackers/FixedCostFunctionValue.java b/examples/example/simulationTrackers/FixedCostFunctionValue.java index cc4e56727e6..8ea20f19951 100644 --- a/examples/example/simulationTrackers/FixedCostFunctionValue.java +++ b/examples/example/simulationTrackers/FixedCostFunctionValue.java @@ -2,28 +2,23 @@ import lsp.functions.InfoFunctionValue; -public class FixedCostFunctionValue implements InfoFunctionValue { +public class FixedCostFunctionValue implements InfoFunctionValue { + + private double value; - private String value; - @Override public String getName() { return "fixed"; } @Override - public Class getDataType() { - return Double.class; - } - - @Override - public String getValue() { + public Double getValue() { return value; } @Override - public void setValue(String value) { - this.value = value; + public void setValue(Double value) { + this.value = value; } - + } diff --git a/examples/example/simulationTrackers/LinearCostFunctionValue.java b/examples/example/simulationTrackers/LinearCostFunctionValue.java index 8e8e8ba1dd9..318d9b03c66 100644 --- a/examples/example/simulationTrackers/LinearCostFunctionValue.java +++ b/examples/example/simulationTrackers/LinearCostFunctionValue.java @@ -2,28 +2,22 @@ import lsp.functions.InfoFunctionValue; -public class LinearCostFunctionValue implements InfoFunctionValue { +public class LinearCostFunctionValue implements InfoFunctionValue { + + private Double value; - private String value; - @Override public String getName() { return "linear"; } @Override - public Class getDataType() { - return Double.class; - } - - @Override - public String getValue() { + public Double getValue() { return value; } @Override - public void setValue(String value) { + public void setValue(Double value) { this.value = value; } - } diff --git a/examples/example/simulationTrackers/LinearCostTracker.java b/examples/example/simulationTrackers/LinearCostTracker.java index eebba27fc15..9e692569f0d 100644 --- a/examples/example/simulationTrackers/LinearCostTracker.java +++ b/examples/example/simulationTrackers/LinearCostTracker.java @@ -9,6 +9,12 @@ import lsp.functions.Info; import lsp.functions.InfoFunctionValue; import lsp.tracking.SimulationTracker; +import testLSPWithCostTracker.CollectionServiceHandler; +import testLSPWithCostTracker.CostInfo; +import testLSPWithCostTracker.DistanceAndTimeHandler; +import testLSPWithCostTracker.FixedCostFunctionValue; +import testLSPWithCostTracker.LinearCostFunctionValue; +import testLSPWithCostTracker.TourStartHandler; public class LinearCostTracker implements SimulationTracker{ @@ -73,10 +79,10 @@ public void notifyAfterMobsim(AfterMobsimEvent event) { CostInfo info = (CostInfo) infos.iterator().next(); for(InfoFunctionValue value : info.getFunction().getValues()) { if(value instanceof FixedCostFunctionValue) { - ((FixedCostFunctionValue)value).setValue(Double.toString(fixedUnitCosts)); + ((FixedCostFunctionValue)value).setValue(fixedUnitCosts); } if(value instanceof LinearCostFunctionValue) { - ((LinearCostFunctionValue)value).setValue(Double.toString(linearUnitCosts)); + ((LinearCostFunctionValue)value).setValue(linearUnitCosts); } } @@ -99,4 +105,4 @@ public void reset() { -} +} \ No newline at end of file diff --git a/src/demand/controler/MutualControlerListener.java b/src/demand/controler/MutualControlerListener.java index 87490c72b7f..115eceb1eb4 100644 --- a/src/demand/controler/MutualControlerListener.java +++ b/src/demand/controler/MutualControlerListener.java @@ -13,12 +13,14 @@ import org.matsim.core.controler.events.AfterMobsimEvent; import org.matsim.core.controler.events.BeforeMobsimEvent; import org.matsim.core.controler.events.IterationEndsEvent; +import org.matsim.core.controler.events.IterationStartsEvent; import org.matsim.core.controler.events.ReplanningEvent; import org.matsim.core.controler.events.ScoringEvent; import org.matsim.core.controler.events.StartupEvent; import org.matsim.core.controler.listener.AfterMobsimListener; import org.matsim.core.controler.listener.BeforeMobsimListener; import org.matsim.core.controler.listener.IterationEndsListener; +import org.matsim.core.controler.listener.IterationStartsListener; import org.matsim.core.controler.listener.ReplanningListener; import org.matsim.core.controler.listener.ScoringListener; import org.matsim.core.controler.listener.StartupListener; @@ -43,7 +45,7 @@ import lsp.tracking.SimulationTracker; public class MutualControlerListener implements FreightControlerListener, BeforeMobsimListener, AfterMobsimListener, - ScoringListener, ReplanningListener, IterationEndsListener, StartupListener { + ScoringListener, ReplanningListener, IterationEndsListener, StartupListener, IterationStartsListener { private CarrierResourceTracker carrierResourceTracker; private Carriers carriers; @@ -91,15 +93,12 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) { for (LogisticsSolution solution : selectedPlan.getSolutions()) { for (EventHandler handler : solution.getEventHandlers()) { eventsManager.addHandler(handler); - registeredHandlers.add(handler); } for (LogisticsSolutionElement element : solution.getSolutionElements()) { for (EventHandler handler : element.getEventHandlers()) { eventsManager.addHandler(handler); - registeredHandlers.add(handler); } - ArrayList resourceHandlers = (ArrayList) element.getResource() - .getEventHandlers(); + ArrayList resourceHandlers = (ArrayList) element.getResource().getEventHandlers(); for (EventHandler handler : resourceHandlers) { if (!registeredHandlers.contains(handler)) { eventsManager.addHandler(handler); @@ -115,34 +114,8 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) { @Override public void notifyIterationEnds(IterationEndsEvent event) { - SupplyClearer supplyClearer = new SupplyClearer(lsps); supplyClearer.notifyIterationEnds(event); - - for (EventHandler handler : registeredHandlers) { - eventsManager.removeHandler(handler); - } - - for (LSP lsp : lsps.getLSPs().values()) { - for (LSPShipment shipment : lsp.getShipments()) { - shipment.getEventHandlers().clear(); - } - - for (LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for (EventHandler handler : solution.getEventHandlers()) { - handler.reset(event.getIteration()); - } - for (LogisticsSolutionElement element : solution.getSolutionElements()) { - for (EventHandler handler : element.getEventHandlers()) { - handler.reset(event.getIteration()); - } - for (EventHandler handler : element.getResource().getEventHandlers()) { - handler.reset(event.getIteration()); - } - } - } - } - } @Override @@ -184,17 +157,14 @@ public void notifyAfterMobsim(AfterMobsimEvent event) { if (!alreadyUpdatedTrackers.contains(tracker)) { tracker.notifyAfterMobsim(event); alreadyUpdatedTrackers.add(tracker); - tracker.reset(); } } for (SimulationTracker tracker : element.getSimulationTrackers()) { tracker.notifyAfterMobsim(event); - tracker.reset(); } } for (SimulationTracker tracker : solution.getSimulationTrackers()) { tracker.notifyAfterMobsim(event); - tracker.reset(); } } } @@ -248,5 +218,45 @@ public void notifyStartup(StartupEvent event) { public CarrierResourceTracker getCarrierResourceTracker() { return carrierResourceTracker; } + + + @Override + public void notifyIterationStarts(IterationStartsEvent event) { + if(event.getIteration() > 0) { + for(EventHandler handler : registeredHandlers) { + eventsManager.removeHandler(handler); + } + + for(LSP lsp : lsps.getLSPs().values()) { + for(LSPShipment shipment : lsp.getShipments()) { + shipment.getEventHandlers().clear(); + } + + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(EventHandler handler : solution.getEventHandlers()) { + handler.reset(event.getIteration()); + } + for(SimulationTracker tracker : solution.getSimulationTrackers()) { + tracker.reset(); + } + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(EventHandler handler : element.getEventHandlers()) { + handler.reset(event.getIteration()); + } + for(SimulationTracker tracker : element.getSimulationTrackers()) { + tracker.reset(); + } + for(EventHandler handler : element.getResource().getEventHandlers()) { + handler.reset(event.getIteration()); + } + for(SimulationTracker tracker : element.getResource().getSimulationTrackers()) { + tracker.reset(); + } + } + } + } + } + + } } diff --git a/src/demand/controler/SupplyClearer.java b/src/demand/controler/SupplyClearer.java index e8ab441cebb..88086ff4a4a 100644 --- a/src/demand/controler/SupplyClearer.java +++ b/src/demand/controler/SupplyClearer.java @@ -7,6 +7,7 @@ import lsp.LSP; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; +import lsp.shipment.LSPShipment; public class SupplyClearer implements IterationEndsListener{ @@ -27,6 +28,13 @@ public void notifyIterationEnds(IterationEndsEvent arg0) { element.getOutgoingShipments().clear(); } } + + for(LSPShipment shipment : lsp.getShipments()) { + shipment.getSchedule().clear(); + shipment.getLog().clear(); + lsp.getSelectedPlan().getAssigner().assignShipment(shipment); + } + } } diff --git a/test/cascadingInfoTest/AverageTimeInfo.java b/test/cascadingInfoTest/AverageTimeInfo.java index df264828ba1..9431917e5ca 100644 --- a/test/cascadingInfoTest/AverageTimeInfo.java +++ b/test/cascadingInfoTest/AverageTimeInfo.java @@ -2,19 +2,22 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; public class AverageTimeInfo extends Info{ - private AverageTimeInfoFunction function; - + private InfoFunction function; + private String name = "averageTime"; + public AverageTimeInfo() { function = new AverageTimeInfoFunction(); - } - + } @Override public String getName() { - return "averageTime"; + return name; } @Override @@ -36,8 +39,17 @@ public double getToTime() { public void update() { Info preInfo = predecessorInfos.iterator().next(); AverageTimeInfo avgInfo = (AverageTimeInfo)preInfo; - AverageTimeInfoFunctionValue avgVal = (AverageTimeInfoFunctionValue) avgInfo.getFunction().getValues().iterator().next(); - function.getValues().iterator().next().setValue(avgVal.getValue()); + InfoFunctionValue infoVal = avgInfo.getFunction().getValues().iterator().next(); + if( infoVal.getValue() instanceof Double) { + if(function.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue) { + AverageTimeInfoFunctionValue avgVal = (AverageTimeInfoFunctionValue) function.getValues().iterator().next(); + avgVal.setValue((Double)infoVal.getValue()); + } + } } + @Override + public void setName(String name) { + this.name = name; + } } diff --git a/test/cascadingInfoTest/AverageTimeInfoFunction.java b/test/cascadingInfoTest/AverageTimeInfoFunction.java index ff87b337f59..fb3a95fe65b 100644 --- a/test/cascadingInfoTest/AverageTimeInfoFunction.java +++ b/test/cascadingInfoTest/AverageTimeInfoFunction.java @@ -10,15 +10,15 @@ public class AverageTimeInfoFunction implements InfoFunction{ - private Collection values; + private Collection> values; public AverageTimeInfoFunction() { - values = new ArrayList(); + values = new ArrayList>(); values.add(new AverageTimeInfoFunctionValue()); } @Override - public Collection getValues() { + public Collection> getValues() { return values; } diff --git a/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java b/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java index 40a3d7d98ca..9136b623161 100644 --- a/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java +++ b/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java @@ -2,27 +2,22 @@ import lsp.functions.InfoFunctionValue; -public class AverageTimeInfoFunctionValue implements InfoFunctionValue{ +public class AverageTimeInfoFunctionValue implements InfoFunctionValue{ - private String value; + private Double value; @Override public String getName() { - return "agerageTimeInSeconds"; + return "averageTimeInSeconds"; } - + @Override - public Class getDataType() { - return Double.class; + public void setValue(Double value) { + this.value = value; } @Override - public String getValue() { + public Double getValue() { return value; } - - @Override - public void setValue(String value) { - this.value = value; - } } diff --git a/test/cascadingInfoTest/AverageTimeTracker.java b/test/cascadingInfoTest/AverageTimeTracker.java index ed00fcc17f0..a3708bc0e4d 100644 --- a/test/cascadingInfoTest/AverageTimeTracker.java +++ b/test/cascadingInfoTest/AverageTimeTracker.java @@ -44,7 +44,7 @@ public void notifyAfterMobsim(AfterMobsimEvent event) { double totalTransportTime = handler.getTotalTime(); double averageTransportTime = totalTransportTime/numberOfStops; AverageTimeInfoFunctionValue value = (AverageTimeInfoFunctionValue) timeInfo.getFunction().getValues().iterator().next(); - value.setValue(Double.toString(averageTransportTime)); + value.setValue(averageTransportTime); } diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java index 7e5e996e1c6..32cb24b7523 100644 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -201,13 +201,13 @@ public void testCascadingInfos() { assertTrue(averageElementFunction.getValues().size() == 1); assertTrue(averageElementFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); AverageTimeInfoFunctionValue averageElementValue = (AverageTimeInfoFunctionValue) averageElementFunction.getValues().iterator().next(); - assertTrue(Double.parseDouble(averageElementValue.getValue()) > 0); + assertTrue(averageElementFunction.getValues().iterator().next().getValue() instanceof Double); assertTrue(elementInfo.getFunction() instanceof AverageTimeInfoFunction); AverageTimeInfoFunction averageSolutionFunction = (AverageTimeInfoFunction) solutionInfo.getFunction(); assertTrue(averageSolutionFunction.getValues().size() == 1); assertTrue(averageSolutionFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); AverageTimeInfoFunctionValue averageSolutionValue = (AverageTimeInfoFunctionValue) averageSolutionFunction.getValues().iterator().next(); - assertTrue(Double.parseDouble(averageSolutionValue.getValue()) > 0); + assertTrue(averageSolutionValue.getValue() > 0); assertTrue(averageElementValue.getValue() == averageSolutionValue.getValue()); } diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java index f3cff2ecb81..01b63489b57 100644 --- a/test/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -173,7 +173,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(2); + config.controler().setLastIteration(10); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); diff --git a/test/lspReplanningTests/CollectionLSPReplanningTest.java b/test/lspReplanningTests/CollectionLSPReplanningTest.java index 3ac15215ab4..162a43d8665 100644 --- a/test/lspReplanningTests/CollectionLSPReplanningTest.java +++ b/test/lspReplanningTests/CollectionLSPReplanningTest.java @@ -48,16 +48,9 @@ import lsp.resources.Resource; import lsp.replanning.LSPReplannerImpl; import lsp.replanning.LSPReplanningModuleImpl; -import lsp.scoring.LSPScorer; import lsp.scoring.LSPScoringModuleImpl; import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; -import lspScoringTests.TrinkgeldEventHandler; -import lspScoringTests.TrinkgeldInfo; -import lspScoringTests.TrinkgeldInfoFunction; -import lspScoringTests.TrinkgeldInfoFunctionValue; -import lspScoringTests.TrinkgeldScorer; -import lspScoringTests.TrinkgeldSimulationTracker; public class CollectionLSPReplanningTest { private Network network; diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java index 2ddc63e1416..73ec7f187fa 100644 --- a/test/lspScoringTests/CollectionLSPScoringTest.java +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -33,6 +33,10 @@ import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.controler.LSPModule; import lsp.events.EventUtils; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -58,11 +62,11 @@ public class CollectionLSPScoringTest { private Carrier carrier; private Resource collectionAdapter; private LogisticsSolutionElement collectionElement; - private LSPScorer trinkgeldScorer; - private TrinkgeldSimulationTracker trinkgeldTracker; - private TrinkgeldInfo info; - private TrinkgeldInfoFunction function; - private TrinkgeldInfoFunctionValue value; + private LSPScorer tipScorer; + private TipSimulationTracker tipTracker; + private TipInfo info; + private InfoFunction function; + private InfoFunctionValue value; private int numberOfShipments = 25; @Before @@ -136,15 +140,15 @@ public void initialize() { collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); - TrinkgeldEventHandler handler = new TrinkgeldEventHandler(); - TrinkgeldInfoFunctionValue value = new TrinkgeldInfoFunctionValue(); - function = new TrinkgeldInfoFunction(); + TipEventHandler handler = new TipEventHandler(); + value = new InfoFunctionValueImpl("TIP IN EUR"); + function = new InfoFunctionImpl(); function.getValues().add(value); - info = new TrinkgeldInfo(function); - trinkgeldTracker = new TrinkgeldSimulationTracker(handler,info); - collectionAdapter.addSimulationTracker(trinkgeldTracker); - trinkgeldScorer = new TrinkgeldScorer(collectionLSP, trinkgeldTracker); - collectionLSP.setScorer(trinkgeldScorer); + info = new TipInfo(function); + tipTracker = new TipSimulationTracker(handler,info); + collectionAdapter.addSimulationTracker(tipTracker); + tipScorer = new TipScorer(collectionLSP, tipTracker); + collectionLSP.setScorer(tipScorer); ArrayList linkList = new ArrayList(network.getLinks().values()); Id toLinkId = collectionLinkId; @@ -191,7 +195,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(25); + config.controler().setLastIteration(1); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -202,7 +206,7 @@ public void testCollectionLSPScoring() { System.out.println(collectionLSP.getSelectedPlan().getScore()); assertTrue(collectionLSP.getShipments().size() == numberOfShipments); assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() == numberOfShipments); - assertTrue(collectionLSP.getSelectedPlan().getScore() >0); + assertTrue(collectionLSP.getSelectedPlan().getScore() > 0); assertTrue(collectionLSP.getSelectedPlan().getScore() <=(numberOfShipments*5)); } diff --git a/test/lspScoringTests/TipEventHandler.java b/test/lspScoringTests/TipEventHandler.java new file mode 100644 index 00000000000..8110ad33c1d --- /dev/null +++ b/test/lspScoringTests/TipEventHandler.java @@ -0,0 +1,35 @@ +package lspScoringTests; + +import java.util.Random; + +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; + +public class TipEventHandler implements ServiceEndEventHandler{ + + private double tipSum; + private Random tipRandom; + + public TipEventHandler() { + tipRandom = new Random(1); + tipSum = 0; + } + + @Override + public void reset(int iteration) { + tipSum = 0; + } + + @Override + public void handleEvent(ServiceEndEvent event) { + double tip = tipRandom.nextDouble() * 5; + System.out.println("ServiceEvent " + tip); + tipSum += tip; + } + + public double getTip() { + return tipSum; + } +} diff --git a/test/lspScoringTests/TrinkgeldInfo.java b/test/lspScoringTests/TipInfo.java similarity index 62% rename from test/lspScoringTests/TrinkgeldInfo.java rename to test/lspScoringTests/TipInfo.java index a51c01ac01e..44d8686affd 100644 --- a/test/lspScoringTests/TrinkgeldInfo.java +++ b/test/lspScoringTests/TipInfo.java @@ -3,12 +3,12 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; -public class TrinkgeldInfo extends Info{ +public class TipInfo extends Info{ - private TrinkgeldInfoFunction function; - private String name = "TRINKGELDINFO"; + private InfoFunction function; + private String name = "TIPINFO"; - public TrinkgeldInfo (TrinkgeldInfoFunction function) { + public TipInfo (InfoFunction function) { this.function = function; } @@ -38,4 +38,10 @@ public void update() { } + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/test/lspScoringTests/TrinkgeldScorer.java b/test/lspScoringTests/TipScorer.java similarity index 50% rename from test/lspScoringTests/TrinkgeldScorer.java rename to test/lspScoringTests/TipScorer.java index 75c569d1b0f..9017370751b 100644 --- a/test/lspScoringTests/TrinkgeldScorer.java +++ b/test/lspScoringTests/TipScorer.java @@ -1,19 +1,17 @@ package lspScoringTests; -import org.matsim.api.core.v01.population.HasPlansAndId; - import lsp.LSP; import lsp.functions.Info; import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionValue; import lsp.scoring.LSPScorer; -public class TrinkgeldScorer implements LSPScorer { +public class TipScorer implements LSPScorer { private LSP lsp; - private TrinkgeldSimulationTracker tracker; + private TipSimulationTracker tracker; - public TrinkgeldScorer(LSP lsp, TrinkgeldSimulationTracker tracker) { + public TipScorer(LSP lsp, TipSimulationTracker tracker) { this.lsp = lsp; this.tracker = tracker; } @@ -22,12 +20,12 @@ public TrinkgeldScorer(LSP lsp, TrinkgeldSimulationTracker tracker) { public double scoreCurrentPlan(LSP lsp) { double score = 0; for(Info info : tracker.getInfos()) { - if(info.getName() == "TRINKGELDINFO") { + if(info.getName() == "TIPINFO") { InfoFunction function = info.getFunction(); - for(InfoFunctionValue value : function.getValues()) { - if(value.getName() == "TRINKGELD IN EUR") { - double trinkgeldValue = Double.parseDouble(value.getValue()); - score += trinkgeldValue; + for(InfoFunctionValue value : function.getValues()) { + if(value.getName() == "TIP IN EUR" && value.getValue() instanceof Double) { + double tipValue = (Double)value.getValue(); + score += tipValue; } } } diff --git a/test/lspScoringTests/TrinkgeldSimulationTracker.java b/test/lspScoringTests/TipSimulationTracker.java similarity index 63% rename from test/lspScoringTests/TrinkgeldSimulationTracker.java rename to test/lspScoringTests/TipSimulationTracker.java index 5d8241ec8af..5185bc689a0 100644 --- a/test/lspScoringTests/TrinkgeldSimulationTracker.java +++ b/test/lspScoringTests/TipSimulationTracker.java @@ -8,14 +8,15 @@ import lsp.functions.Info; import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; import lsp.tracking.SimulationTracker; -public class TrinkgeldSimulationTracker implements SimulationTracker { +public class TipSimulationTracker implements SimulationTracker { - private TrinkgeldEventHandler handler; - private Info info; + private TipEventHandler handler; + private TipInfo info; - public TrinkgeldSimulationTracker(TrinkgeldEventHandler handler, Info info) { + public TipSimulationTracker(TipEventHandler handler, TipInfo info) { this.info = info; this.handler = handler; } @@ -36,9 +37,10 @@ public Collection getInfos() { @Override public void notifyAfterMobsim(AfterMobsimEvent event) { - double trinkgeld = handler.getTrinkgeld(); - InfoFunctionValue value = info.getFunction().getValues().iterator().next(); - value.setValue(String.valueOf(trinkgeld)); + double tip = handler.getTip(); + InfoFunctionValue value = new InfoFunctionValueImpl("TIP IN EUR"); + value.setValue(tip); + info.getFunction().getValues().add(value); } @Override diff --git a/test/lspScoringTests/TrinkgeldEventHandler.java b/test/lspScoringTests/TrinkgeldEventHandler.java deleted file mode 100644 index 2d81845abbb..00000000000 --- a/test/lspScoringTests/TrinkgeldEventHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -package lspScoringTests; - -import java.util.Random; - -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; -import lsp.events.ServiceEndEvent; -import lsp.events.ServiceEndEventHandler; - -public class TrinkgeldEventHandler implements ServiceEndEventHandler{ - - private double trinkgeldSum; - private Random trinkgeldRandom; - - public TrinkgeldEventHandler() { - trinkgeldRandom = new Random(1); - trinkgeldSum = 0; - } - - @Override - public void reset(int iteration) { - trinkgeldSum = 0; - } - - @Override - public void handleEvent(ServiceEndEvent event) { - double trinkgeld = trinkgeldRandom.nextDouble() * 5; - System.out.println("ServiceEvent " + trinkgeld); - trinkgeldSum += trinkgeld; - } - - public double getTrinkgeld() { - return trinkgeldSum; - } -} diff --git a/test/lspScoringTests/TrinkgeldInfoFunction.java b/test/lspScoringTests/TrinkgeldInfoFunction.java deleted file mode 100644 index 720b8f3e460..00000000000 --- a/test/lspScoringTests/TrinkgeldInfoFunction.java +++ /dev/null @@ -1,23 +0,0 @@ -package lspScoringTests; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; - -public class TrinkgeldInfoFunction implements InfoFunction{ - - private Collection values; - - public TrinkgeldInfoFunction() { - this.values = new ArrayList(); - } - - - @Override - public Collection getValues() { - return values; - } - -} diff --git a/test/lspScoringTests/TrinkgeldInfoFunctionValue.java b/test/lspScoringTests/TrinkgeldInfoFunctionValue.java deleted file mode 100644 index b15c3d680eb..00000000000 --- a/test/lspScoringTests/TrinkgeldInfoFunctionValue.java +++ /dev/null @@ -1,35 +0,0 @@ -package lspScoringTests; - -import lsp.functions.InfoFunctionValue; - -public class TrinkgeldInfoFunctionValue implements InfoFunctionValue{ - - private String name = "TRINKGELD IN EUR"; - private Class type; - private double value; - - public TrinkgeldInfoFunctionValue() { - this.type = double.class; - } - - @Override - public String getName() { - return name; - } - - @Override - public Class getDataType() { - return type; - } - - @Override - public String getValue() { - return String.valueOf(value); - } - - @Override - public void setValue(String value) { - this.value = Double.valueOf(value).doubleValue(); - } - -} diff --git a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java index ad922d67c58..a6f699a819f 100644 --- a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java +++ b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java @@ -310,7 +310,7 @@ public void testCollectionLSPShipmentAssignment() { assertTrue(solution.getShipments().size() == 10); for(LogisticsSolutionElement element : solution.getSolutionElements()) { if(element.getPreviousElement() == null) { - assertTrue(element.getIncomingShipments().getShipments().size() == 10); + //assertTrue(element.getIncomingShipments().getShipments().size() == 10); } } } diff --git a/test/requirementsCheckerTests/BlueInfo.java b/test/requirementsCheckerTests/BlueInfo.java index ecdf8dcb16e..1436a6582c2 100644 --- a/test/requirementsCheckerTests/BlueInfo.java +++ b/test/requirementsCheckerTests/BlueInfo.java @@ -3,6 +3,8 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; public class BlueInfo extends Info{ @@ -10,7 +12,9 @@ public class BlueInfo extends Info{ public BlueInfo() { blueInfoFunction = new InfoFunctionImpl(); - blueInfoFunction.getValues().add(new BlueInfoFunctionValue()); + InfoFunctionValue value = new InfoFunctionValueImpl("blue"); + value.setValue("blue"); + blueInfoFunction.getValues().add(value); } @Override @@ -41,4 +45,10 @@ public void update() { } + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/test/requirementsCheckerTests/BlueInfoFunctionValue.java b/test/requirementsCheckerTests/BlueInfoFunctionValue.java deleted file mode 100644 index 309e346122e..00000000000 --- a/test/requirementsCheckerTests/BlueInfoFunctionValue.java +++ /dev/null @@ -1,30 +0,0 @@ -package requirementsCheckerTests; - -import java.awt.Color; - -import lsp.functions.InfoFunctionValue; - -public class BlueInfoFunctionValue implements InfoFunctionValue{ - - @Override - public String getName() { - return "blue"; - } - - @Override - public Class getDataType() { - return Color.class; - } - - @Override - public String getValue() { - return "blue"; - } - - @Override - public void setValue(String value) { - // TODO Auto-generated method stub - - } - -} diff --git a/test/requirementsCheckerTests/RedInfo.java b/test/requirementsCheckerTests/RedInfo.java index 45dd88830bb..442e87c950b 100644 --- a/test/requirementsCheckerTests/RedInfo.java +++ b/test/requirementsCheckerTests/RedInfo.java @@ -3,6 +3,8 @@ import lsp.functions.Info; import lsp.functions.InfoFunction; import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; public class RedInfo extends Info{ @@ -10,7 +12,9 @@ public class RedInfo extends Info{ public RedInfo() { redInfoFunction = new InfoFunctionImpl(); - redInfoFunction.getValues().add(new RedInfoFunctionValue()); + InfoFunctionValue value = new InfoFunctionValueImpl("red"); + value.setValue("red"); + redInfoFunction.getValues().add(value); } @Override @@ -41,4 +45,10 @@ public void update() { } + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/test/requirementsCheckerTests/RedInfoFunctionValue.java b/test/requirementsCheckerTests/RedInfoFunctionValue.java deleted file mode 100644 index 1d1c8acbd13..00000000000 --- a/test/requirementsCheckerTests/RedInfoFunctionValue.java +++ /dev/null @@ -1,30 +0,0 @@ -package requirementsCheckerTests; - -import java.awt.Color; - -import lsp.functions.InfoFunctionValue; - -public class RedInfoFunctionValue implements InfoFunctionValue{ - - @Override - public String getName() { - return "red"; - } - - @Override - public Class getDataType() { - return Color.class; - } - - @Override - public String getValue() { - return "red"; - } - - @Override - public void setValue(String value) { - // TODO Auto-generated method stub - - } - -} diff --git a/test/testLSPWithCostTracker/CollectionTrackerTest.java b/test/testLSPWithCostTracker/CollectionTrackerTest.java index fbb1e4ea03c..6cdffcdcbfc 100644 --- a/test/testLSPWithCostTracker/CollectionTrackerTest.java +++ b/test/testLSPWithCostTracker/CollectionTrackerTest.java @@ -311,17 +311,17 @@ public void testCollectionTracker() { CostInfo costInfo = (CostInfo) info; assertTrue(costInfo.getFunction() instanceof CostInfoFunction); CostInfoFunction function = (CostInfoFunction) costInfo.getFunction(); - ArrayList values = new ArrayList(function.getValues()); - for(InfoFunctionValue value : values) { + ArrayList> values = new ArrayList>(function.getValues()); + for(InfoFunctionValue value : values) { if(value instanceof LinearCostFunctionValue) { LinearCostFunctionValue linearValue = (LinearCostFunctionValue) value; - assertEquals(Double.parseDouble(linearValue.getValue()),linearTrackedCostsPerShipment, Math.max(linearTrackedCostsPerShipment,Double.parseDouble(linearValue.getValue())) * 0.01 ); - assertEquals(Double.parseDouble(linearValue.getValue()),linearScheduledCostsPerShipment, Math.max(linearScheduledCostsPerShipment,Double.parseDouble(linearValue.getValue())) * 0.01 ); + assertEquals(linearValue.getValue(),linearTrackedCostsPerShipment, Math.max(linearTrackedCostsPerShipment,linearValue.getValue()) * 0.01 ); + assertEquals(linearValue.getValue(),linearScheduledCostsPerShipment, Math.max(linearScheduledCostsPerShipment,linearValue.getValue()) * 0.01 ); } if(value instanceof FixedCostFunctionValue) { FixedCostFunctionValue fixedValue = (FixedCostFunctionValue) value; - assertEquals(Double.parseDouble(fixedValue.getValue()),fixedTrackedCostsPerShipment, Math.max(fixedTrackedCostsPerShipment,Double.parseDouble(fixedValue.getValue())) * 0.01 ); - assertEquals(Double.parseDouble(fixedValue.getValue()),fixedScheduledCostsPerShipment, Math.max(fixedScheduledCostsPerShipment,Double.parseDouble(fixedValue.getValue())) * 0.01 ); + assertEquals(fixedValue.getValue(),fixedTrackedCostsPerShipment, Math.max(fixedTrackedCostsPerShipment,fixedValue.getValue()) * 0.01 ); + assertEquals(fixedValue.getValue(),fixedScheduledCostsPerShipment, Math.max(fixedScheduledCostsPerShipment,fixedValue.getValue()) * 0.01 ); } } } diff --git a/test/testLSPWithCostTracker/CostInfo.java b/test/testLSPWithCostTracker/CostInfo.java index d454d8aff25..60e47764d1f 100644 --- a/test/testLSPWithCostTracker/CostInfo.java +++ b/test/testLSPWithCostTracker/CostInfo.java @@ -39,4 +39,11 @@ public void update() { } + + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/test/testLSPWithCostTracker/CostInfoFunction.java b/test/testLSPWithCostTracker/CostInfoFunction.java index a4b2ca1b0c8..25978420268 100644 --- a/test/testLSPWithCostTracker/CostInfoFunction.java +++ b/test/testLSPWithCostTracker/CostInfoFunction.java @@ -12,10 +12,10 @@ public class CostInfoFunction implements InfoFunction { private FixedCostFunctionValue fixedValue; private LinearCostFunctionValue linearValue; - private Collection values; + private Collection> values; public CostInfoFunction() { - values = new ArrayList(); + values = new ArrayList>(); fixedValue = new FixedCostFunctionValue(); linearValue = new LinearCostFunctionValue(); values.add(fixedValue); @@ -24,7 +24,7 @@ public CostInfoFunction() { } @Override - public Collection getValues() { + public Collection> getValues() { return values; } diff --git a/test/testLSPWithCostTracker/FixedCostFunctionValue.java b/test/testLSPWithCostTracker/FixedCostFunctionValue.java index 64241f60723..e6b2b0998af 100644 --- a/test/testLSPWithCostTracker/FixedCostFunctionValue.java +++ b/test/testLSPWithCostTracker/FixedCostFunctionValue.java @@ -2,28 +2,23 @@ import lsp.functions.InfoFunctionValue; -public class FixedCostFunctionValue implements InfoFunctionValue { +public class FixedCostFunctionValue implements InfoFunctionValue { + + private double value; - private String value; - @Override public String getName() { return "fixed"; } @Override - public Class getDataType() { - return Double.class; - } - - @Override - public String getValue() { + public Double getValue() { return value; } @Override - public void setValue(String value) { - this.value = value; + public void setValue(Double value) { + this.value = value; } - + } diff --git a/test/testLSPWithCostTracker/LinearCostFunctionValue.java b/test/testLSPWithCostTracker/LinearCostFunctionValue.java index 81cccb79dff..8a151b0e258 100644 --- a/test/testLSPWithCostTracker/LinearCostFunctionValue.java +++ b/test/testLSPWithCostTracker/LinearCostFunctionValue.java @@ -2,28 +2,22 @@ import lsp.functions.InfoFunctionValue; -public class LinearCostFunctionValue implements InfoFunctionValue { +public class LinearCostFunctionValue implements InfoFunctionValue { + + private Double value; - private String value; - @Override public String getName() { return "linear"; } @Override - public Class getDataType() { - return Double.class; - } - - @Override - public String getValue() { + public Double getValue() { return value; } @Override - public void setValue(String value) { + public void setValue(Double value) { this.value = value; } - } diff --git a/test/testLSPWithCostTracker/LinearCostTracker.java b/test/testLSPWithCostTracker/LinearCostTracker.java index 711a37de951..f8b956be4b0 100644 --- a/test/testLSPWithCostTracker/LinearCostTracker.java +++ b/test/testLSPWithCostTracker/LinearCostTracker.java @@ -73,10 +73,10 @@ public void notifyAfterMobsim(AfterMobsimEvent event) { CostInfo info = (CostInfo) infos.iterator().next(); for(InfoFunctionValue value : info.getFunction().getValues()) { if(value instanceof FixedCostFunctionValue) { - ((FixedCostFunctionValue)value).setValue(Double.toString(fixedUnitCosts)); + ((FixedCostFunctionValue)value).setValue(fixedUnitCosts); } if(value instanceof LinearCostFunctionValue) { - ((LinearCostFunctionValue)value).setValue(Double.toString(linearUnitCosts)); + ((LinearCostFunctionValue)value).setValue(linearUnitCosts); } } diff --git a/test/testMutualReplanning/MutualReplanningTest.java b/test/testMutualReplanning/MutualReplanningTest.java index 67221556f01..59f2e51d31f 100644 --- a/test/testMutualReplanning/MutualReplanningTest.java +++ b/test/testMutualReplanning/MutualReplanningTest.java @@ -30,6 +30,7 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; +import demand.controler.MutualModule; import demand.decoratedLSP.LSPDecorator; import demand.decoratedLSP.LSPPlanDecorator; import demand.decoratedLSP.LSPPlanWithOfferTransferrer; @@ -45,7 +46,6 @@ import demand.demandObject.DemandPlanImpl; import demand.demandObject.ShipperShipment; import demand.demandObject.ShipperShipmentImpl; -import demand.mobsim.MutualModule; import demand.mutualReplanning.DemandPlanStrategyImpl; import demand.mutualReplanning.DemandReplannerImpl; import demand.mutualReplanning.MutualReplanningModule; @@ -60,6 +60,7 @@ import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.SolutionScheduler; +import lsp.events.EventUtils; import lsp.resources.Resource; import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; @@ -215,12 +216,13 @@ public void initialize(){ moduleBuilder.setLsps(new LSPDecorators(lsps)); moduleBuilder.setMutualReplanningModule(mutReplanModule); moduleBuilder.setMutualScoringModule(mutScoreModule); + moduleBuilder.setEventCreators(EventUtils.getStandardEventCreators()); MutualModule mutualModule = moduleBuilder.build(); Controler controler = new Controler(config); controler.addOverridingModule(mutualModule); config.controler().setFirstIteration(0); - config.controler().setLastIteration(1); + config.controler().setLastIteration(2); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); diff --git a/test/testMutualreplanningWithOfferUpdate/CostInfo.java b/test/testMutualreplanningWithOfferUpdate/CostInfo.java index f81982df75a..fe29814e611 100644 --- a/test/testMutualreplanningWithOfferUpdate/CostInfo.java +++ b/test/testMutualreplanningWithOfferUpdate/CostInfo.java @@ -39,4 +39,11 @@ public void update() { } + + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + } diff --git a/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java b/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java index 5f917bdf1e4..4c46792c88e 100644 --- a/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java +++ b/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java @@ -10,10 +10,10 @@ public class CostInfoFunction implements InfoFunction { private FixedCostFunctionValue fixedValue; private LinearCostFunctionValue linearValue; - private Collection values; + private Collection> values; public CostInfoFunction() { - values = new ArrayList(); + values = new ArrayList>(); fixedValue = new FixedCostFunctionValue(); linearValue = new LinearCostFunctionValue(); values.add(fixedValue); @@ -22,7 +22,7 @@ public CostInfoFunction() { } @Override - public Collection getValues() { + public Collection> getValues() { return values; } diff --git a/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java b/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java index 5f03fb25ff5..7961985596a 100644 --- a/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java +++ b/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java @@ -2,9 +2,9 @@ import lsp.functions.InfoFunctionValue; -public class FixedCostFunctionValue implements InfoFunctionValue { +public class FixedCostFunctionValue implements InfoFunctionValue { - private String value; + private Double value; @Override public String getName() { @@ -12,17 +12,12 @@ public String getName() { } @Override - public Class getDataType() { - return Double.class; - } - - @Override - public String getValue() { + public Double getValue() { return value; } @Override - public void setValue(String value) { + public void setValue(Double value) { this.value = value; } diff --git a/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java b/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java index 407e3108a34..cecf624b46c 100644 --- a/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java +++ b/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java @@ -2,9 +2,9 @@ import lsp.functions.InfoFunctionValue; -public class LinearCostFunctionValue implements InfoFunctionValue { +public class LinearCostFunctionValue implements InfoFunctionValue { - private String value; + private Double value; @Override public String getName() { @@ -12,17 +12,12 @@ public String getName() { } @Override - public Class getDataType() { - return Double.class; - } - - @Override - public String getValue() { + public Double getValue() { return value; } @Override - public void setValue(String value) { + public void setValue(Double value) { this.value = value; } diff --git a/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java b/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java index 92c65730858..3fc8f89833d 100644 --- a/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java +++ b/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java @@ -73,10 +73,10 @@ public void notifyAfterMobsim(AfterMobsimEvent event) { CostInfo info = (CostInfo) infos.iterator().next(); for(InfoFunctionValue value : info.getFunction().getValues()) { if(value instanceof FixedCostFunctionValue) { - ((FixedCostFunctionValue)value).setValue(Double.toString(fixedUnitCosts)); + ((FixedCostFunctionValue)value).setValue(fixedUnitCosts); } if(value instanceof LinearCostFunctionValue) { - ((LinearCostFunctionValue)value).setValue(Double.toString(linearUnitCosts)); + ((LinearCostFunctionValue)value).setValue(linearUnitCosts); } } diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOffer.java b/test/testMutualreplanningWithOfferUpdate/LinearOffer.java index fd5ab8938bb..79256a0b1c2 100644 --- a/test/testMutualreplanningWithOfferUpdate/LinearOffer.java +++ b/test/testMutualreplanningWithOfferUpdate/LinearOffer.java @@ -74,11 +74,11 @@ public void update() { for(InfoFunctionValue value : costFunction.getValues()) { if(value instanceof FixedCostFunctionValue) { fixedValue = (FixedCostFunctionValue) value; - this.fix = Double.parseDouble(fixedValue.getValue()); + this.fix = fixedValue.getValue(); } if(value instanceof LinearCostFunctionValue) { linearValue = (LinearCostFunctionValue) value; - this.linear = Double.parseDouble(linearValue.getValue()); + this.linear = linearValue.getValue(); } } } diff --git a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java index 126e0d1253c..fba815da97a 100644 --- a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java +++ b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java @@ -29,6 +29,7 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; +import demand.controler.MutualModule; import demand.decoratedLSP.LSPDecorator; import demand.decoratedLSP.LSPDecorators; import demand.decoratedLSP.LSPPlanDecorator; @@ -44,7 +45,6 @@ import demand.demandObject.DemandPlanImpl; import demand.demandObject.ShipperShipment; import demand.demandObject.ShipperShipmentImpl; -import demand.mobsim.MutualModule; import demand.mutualReplanning.DemandPlanStrategyImpl; import demand.mutualReplanning.DemandReplannerImpl; import demand.mutualReplanning.LSPWithOffersReplanner; @@ -64,6 +64,7 @@ import lsp.LogisticsSolutionElement; import lsp.LogisticsSolutionElementImpl; import lsp.SolutionScheduler; +import lsp.events.EventUtils; import lsp.resources.Resource; import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; @@ -76,11 +77,9 @@ public class MutualReplanningAndOfferUpdateTest { private LSPDecorator lsp; - private Collection demandObjects; private OfferFactoryImpl offerFactory; private LinearCostTracker tracker; private LinearOfferVisitor linearVisitor; - private LSPPlanDecorator collectionPlan; private LogisticsSolutionDecorator solution; private double initialFixed; private @@ -242,6 +241,7 @@ public void initialize() { moduleBuilder.setLsps(new LSPDecorators(lspList)); moduleBuilder.setMutualReplanningModule(mutReplanModule); moduleBuilder.setMutualScoringModule(mutScoreModule); + moduleBuilder.setEventCreators(EventUtils.getStandardEventCreators()); MutualModule mutualModule = moduleBuilder.build(); controler.addOverridingModule(mutualModule); From 677f18e0d86cc2ec4006c84ca653f2f1fb995a15 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Mon, 23 Apr 2018 17:03:56 +0200 Subject: [PATCH 0032/1340] Assertions in the test changed in order to reflect the fact that shipments are now assigned to the resources and solutionElements only before scheduling the solutions --- .../CollectionLSPShipmentAssigmentTest.java | 3 ++- .../CompleteLSPShipmentAssignerTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java index 7d193840064..89f0849c61f 100644 --- a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java +++ b/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java @@ -162,7 +162,8 @@ public void testCollectionLSPShipmentAssignment() { assertTrue(solution.getShipments().size() == 10); for(LogisticsSolutionElement element : solution.getSolutionElements()) { if(element.getPreviousElement() == null) { - assertTrue(element.getIncomingShipments().getShipments().size() == 10); + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); } } } diff --git a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java index a6f699a819f..935b318eab1 100644 --- a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java +++ b/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java @@ -310,7 +310,8 @@ public void testCollectionLSPShipmentAssignment() { assertTrue(solution.getShipments().size() == 10); for(LogisticsSolutionElement element : solution.getSolutionElements()) { if(element.getPreviousElement() == null) { - //assertTrue(element.getIncomingShipments().getShipments().size() == 10); + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); } } } From 226a2b5a01cdfa1e57408bad005f6a6cba318259 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 24 Apr 2018 11:05:28 +0200 Subject: [PATCH 0033/1340] Refined tests in order to enable automatic testing with test suite --- test/cascadingInfoTest/CascadingInfoTest.java | 22 ++- .../CollectionLSPMobsimTest.java | 4 +- .../lspMobsimTests/CompleteLSPMobsimTest.java | 2 +- test/lspPlanTests/CollectionLSPPlanTest.java | 1 + test/lspPlanTests/CompleteLSPPlanTest.java | 1 + .../CollectionLSPSchedulingTest.java | 19 ++- .../CompleteLSPSchedulingTest.java | 2 - .../FirstReloadLSPSchedulingTest.java | 134 ++++++++++++++++-- .../MainRunLSPSchedulingTest.java | 5 +- ...ava => CollectionShipmentBuilderTest.java} | 2 +- ....java => CompleteShipmentBuilderTest.java} | 2 +- ...a => DistributionShipmentBuilderTest.java} | 2 +- ...est.java => AssignerRequirementsTest.java} | 2 +- ....java => TransferrerRequirementsTest.java} | 2 +- test/testSuite/FTLabTestSuite.java | 96 +++++++++++++ 15 files changed, 262 insertions(+), 34 deletions(-) rename test/lspShipmentTest/{collectionShipmentBuilderTest.java => CollectionShipmentBuilderTest.java} (96%) rename test/lspShipmentTest/{completeShipmentBuilderTest.java => CompleteShipmentBuilderTest.java} (96%) rename test/lspShipmentTest/{distributionShipmentBuilderTest.java => DistributionShipmentBuilderTest.java} (96%) rename test/requirementsCheckerTests/{assignerRequirementsTest.java => AssignerRequirementsTest.java} (97%) rename test/requirementsCheckerTests/{transferrerRequirementsTest.java => TransferrerRequirementsTest.java} (97%) create mode 100644 test/testSuite/FTLabTestSuite.java diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java index 32cb24b7523..c567b88ad15 100644 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -60,6 +60,7 @@ public class CascadingInfoTest { private LogisticsSolution collectionSolution; private AverageTimeInfo elementInfo; private AverageTimeInfo solutionInfo; + private AverageTimeTracker timeTracker; @Before public void initialize() { @@ -83,9 +84,7 @@ public void initialize() { Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); Link collectionLink = network.getLinks().get(collectionLinkId); - if (collectionLink == null) { - System.exit(1); - } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); carrierVehicle.setVehicleType(collectionType); @@ -105,8 +104,8 @@ public void initialize() { adapterBuilder.setCarrier(carrier); adapterBuilder.setLocationLinkId(collectionLinkId); collectionAdapter = adapterBuilder.build(); - - collectionAdapter.addSimulationTracker(new AverageTimeTracker()); + timeTracker = new AverageTimeTracker(); + collectionAdapter.addSimulationTracker(timeTracker); Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); @@ -196,18 +195,29 @@ public void initialize() { @Test public void testCascadingInfos() { + assertTrue(timeTracker.getInfos().iterator().next() == elementInfo.getPredecessorInfos().iterator().next()); + assertTrue(timeTracker.getInfos().iterator().next() instanceof AverageTimeInfo); + AverageTimeInfo resourceInfo = (AverageTimeInfo) timeTracker.getInfos().iterator().next(); + assertTrue(resourceInfo.getFunction() instanceof AverageTimeInfoFunction); + AverageTimeInfoFunction resourceInfoFunction = (AverageTimeInfoFunction) resourceInfo.getFunction(); + assertTrue(resourceInfoFunction.getValues().size() == 1); + assertTrue(resourceInfoFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); + AverageTimeInfoFunctionValue averageResourceValue = (AverageTimeInfoFunctionValue) resourceInfoFunction.getValues().iterator().next(); assertTrue(elementInfo.getFunction() instanceof AverageTimeInfoFunction); AverageTimeInfoFunction averageElementFunction = (AverageTimeInfoFunction) elementInfo.getFunction(); assertTrue(averageElementFunction.getValues().size() == 1); assertTrue(averageElementFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); AverageTimeInfoFunctionValue averageElementValue = (AverageTimeInfoFunctionValue) averageElementFunction.getValues().iterator().next(); + assertTrue(averageElementValue.getValue() > 0); assertTrue(averageElementFunction.getValues().iterator().next().getValue() instanceof Double); - assertTrue(elementInfo.getFunction() instanceof AverageTimeInfoFunction); + assertTrue(solutionInfo.getFunction() instanceof AverageTimeInfoFunction); + assertTrue(solutionInfo.getPredecessorInfos().iterator().next() == elementInfo); AverageTimeInfoFunction averageSolutionFunction = (AverageTimeInfoFunction) solutionInfo.getFunction(); assertTrue(averageSolutionFunction.getValues().size() == 1); assertTrue(averageSolutionFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); AverageTimeInfoFunctionValue averageSolutionValue = (AverageTimeInfoFunctionValue) averageSolutionFunction.getValues().iterator().next(); assertTrue(averageSolutionValue.getValue() > 0); + assertTrue(averageElementValue.getValue() == averageResourceValue.getValue()); assertTrue(averageElementValue.getValue() == averageSolutionValue.getValue()); } diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java index 01b63489b57..21fabdd9982 100644 --- a/test/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -173,7 +173,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(10); + config.controler().setLastIteration(2); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -188,6 +188,8 @@ public void testCollectionLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/test/lspMobsimTests/CompleteLSPMobsimTest.java index e39b5f8c0e6..30c52971443 100644 --- a/test/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/test/lspMobsimTests/CompleteLSPMobsimTest.java @@ -325,7 +325,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(10); + config.controler().setLastIteration(2); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); diff --git a/test/lspPlanTests/CollectionLSPPlanTest.java b/test/lspPlanTests/CollectionLSPPlanTest.java index da7bd6f13ef..b04e4a1c162 100644 --- a/test/lspPlanTests/CollectionLSPPlanTest.java +++ b/test/lspPlanTests/CollectionLSPPlanTest.java @@ -101,6 +101,7 @@ public void collectionLSPPlanTest() { assertTrue(collectionPlan.getScore() == 0); assertTrue(collectionPlan.getLsp() == null); assertTrue(collectionPlan.getSolutions().size() == 1); + assertTrue(collectionPlan.getSolutions().iterator().next() == collectionSolution); } } diff --git a/test/lspPlanTests/CompleteLSPPlanTest.java b/test/lspPlanTests/CompleteLSPPlanTest.java index 5b8a347bc30..3570dc3fc58 100644 --- a/test/lspPlanTests/CompleteLSPPlanTest.java +++ b/test/lspPlanTests/CompleteLSPPlanTest.java @@ -232,6 +232,7 @@ public void testCompleteLSPPlan() { assertTrue(completePlan.getLsp() == null); assertTrue(completePlan.getScore() == 0); assertTrue(completePlan.getSolutions().size() ==1); + assertTrue(completePlan.getSolutions().iterator().next() == completeSolution); } } diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index 789c7ab4cea..e6f0d930d4c 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -193,6 +193,7 @@ public void testCollectionLSPScheduling() { assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); assertTrue(planElements.get(1).getEndTime() >= (0)); assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); assertTrue(planElements.get(1).getStartTime() >= (0)); assertTrue(planElements.get(1).getStartTime() <= (24*3600)); @@ -201,6 +202,7 @@ public void testCollectionLSPScheduling() { assertTrue(planElements.get(0).getElementType() == "LOAD"); assertTrue(planElements.get(0).getEndTime() >= (0)); assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); assertTrue(planElements.get(0).getStartTime() >= (0)); assertTrue(planElements.get(0).getStartTime() <= (24*3600)); @@ -209,25 +211,30 @@ public void testCollectionLSPScheduling() { assertTrue(shipment.getEventHandlers().size() == 2); ArrayList eventHandlers = new ArrayList(shipment.getEventHandlers()); + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(serviceHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(serviceHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); } } } diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index 94672294684..d5414d9a840 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -1,7 +1,5 @@ package lspSchedulingTests; -import static org.junit.Assert.*; - import java.util.ArrayList; import java.util.Collections; import java.util.Random; diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java index e76431f6f70..c2461ea5d7c 100644 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; +import java.util.Map.Entry; import java.util.Random; import org.junit.Before; @@ -16,11 +18,13 @@ import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierCapabilities; import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vehicles.Vehicle; @@ -28,14 +32,14 @@ import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.usecase.ReloadingPointEventHandler.ReloadingPointEventHandlerPair; import lsp.LSP; import lsp.LSPImpl; import lsp.LSPPlanImpl; @@ -58,8 +62,11 @@ public class FirstReloadLSPSchedulingTest { private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; - - + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private LogisticsSolutionElement collectionElement; + private Resource collectionAdapter; + @Before public void initialize() { Config config = new Config(); @@ -99,12 +106,12 @@ public void initialize() { collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); collectionAdapterBuilder.setCarrier(collectionCarrier); collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); + collectionAdapter = collectionAdapterBuilder.build(); Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); collectionBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionBuilder.build(); + collectionElement = collectionBuilder.build(); ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); @@ -116,12 +123,12 @@ public void initialize() { ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + firstReloadElement = firstReloadingElementBuilder.build(); collectionElement.setNextElement(firstReloadElement); firstReloadElement.setPreviousElement(collectionElement); @@ -212,5 +219,112 @@ public void testFirstReloadLSPScheduling() { } System.out.println(); } + + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 4); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + //This asserts that the shipments waiting for handling have been handled and the queues have been cleared + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 2); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == lsp.getResources().iterator().next().getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(serviceHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getResourceId() == lsp.getResources().iterator().next().getId()); + } } } diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java index 8798573ffcd..670072c95a0 100644 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -1,6 +1,5 @@ package lspSchedulingTests; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -29,8 +28,6 @@ import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; import lsp.usecase.MainRunCarrierAdapter; import lsp.usecase.MainRunCarrierScheduler; import lsp.usecase.ReloadingPoint; @@ -254,4 +251,6 @@ public void testMainRunLSPScheduling() { System.out.println(); } } + + } diff --git a/test/lspShipmentTest/collectionShipmentBuilderTest.java b/test/lspShipmentTest/CollectionShipmentBuilderTest.java similarity index 96% rename from test/lspShipmentTest/collectionShipmentBuilderTest.java rename to test/lspShipmentTest/CollectionShipmentBuilderTest.java index 3ae181f7c88..cab6178bded 100644 --- a/test/lspShipmentTest/collectionShipmentBuilderTest.java +++ b/test/lspShipmentTest/CollectionShipmentBuilderTest.java @@ -20,7 +20,7 @@ import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; -public class collectionShipmentBuilderTest { +public class CollectionShipmentBuilderTest { private Network network; private Id toLinkId; diff --git a/test/lspShipmentTest/completeShipmentBuilderTest.java b/test/lspShipmentTest/CompleteShipmentBuilderTest.java similarity index 96% rename from test/lspShipmentTest/completeShipmentBuilderTest.java rename to test/lspShipmentTest/CompleteShipmentBuilderTest.java index f1d771e61db..3386f8b3d4d 100644 --- a/test/lspShipmentTest/completeShipmentBuilderTest.java +++ b/test/lspShipmentTest/CompleteShipmentBuilderTest.java @@ -23,7 +23,7 @@ import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; -public class completeShipmentBuilderTest { +public class CompleteShipmentBuilderTest { private Network network; private ArrayList shipments; diff --git a/test/lspShipmentTest/distributionShipmentBuilderTest.java b/test/lspShipmentTest/DistributionShipmentBuilderTest.java similarity index 96% rename from test/lspShipmentTest/distributionShipmentBuilderTest.java rename to test/lspShipmentTest/DistributionShipmentBuilderTest.java index b2959ac3c71..2d08c411454 100644 --- a/test/lspShipmentTest/distributionShipmentBuilderTest.java +++ b/test/lspShipmentTest/DistributionShipmentBuilderTest.java @@ -22,7 +22,7 @@ import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; -public class distributionShipmentBuilderTest { +public class DistributionShipmentBuilderTest { private Network network; private Id fromLinkId; diff --git a/test/requirementsCheckerTests/assignerRequirementsTest.java b/test/requirementsCheckerTests/AssignerRequirementsTest.java similarity index 97% rename from test/requirementsCheckerTests/assignerRequirementsTest.java rename to test/requirementsCheckerTests/AssignerRequirementsTest.java index f875aaccaa9..f3223515b25 100644 --- a/test/requirementsCheckerTests/assignerRequirementsTest.java +++ b/test/requirementsCheckerTests/AssignerRequirementsTest.java @@ -43,7 +43,7 @@ import lsp.usecase.DeterministicShipmentAssigner; import lsp.usecase.SimpleForwardSolutionScheduler; -public class assignerRequirementsTest { +public class AssignerRequirementsTest { private Network network; private LogisticsSolution blueSolution; diff --git a/test/requirementsCheckerTests/transferrerRequirementsTest.java b/test/requirementsCheckerTests/TransferrerRequirementsTest.java similarity index 97% rename from test/requirementsCheckerTests/transferrerRequirementsTest.java rename to test/requirementsCheckerTests/TransferrerRequirementsTest.java index 9bf6c2eb76a..53ca42d61e8 100644 --- a/test/requirementsCheckerTests/transferrerRequirementsTest.java +++ b/test/requirementsCheckerTests/TransferrerRequirementsTest.java @@ -44,7 +44,7 @@ import lsp.usecase.CollectionCarrierScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; -public class transferrerRequirementsTest { +public class TransferrerRequirementsTest { private Network network; private LogisticsSolutionWithOffers blueOfferSolution; private LogisticsSolutionWithOffers redOfferSolution; diff --git a/test/testSuite/FTLabTestSuite.java b/test/testSuite/FTLabTestSuite.java new file mode 100644 index 00000000000..5a69bf732f9 --- /dev/null +++ b/test/testSuite/FTLabTestSuite.java @@ -0,0 +1,96 @@ +package testSuite; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import adapterTests.CollectionAdapterTest; +import adapterTests.DistributionAdapterTest; +import adapterTests.FirstReloadAdapterTest; +import adapterTests.MainRunAdapterTest; +import adapterTests.SecondReloadAdapterTest; +import cascadingInfoTest.CascadingInfoTest; +import demandObjectTests.DemandObjectBuilderTest; +import lspCreationTests.CollectionLSPCreationTest; +import lspCreationTests.CompleteLSPCreationTest; +import lspMobsimTests.CollectionLSPMobsimTest; +import lspMobsimTests.CompleteLSPMobsimTest; +import lspMobsimTests.FirstReloadLSPMobsimTest; +import lspMobsimTests.MainRunLSPMobsimTest; +import lspMobsimTests.MainRunOnlyLSPMobsimTest; +import lspMobsimTests.SecondReloadLSPMobsimTest; +import lspPlanTests.CollectionLSPPlanTest; +import lspPlanTests.CompleteLSPPlanTest; +import lspReplanningTests.CollectionLSPReplanningTest; +import lspSchedulingTests.CollectionLSPSchedulingTest; +import lspSchedulingTests.CompleteLSPSchedulingTest; +import lspSchedulingTests.FirstReloadLSPSchedulingTest; +import lspSchedulingTests.MainRunLSPSchedulingTest; +import lspSchedulingTests.SecondReloadLSPSchedulingTest; +import lspScoringTests.CollectionLSPScoringTest; +import lspShipmentAssignmentTests.CollectionLSPShipmentAssigmentTest; +import lspShipmentAssignmentTests.CompleteLSPShipmentAssignerTest; +import lspShipmentTest.CollectionShipmentBuilderTest; +import lspShipmentTest.CompleteShipmentBuilderTest; +import lspShipmentTest.DistributionShipmentBuilderTest; +import requirementsCheckerTests.AssignerRequirementsTest; +import requirementsCheckerTests.TransferrerRequirementsTest; +import solutionElementTests.CollectionElementTest; +import solutionElementTests.DistributionElementTest; +import solutionElementTests.FirstReloadElementTest; +import solutionElementTests.MainRunElementTest; +import solutionElementTests.SecondReloadElementTest; +import solutionTests.CollectionSolutionTest; +import solutionTests.CompleteSolutionTest; +import testLSPWithCostTracker.CollectionTrackerTest; +import testMutualReplanning.MutualReplanningTest; +import testMutualreplanningWithOfferUpdate.MutualReplanningAndOfferUpdateTest; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CollectionAdapterTest.class, + DistributionAdapterTest.class, + FirstReloadAdapterTest.class, + MainRunAdapterTest.class, + SecondReloadAdapterTest.class, + CascadingInfoTest.class, + DemandObjectBuilderTest.class, + CompleteLSPCreationTest.class, + CollectionLSPCreationTest.class, + CollectionLSPMobsimTest.class, + CompleteLSPMobsimTest.class, + FirstReloadLSPMobsimTest.class, + MainRunLSPMobsimTest.class, + MainRunOnlyLSPMobsimTest.class, + SecondReloadLSPMobsimTest.class, + CompleteLSPPlanTest.class, + CollectionLSPPlanTest.class, + CollectionLSPReplanningTest.class, + CollectionLSPSchedulingTest.class, + CompleteLSPSchedulingTest.class, + //FirstReloadLSPSchedulingTest.class, + MainRunLSPSchedulingTest.class, + SecondReloadLSPSchedulingTest.class, + CollectionLSPScoringTest.class, + CollectionShipmentBuilderTest.class, + CompleteShipmentBuilderTest.class, + DistributionShipmentBuilderTest.class, + AssignerRequirementsTest.class, + TransferrerRequirementsTest.class, + CollectionElementTest.class, + DistributionElementTest.class, + FirstReloadElementTest.class, + MainRunElementTest.class, + SecondReloadElementTest.class, + CompleteSolutionTest.class, + CollectionSolutionTest.class, + CollectionTrackerTest.class, + MutualReplanningTest.class, + MutualReplanningAndOfferUpdateTest.class, + CollectionLSPShipmentAssigmentTest.class, + CompleteLSPShipmentAssignerTest.class, + +}) + +public class FTLabTestSuite { + +} From c0e842ee1abd7c582191b8eb96013a82f131ce6d Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 24 Apr 2018 17:12:30 +0200 Subject: [PATCH 0034/1340] Extended tests in order to enable automatic testing with test suite --- .../FirstReloadLSPSchedulingTest.java | 3 +- .../MainRunLSPSchedulingTest.java | 246 ++++++++++++++++-- .../SecondReloadLSPSchedulingTest.java | 2 +- 3 files changed, 226 insertions(+), 25 deletions(-) diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java index c2461ea5d7c..ff9069c182c 100644 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -163,7 +163,8 @@ public void initialize() { for(int i = 1; i < 11; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(10); + //Random random = new Random(1); + int capacityDemand = new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java index 670072c95a0..bf8a88ef044 100644 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -1,11 +1,16 @@ package lspSchedulingTests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; +import java.util.Map.Entry; import java.util.Random; + import org.junit.Before; import org.junit.Test; import org.matsim.api.core.v01.Id; @@ -15,11 +20,13 @@ import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierCapabilities; import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vehicles.Vehicle; @@ -27,10 +34,15 @@ import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; import lsp.usecase.DeterministicShipmentAssigner; import lsp.usecase.MainRunCarrierAdapter; import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunEndEventHandler; +import lsp.usecase.MainRunStartEventHandler; import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; @@ -55,7 +67,17 @@ public class MainRunLSPSchedulingTest { private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; - + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Id collectionLinkId; + private Id firstReloadingLinkId; + private Id fromLinkId; + private Id toLinkId; + @Before public void initialize() { Config config = new Config(); @@ -63,7 +85,6 @@ public void initialize() { Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); this.network = scenario.getNetwork(); - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); @@ -76,7 +97,7 @@ public void initialize() { collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + collectionLinkId = Id.createLinkId("(4 2) (4 3)"); Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); collectionCarrierVehicle.setVehicleType(collectionType); @@ -89,35 +110,33 @@ public void initialize() { Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); collectionCarrier.setCarrierCapabilities(collectionCapabilities); - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); collectionAdapterBuilder.setCarrier(collectionCarrier); collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); + collectionAdapter = collectionAdapterBuilder.build(); Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); collectionBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionBuilder.build(); + collectionElement = collectionBuilder.build(); ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + firstReloadElement = firstReloadingElementBuilder.build(); Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); @@ -128,13 +147,13 @@ public void initialize() { mainRunVehicleTypeBuilder.setFixCost(120); mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + fromLinkId = Id.createLinkId("(4 2) (4 3)"); + toLinkId = Id.createLinkId("(14 2) (14 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); mainRunCarrierVehicle.setVehicleType(mainRunType); - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); mainRunCapabilitiesBuilder.addType(mainRunType); @@ -144,21 +163,19 @@ public void initialize() { Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); Id mainRunId = Id.create("MainRunAdapter", Resource.class); MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setFromLinkId(fromLinkId); + mainRunAdapterBuilder.setToLinkId(toLinkId); mainRunAdapterBuilder.setCarrier(mainRunCarrier); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); + mainRunAdapter = mainRunAdapterBuilder.build(); Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + mainRunElement = mainRunBuilder.build(); collectionElement.setNextElement(firstReloadElement); firstReloadElement.setPreviousElement(collectionElement); @@ -192,9 +209,10 @@ public void initialize() { ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); int capacityDemand = new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); @@ -237,6 +255,7 @@ public void initialize() { lsp.scheduleSoultions(); } + @Test public void testMainRunLSPScheduling() { @@ -250,7 +269,188 @@ public void testMainRunLSPScheduling() { } System.out.println(); } - } + + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 7); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + assertTrue(planElements.get(6).getElementType() == "UNLOAD"); + assertTrue(planElements.get(6).getEndTime() >= (0)); + assertTrue(planElements.get(6).getEndTime() <= (24*3600)); + assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(6).getStartTime() >= (0)); + assertTrue(planElements.get(6).getStartTime() <= (24*3600)); + assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); + + assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(5).getEndTime() >= (0)); + assertTrue(planElements.get(5).getEndTime() <= (24*3600)); + assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); + assertTrue(planElements.get(5).getStartTime() >= (0)); + assertTrue(planElements.get(5).getStartTime() <= (24*3600)); + assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); + + assertTrue(planElements.get(4).getElementType() == "LOAD"); + assertTrue(planElements.get(4).getEndTime() >= (0)); + assertTrue(planElements.get(4).getEndTime() <= (24*3600)); + assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); + assertTrue(planElements.get(4).getStartTime() >= (0)); + assertTrue(planElements.get(4).getStartTime() <= (24*3600)); + assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); + + assertEquals(planElements.get(4).getStartTime(), planElements.get(3).getEndTime() , 60 ); + + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + } + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 4); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); + ArrayList resources = new ArrayList<>(lsp.getResources()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == solutionElements.get(0)); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(serviceHandler.getElement() == solutionElements.get(0)); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); + MainRunStartEventHandler startHandler = (MainRunStartEventHandler) eventHandlers.get(2); + assertTrue(startHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(startHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(startHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(startHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(startHandler.getLspShipment() == shipment); + assertTrue(startHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(startHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(startHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(startHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); + MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); + assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(startHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(startHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(startHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(startHandler.getLspShipment() == shipment); + assertTrue(startHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(startHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(startHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(startHandler.getResource().getId() == resources.get(2).getId()); + } + + } } diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java index 399d622671d..4b03309cafc 100644 --- a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java @@ -218,7 +218,7 @@ public void initialize() { ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 11; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); int capacityDemand = new Random().nextInt(10); From d42440d102878162de3c6192919e7161640a2ab1 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 24 Apr 2018 17:14:25 +0200 Subject: [PATCH 0035/1340] Extended test cases to enable automatic testing with test suite. --- test/testSuite/FTLabTestSuite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testSuite/FTLabTestSuite.java b/test/testSuite/FTLabTestSuite.java index 5a69bf732f9..881a677f338 100644 --- a/test/testSuite/FTLabTestSuite.java +++ b/test/testSuite/FTLabTestSuite.java @@ -67,7 +67,7 @@ CollectionLSPReplanningTest.class, CollectionLSPSchedulingTest.class, CompleteLSPSchedulingTest.class, - //FirstReloadLSPSchedulingTest.class, + FirstReloadLSPSchedulingTest.class, MainRunLSPSchedulingTest.class, SecondReloadLSPSchedulingTest.class, CollectionLSPScoringTest.class, From 4a0fdbb76af849dc15345352dd08d955a46769fd Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 24 Apr 2018 20:08:57 +0200 Subject: [PATCH 0036/1340] Extended tests to enable automatic testing with test suite --- .../CollectionLSPSchedulingTest.java | 2 +- .../CompleteLSPSchedulingTest.java | 353 +++++++++- .../FirstReloadLSPSchedulingTest.java | 2 +- .../MainRunLSPSchedulingTest.java | 29 +- ...eShipmentsCollectionLSPSchedulingTest.java | 240 +++++++ ...pleShipmentsCompleteLSPSchedulingTest.java | 634 ++++++++++++++++++ ...ShipmentsFirstReloadLSPSchedulingTest.java | 331 +++++++++ ...ipleShipmentsMainRunLSPSchedulingTest.java | 455 +++++++++++++ ...hipmentsSecondReloadLSPSchedulingTest.java | 520 ++++++++++++++ .../SecondReloadLSPSchedulingTest.java | 265 +++++++- .../CollectionLSPScoringTest.java | 134 ++-- ...pleIterationsCollectionLSPScoringTest.java | 215 ++++++ test/testSuite/FTLabTestSuite.java | 13 +- 13 files changed, 3076 insertions(+), 117 deletions(-) create mode 100644 test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java create mode 100644 test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java create mode 100644 test/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index e6f0d930d4c..6bd6e5b1568 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -133,7 +133,7 @@ public void initialize() { Id toLinkId = collectionLinkId; - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); Random random = new Random(1); diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index d5414d9a840..0e6b8e6260a 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -1,8 +1,13 @@ package lspSchedulingTests; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.Random; +import java.util.Map.Entry; import org.junit.Before; import org.junit.Test; @@ -13,11 +18,13 @@ import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierCapabilities; import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vehicles.Vehicle; @@ -25,12 +32,19 @@ import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; import lsp.usecase.DeterministicShipmentAssigner; import lsp.usecase.DistributionCarrierAdapter; import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.DistributionServiceEventHandler; +import lsp.usecase.DistributionStartEventHandler; import lsp.usecase.MainRunCarrierAdapter; import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunEndEventHandler; +import lsp.usecase.MainRunStartEventHandler; import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; @@ -55,10 +69,19 @@ public class CompleteLSPSchedulingTest { private ShipmentAssigner assigner; private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; - private LSP completeLSP; - private Resource completeAdapter; - private LogisticsSolutionElement completeElement; - + private LSP lsp; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Resource secondReloadingPointAdapter; + private LogisticsSolutionElement secondReloadElement; + private Resource distributionAdapter; + private LogisticsSolutionElement distributionElement; + private Id toLinkId; + @Before public void initialize() { Config config = new Config(); @@ -97,12 +120,12 @@ public void initialize() { collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); collectionAdapterBuilder.setCarrier(collectionCarrier); collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); + collectionAdapter = collectionAdapterBuilder.build(); Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); collectionBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionBuilder.build(); + collectionElement = collectionBuilder.build(); ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); @@ -114,12 +137,12 @@ public void initialize() { ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + firstReloadElement = firstReloadingElementBuilder.build(); Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); @@ -133,6 +156,7 @@ public void initialize() { Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + toLinkId = Id.createLinkId("(14 2) (14 3)"); Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); mainRunCarrierVehicle.setVehicleType(mainRunType); @@ -152,15 +176,15 @@ public void initialize() { Id mainRunId = Id.create("MainRunAdapter", Resource.class); MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setFromLinkId(fromLinkId); + mainRunAdapterBuilder.setToLinkId(toLinkId); mainRunAdapterBuilder.setCarrier(mainRunCarrier); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); + mainRunAdapter = mainRunAdapterBuilder.build(); Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + mainRunElement = mainRunBuilder.build(); ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); secondSchedulerBuilder.setCapacityNeedFixed(10); @@ -172,12 +196,12 @@ public void initialize() { ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + secondReloadingPointAdapter = secondReloadingPointBuilder.build(); Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + secondReloadElement = secondReloadingElementBuilder.build(); DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); @@ -209,12 +233,12 @@ public void initialize() { distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); distributionAdapterBuilder.setCarrier(distributionCarrier); distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - Resource distributionAdapter = distributionAdapterBuilder.build(); + distributionAdapter = distributionAdapterBuilder.build(); Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); distributionBuilder.setResource(distributionAdapter); - LogisticsSolutionElement distributionElement = distributionBuilder.build(); + distributionElement = distributionBuilder.build(); collectionElement.setNextElement(firstReloadElement); firstReloadElement.setPreviousElement(collectionElement); @@ -253,7 +277,7 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); completeLSPBuilder.setSolutionScheduler(simpleScheduler); - completeLSP = completeLSPBuilder.build(); + lsp = completeLSPBuilder.build(); ArrayList linkList = new ArrayList(network.getLinks().values()); Random rand = new Random(1); @@ -297,16 +321,16 @@ public void initialize() { builder.setStartTimeWindow(startTimeWindow); builder.setServiceTime(capacityDemand * 60); LSPShipment shipment = builder.build(); - completeLSP.assignShipmentToLSP(shipment); + lsp.assignShipmentToLSP(shipment); } - completeLSP.scheduleSoultions(); + lsp.scheduleSoultions(); } @Test public void testCompletedLSPScheduling() { - for(LSPShipment shipment : completeLSP.getShipments()) { + for(LSPShipment shipment : lsp.getShipments()) { ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); System.out.println(); @@ -316,6 +340,295 @@ public void testCompletedLSPScheduling() { System.out.println(); } + ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); + ArrayList resources = new ArrayList<>(lsp.getResources()); + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 11); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + + assertTrue(planElements.get(10).getElementType() == "UNLOAD"); + assertTrue(planElements.get(10).getEndTime() >= (0)); + assertTrue(planElements.get(10).getEndTime() <= (24*3600)); + assertTrue(planElements.get(10).getStartTime() <= planElements.get(10).getEndTime()); + assertTrue(planElements.get(10).getStartTime() >= (0)); + assertTrue(planElements.get(10).getStartTime() <= (24*3600)); + assertTrue(planElements.get(10).getResourceId() == distributionAdapter.getId()); + assertTrue(planElements.get(10).getSolutionElement() == distributionElement); + + assertTrue(planElements.get(10).getStartTime() == planElements.get(9).getEndTime()); + + assertTrue(planElements.get(9).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(9).getEndTime() >= (0)); + assertTrue(planElements.get(9).getEndTime() <= (24*3600)); + assertTrue(planElements.get(9).getStartTime() <= planElements.get(9).getEndTime()); + assertTrue(planElements.get(9).getStartTime() >= (0)); + assertTrue(planElements.get(9).getStartTime() <= (24*3600)); + assertTrue(planElements.get(9).getResourceId() == distributionAdapter.getId()); + assertTrue(planElements.get(9).getSolutionElement() == distributionElement); + + assertTrue(planElements.get(9).getStartTime() == planElements.get(8).getEndTime()); + + assertTrue(planElements.get(8).getElementType() == "LOAD"); + assertTrue(planElements.get(8).getEndTime() >= (0)); + assertTrue(planElements.get(8).getEndTime() <= (24*3600)); + assertTrue(planElements.get(8).getStartTime() <= planElements.get(8).getEndTime()); + assertTrue(planElements.get(8).getStartTime() >= (0)); + assertTrue(planElements.get(8).getStartTime() <= (24*3600)); + assertTrue(planElements.get(8).getResourceId() == distributionAdapter.getId()); + assertTrue(planElements.get(8).getSolutionElement() == distributionElement); + + assertTrue(planElements.get(8).getStartTime() >= planElements.get(7).getEndTime()/ 1.0001); + + assertTrue(planElements.get(7).getElementType() == "HANDLE"); + assertTrue(planElements.get(7).getEndTime() >= (0)); + assertTrue(planElements.get(7).getEndTime() <= (24*3600)); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() >= (0)); + assertTrue(planElements.get(7).getStartTime() <= (24*3600)); + assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); + assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); + + assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + + assertTrue(planElements.get(6).getElementType() == "UNLOAD"); + assertTrue(planElements.get(6).getEndTime() >= (0)); + assertTrue(planElements.get(6).getEndTime() <= (24*3600)); + assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(6).getStartTime() >= (0)); + assertTrue(planElements.get(6).getStartTime() <= (24*3600)); + assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); + + assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(5).getEndTime() >= (0)); + assertTrue(planElements.get(5).getEndTime() <= (24*3600)); + assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); + assertTrue(planElements.get(5).getStartTime() >= (0)); + assertTrue(planElements.get(5).getStartTime() <= (24*3600)); + assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); + + assertTrue(planElements.get(4).getElementType() == "LOAD"); + assertTrue(planElements.get(4).getEndTime() >= (0)); + assertTrue(planElements.get(4).getEndTime() <= (24*3600)); + assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); + assertTrue(planElements.get(4).getStartTime() >= (0)); + assertTrue(planElements.get(4).getStartTime() <= (24*3600)); + assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); + eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == toLinkId); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 6); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == solutionElements.get(0)); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(serviceHandler.getElement() == solutionElements.get(0)); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); + MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); + assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunStartHandler.getLspShipment() == shipment); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); + MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); + assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunEndHandler.getLspShipment() == shipment); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(4) instanceof DistributionStartEventHandler); + DistributionStartEventHandler distributionStartHandler = (DistributionStartEventHandler) eventHandlers.get(4); + assertTrue(distributionStartHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); + assertTrue(distributionStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(distributionStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(distributionStartHandler.getElement() == planElements.get(8).getSolutionElement()); + assertTrue(distributionStartHandler.getElement() == planElements.get(9).getSolutionElement()); + assertTrue(distributionStartHandler.getElement() == planElements.get(10).getSolutionElement()); + assertTrue(distributionStartHandler.getElement() == solutionElements.get(4)); + assertTrue(distributionStartHandler.getLspShipment() == shipment); + assertTrue(distributionStartHandler.getResource().getId() == planElements.get(8).getResourceId()); + assertTrue(distributionStartHandler.getResource().getId() == planElements.get(9).getResourceId()); + assertTrue(distributionStartHandler.getResource().getId() == planElements.get(10).getResourceId()); + assertTrue(distributionStartHandler.getResource().getId() == resources.get(4).getId()); + + assertTrue(eventHandlers.get(5) instanceof DistributionServiceEventHandler); + DistributionServiceEventHandler distributionServiceHandler = (DistributionServiceEventHandler) eventHandlers.get(5); + assertTrue(distributionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); + assertTrue(distributionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(distributionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(8).getSolutionElement()); + assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(9).getSolutionElement()); + assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(10).getSolutionElement()); + assertTrue(distributionServiceHandler.getSolutionElement() == solutionElements.get(4)); + assertTrue(distributionServiceHandler.getLspShipment() == shipment); + assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(8).getResourceId()); + assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(9).getResourceId()); + assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(10).getResourceId()); + assertTrue(distributionServiceHandler.getResource().getId() == resources.get(4).getId()); + + } + + } } diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java index ff9069c182c..c24c40878d3 100644 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -160,7 +160,7 @@ public void initialize() { ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 11; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); //Random random = new Random(1); diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java index bf8a88ef044..366e693846b 100644 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -1,6 +1,5 @@ package lspSchedulingTests; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -306,7 +305,7 @@ public void testMainRunLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertEquals(planElements.get(4).getStartTime(), planElements.get(3).getEndTime() , 60 ); + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -437,19 +436,19 @@ public void testMainRunLSPScheduling() { assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(startHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(startHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(startHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(startHandler.getLspShipment() == shipment); - assertTrue(startHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(startHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(startHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(startHandler.getResource().getId() == resources.get(2).getId()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunEndHandler.getLspShipment() == shipment); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); } } diff --git a/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java new file mode 100644 index 00000000000..53f5ad588f4 --- /dev/null +++ b/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java @@ -0,0 +1,240 @@ +package lspSchedulingTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierPlanXmlWriterV2; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.Carriers; +import org.matsim.contrib.freight.carrier.ScheduledTour; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.Leg; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsCollectionLSPSchedulingTest { + + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + + for(int i = 1; i < 100; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + + } + + @Test + public void testCollectionLSPScheduling() { + + for(LSPShipment shipment : collectionLSP.getShipments()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + } + + for(LSPShipment shipment : collectionLSP.getShipments()) { + assertTrue(shipment.getSchedule().getPlanElements().size() == 3); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + + assertTrue(shipment.getEventHandlers().size() == 2); + ArrayList eventHandlers = new ArrayList(shipment.getEventHandlers()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(serviceHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(serviceHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); + } + } +} diff --git a/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java new file mode 100644 index 00000000000..78d9a3321d0 --- /dev/null +++ b/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java @@ -0,0 +1,634 @@ +package lspSchedulingTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Random; +import java.util.Map.Entry; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.DistributionServiceEventHandler; +import lsp.usecase.DistributionStartEventHandler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunEndEventHandler; +import lsp.usecase.MainRunStartEventHandler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsCompleteLSPSchedulingTest { + + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Resource secondReloadingPointAdapter; + private LogisticsSolutionElement secondReloadElement; + private Resource distributionAdapter; + private LogisticsSolutionElement distributionElement; + private Id toLinkId; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + toLinkId = Id.createLinkId("(14 2) (14 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(fromLinkId); + mainRunAdapterBuilder.setToLinkId(toLinkId); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); + distributionCarrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(distributionCarrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Random rand = new Random(1); + for(int i = 1; i < 100; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = rand.nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList, rand); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + + @Test + public void testCompletedLSPScheduling() { + + for(LSPShipment shipment : lsp.getShipments()) { + ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(AbstractShipmentPlanElement element : elementList) { + System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime()); + } + System.out.println(); + } + + ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); + ArrayList resources = new ArrayList<>(lsp.getResources()); + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 11); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + + assertTrue(planElements.get(10).getElementType() == "UNLOAD"); + assertTrue(planElements.get(10).getEndTime() >= (0)); + assertTrue(planElements.get(10).getEndTime() <= (24*3600)); + assertTrue(planElements.get(10).getStartTime() <= planElements.get(10).getEndTime()); + assertTrue(planElements.get(10).getStartTime() >= (0)); + assertTrue(planElements.get(10).getStartTime() <= (24*3600)); + assertTrue(planElements.get(10).getResourceId() == distributionAdapter.getId()); + assertTrue(planElements.get(10).getSolutionElement() == distributionElement); + + assertTrue(planElements.get(10).getStartTime() == planElements.get(9).getEndTime()); + + assertTrue(planElements.get(9).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(9).getEndTime() >= (0)); + assertTrue(planElements.get(9).getEndTime() <= (24*3600)); + assertTrue(planElements.get(9).getStartTime() <= planElements.get(9).getEndTime()); + assertTrue(planElements.get(9).getStartTime() >= (0)); + assertTrue(planElements.get(9).getStartTime() <= (24*3600)); + assertTrue(planElements.get(9).getResourceId() == distributionAdapter.getId()); + assertTrue(planElements.get(9).getSolutionElement() == distributionElement); + + assertTrue(planElements.get(9).getStartTime() == planElements.get(8).getEndTime()); + + assertTrue(planElements.get(8).getElementType() == "LOAD"); + assertTrue(planElements.get(8).getEndTime() >= (0)); + assertTrue(planElements.get(8).getEndTime() <= (24*3600)); + assertTrue(planElements.get(8).getStartTime() <= planElements.get(8).getEndTime()); + assertTrue(planElements.get(8).getStartTime() >= (0)); + assertTrue(planElements.get(8).getStartTime() <= (24*3600)); + assertTrue(planElements.get(8).getResourceId() == distributionAdapter.getId()); + assertTrue(planElements.get(8).getSolutionElement() == distributionElement); + + assertTrue(planElements.get(8).getStartTime() >= planElements.get(7).getEndTime()/ 1.0001); + + assertTrue(planElements.get(7).getElementType() == "HANDLE"); + assertTrue(planElements.get(7).getEndTime() >= (0)); + assertTrue(planElements.get(7).getEndTime() <= (24*3600)); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() >= (0)); + assertTrue(planElements.get(7).getStartTime() <= (24*3600)); + assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); + assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); + + assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + + assertTrue(planElements.get(6).getElementType() == "UNLOAD"); + assertTrue(planElements.get(6).getEndTime() >= (0)); + assertTrue(planElements.get(6).getEndTime() <= (24*3600)); + assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(6).getStartTime() >= (0)); + assertTrue(planElements.get(6).getStartTime() <= (24*3600)); + assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); + + assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(5).getEndTime() >= (0)); + assertTrue(planElements.get(5).getEndTime() <= (24*3600)); + assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); + assertTrue(planElements.get(5).getStartTime() >= (0)); + assertTrue(planElements.get(5).getStartTime() <= (24*3600)); + assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); + + assertTrue(planElements.get(4).getElementType() == "LOAD"); + assertTrue(planElements.get(4).getEndTime() >= (0)); + assertTrue(planElements.get(4).getEndTime() <= (24*3600)); + assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); + assertTrue(planElements.get(4).getStartTime() >= (0)); + assertTrue(planElements.get(4).getStartTime() <= (24*3600)); + assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); + eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == toLinkId); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 6); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == solutionElements.get(0)); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(serviceHandler.getElement() == solutionElements.get(0)); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); + MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); + assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunStartHandler.getLspShipment() == shipment); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); + MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); + assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunEndHandler.getLspShipment() == shipment); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(4) instanceof DistributionStartEventHandler); + DistributionStartEventHandler distributionStartHandler = (DistributionStartEventHandler) eventHandlers.get(4); + assertTrue(distributionStartHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); + assertTrue(distributionStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(distributionStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(distributionStartHandler.getElement() == planElements.get(8).getSolutionElement()); + assertTrue(distributionStartHandler.getElement() == planElements.get(9).getSolutionElement()); + assertTrue(distributionStartHandler.getElement() == planElements.get(10).getSolutionElement()); + assertTrue(distributionStartHandler.getElement() == solutionElements.get(4)); + assertTrue(distributionStartHandler.getLspShipment() == shipment); + assertTrue(distributionStartHandler.getResource().getId() == planElements.get(8).getResourceId()); + assertTrue(distributionStartHandler.getResource().getId() == planElements.get(9).getResourceId()); + assertTrue(distributionStartHandler.getResource().getId() == planElements.get(10).getResourceId()); + assertTrue(distributionStartHandler.getResource().getId() == resources.get(4).getId()); + + assertTrue(eventHandlers.get(5) instanceof DistributionServiceEventHandler); + DistributionServiceEventHandler distributionServiceHandler = (DistributionServiceEventHandler) eventHandlers.get(5); + assertTrue(distributionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); + assertTrue(distributionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(distributionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(8).getSolutionElement()); + assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(9).getSolutionElement()); + assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(10).getSolutionElement()); + assertTrue(distributionServiceHandler.getSolutionElement() == solutionElements.get(4)); + assertTrue(distributionServiceHandler.getLspShipment() == shipment); + assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(8).getResourceId()); + assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(9).getResourceId()); + assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(10).getResourceId()); + assertTrue(distributionServiceHandler.getResource().getId() == resources.get(4).getId()); + + } + + + } + +} diff --git a/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java new file mode 100644 index 00000000000..c3910a1ae83 --- /dev/null +++ b/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java @@ -0,0 +1,331 @@ +package lspSchedulingTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.usecase.ReloadingPointEventHandler.ReloadingPointEventHandlerPair; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsFirstReloadLSPSchedulingTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private LogisticsSolutionElement collectionElement; + private Resource collectionAdapter; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + firstReloadElement = firstReloadingElementBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 100; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + + @Test + public void testFirstReloadLSPScheduling() { + + for(LSPShipment shipment : lsp.getShipments()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + } + + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 4); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + //This asserts that the shipments waiting for handling have been handled and the queues have been cleared + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 2); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == lsp.getResources().iterator().next().getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(serviceHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getResourceId() == lsp.getResources().iterator().next().getId()); + } + } +} diff --git a/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java new file mode 100644 index 00000000000..eaf680fb367 --- /dev/null +++ b/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java @@ -0,0 +1,455 @@ +package lspSchedulingTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Random; + + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunEndEventHandler; +import lsp.usecase.MainRunStartEventHandler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsMainRunLSPSchedulingTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Id collectionLinkId; + private Id firstReloadingLinkId; + private Id fromLinkId; + private Id toLinkId; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + fromLinkId = Id.createLinkId("(4 2) (4 3)"); + toLinkId = Id.createLinkId("(14 2) (14 3)"); + + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(fromLinkId); + mainRunAdapterBuilder.setToLinkId(toLinkId); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + mainRunElement = mainRunBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 100; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + + @Test + public void testMainRunLSPScheduling() { + + /*for(LSPShipment shipment : lsp.getShipments()) { + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + + System.out.println(); + for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { + System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + } + System.out.println(); + }*/ + + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 7); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + assertTrue(planElements.get(6).getElementType() == "UNLOAD"); + assertTrue(planElements.get(6).getEndTime() >= (0)); + assertTrue(planElements.get(6).getEndTime() <= (24*3600)); + assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(6).getStartTime() >= (0)); + assertTrue(planElements.get(6).getStartTime() <= (24*3600)); + assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); + + assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(5).getEndTime() >= (0)); + assertTrue(planElements.get(5).getEndTime() <= (24*3600)); + assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); + assertTrue(planElements.get(5).getStartTime() >= (0)); + assertTrue(planElements.get(5).getStartTime() <= (24*3600)); + assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); + + assertTrue(planElements.get(4).getElementType() == "LOAD"); + assertTrue(planElements.get(4).getEndTime() >= (0)); + assertTrue(planElements.get(4).getEndTime() <= (24*3600)); + assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); + assertTrue(planElements.get(4).getStartTime() >= (0)); + assertTrue(planElements.get(4).getStartTime() <= (24*3600)); + assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 4); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); + ArrayList resources = new ArrayList<>(lsp.getResources()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(endHandler.getElement() == solutionElements.get(0)); + assertTrue(endHandler.getLspShipment() == shipment); + assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(endHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(serviceHandler.getElement() == solutionElements.get(0)); + assertTrue(serviceHandler.getLspShipment() == shipment); + assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); + MainRunStartEventHandler startHandler = (MainRunStartEventHandler) eventHandlers.get(2); + assertTrue(startHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(startHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(startHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(startHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(startHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(startHandler.getLspShipment() == shipment); + assertTrue(startHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(startHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(startHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(startHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); + MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); + assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunEndHandler.getLspShipment() == shipment); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); + } + + } +} diff --git a/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java new file mode 100644 index 00000000000..21d6504771a --- /dev/null +++ b/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -0,0 +1,520 @@ +package lspSchedulingTests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Random; +import java.util.Map.Entry; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunEndEventHandler; +import lsp.usecase.MainRunStartEventHandler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsSecondReloadLSPSchedulingTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Resource secondReloadingPointAdapter; + private LogisticsSolutionElement secondReloadElement; + private Id toLinkId; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + toLinkId = Id.createLinkId("(14 2) (14 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(fromLinkId); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId(toLinkId)); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + secondReloadElement = secondReloadingElementBuilder.build(); + + + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + for(int i = 1; i < 100; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + } + + @Test + public void testSecondReloadLSPScheduling() { + + /*for(LSPShipment shipment : lsp.getShipments()) { + ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); + System.out.println(); + for(AbstractShipmentPlanElement element : elementList) { + System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); + } + System.out.println(); + }*/ + + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 8); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + + assertTrue(planElements.get(7).getElementType() == "HANDLE"); + assertTrue(planElements.get(7).getEndTime() >= (0)); + assertTrue(planElements.get(7).getEndTime() <= (24*3600)); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() >= (0)); + assertTrue(planElements.get(7).getStartTime() <= (24*3600)); + assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); + assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); + + assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + + assertTrue(planElements.get(6).getElementType() == "UNLOAD"); + assertTrue(planElements.get(6).getEndTime() >= (0)); + assertTrue(planElements.get(6).getEndTime() <= (24*3600)); + assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(6).getStartTime() >= (0)); + assertTrue(planElements.get(6).getStartTime() <= (24*3600)); + assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); + + assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(5).getEndTime() >= (0)); + assertTrue(planElements.get(5).getEndTime() <= (24*3600)); + assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); + assertTrue(planElements.get(5).getStartTime() >= (0)); + assertTrue(planElements.get(5).getStartTime() <= (24*3600)); + assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); + + assertTrue(planElements.get(4).getElementType() == "LOAD"); + assertTrue(planElements.get(4).getEndTime() >= (0)); + assertTrue(planElements.get(4).getEndTime() <= (24*3600)); + assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); + assertTrue(planElements.get(4).getStartTime() >= (0)); + assertTrue(planElements.get(4).getStartTime() <= (24*3600)); + assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime()/ (1.0001)); + + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); + eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == toLinkId); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 4); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); + ArrayList resources = new ArrayList<>(lsp.getResources()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler collectionEndHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(collectionEndHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(collectionEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(collectionEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(collectionEndHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(collectionEndHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(collectionEndHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(collectionEndHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(collectionEndHandler.getElement() == solutionElements.get(0)); + assertTrue(collectionEndHandler.getLspShipment() == shipment); + assertTrue(collectionEndHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(collectionEndHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(collectionEndHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(collectionEndHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler collectionServiceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(collectionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(collectionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(collectionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(collectionServiceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(collectionServiceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(collectionServiceHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(collectionServiceHandler.getElement() == solutionElements.get(0)); + assertTrue(collectionServiceHandler.getLspShipment() == shipment); + assertTrue(collectionServiceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(collectionServiceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(collectionServiceHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(collectionServiceHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); + MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); + assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunStartHandler.getLspShipment() == shipment); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); + MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); + assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunEndHandler.getLspShipment() == shipment); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); + } + + } +} diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java index 4b03309cafc..9acf7daee1c 100644 --- a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java @@ -1,8 +1,13 @@ package lspSchedulingTests; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.Random; +import java.util.Map.Entry; import org.junit.Before; import org.junit.Test; @@ -13,11 +18,13 @@ import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierCapabilities; import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; +import org.matsim.core.events.handler.EventHandler; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vehicles.Vehicle; @@ -25,12 +32,15 @@ import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.CollectionServiceEventHandler; +import lsp.usecase.CollectionTourEndEventHandler; import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; import lsp.usecase.MainRunCarrierAdapter; import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.MainRunEndEventHandler; +import lsp.usecase.MainRunStartEventHandler; import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointEventHandler; import lsp.usecase.ReloadingPointScheduler; import lsp.usecase.SimpleForwardSolutionScheduler; import lsp.LSP; @@ -55,7 +65,16 @@ public class SecondReloadLSPSchedulingTest { private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; private LSP lsp; - + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private Resource firstReloadingPointAdapter; + private LogisticsSolutionElement firstReloadElement; + private Resource mainRunAdapter; + private LogisticsSolutionElement mainRunElement; + private Resource secondReloadingPointAdapter; + private LogisticsSolutionElement secondReloadElement; + private Id toLinkId; + @Before public void initialize() { Config config = new Config(); @@ -95,12 +114,12 @@ public void initialize() { collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); collectionAdapterBuilder.setCarrier(collectionCarrier); collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); + collectionAdapter = collectionAdapterBuilder.build(); Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); collectionBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionBuilder.build(); + collectionElement = collectionBuilder.build(); ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); @@ -112,12 +131,12 @@ public void initialize() { ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + firstReloadElement = firstReloadingElementBuilder.build(); Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); @@ -131,6 +150,7 @@ public void initialize() { Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + toLinkId = Id.createLinkId("(14 2) (14 3)"); Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); mainRunCarrierVehicle.setVehicleType(mainRunType); @@ -150,15 +170,15 @@ public void initialize() { Id mainRunId = Id.create("MainRunAdapter", Resource.class); MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setFromLinkId(fromLinkId); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId(toLinkId)); mainRunAdapterBuilder.setCarrier(mainRunCarrier); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); + mainRunAdapter = mainRunAdapterBuilder.build(); Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + mainRunElement = mainRunBuilder.build(); ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); secondSchedulerBuilder.setCapacityNeedFixed(10); @@ -170,12 +190,12 @@ public void initialize() { ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + secondReloadingPointAdapter = secondReloadingPointBuilder.build(); Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + secondReloadElement = secondReloadingElementBuilder.build(); @@ -277,5 +297,224 @@ public void testSecondReloadLSPScheduling() { System.out.println(); } + for(LSPShipment shipment : lsp.getShipments()){ + assertTrue(shipment.getSchedule().getPlanElements().size() == 8); + ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + + assertTrue(planElements.get(7).getElementType() == "HANDLE"); + assertTrue(planElements.get(7).getEndTime() >= (0)); + assertTrue(planElements.get(7).getEndTime() <= (24*3600)); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() >= (0)); + assertTrue(planElements.get(7).getStartTime() <= (24*3600)); + assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); + assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); + + assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + + assertTrue(planElements.get(6).getElementType() == "UNLOAD"); + assertTrue(planElements.get(6).getEndTime() >= (0)); + assertTrue(planElements.get(6).getEndTime() <= (24*3600)); + assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(6).getStartTime() >= (0)); + assertTrue(planElements.get(6).getStartTime() <= (24*3600)); + assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); + + assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(5).getEndTime() >= (0)); + assertTrue(planElements.get(5).getEndTime() <= (24*3600)); + assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); + assertTrue(planElements.get(5).getStartTime() >= (0)); + assertTrue(planElements.get(5).getStartTime() <= (24*3600)); + assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); + + assertTrue(planElements.get(4).getElementType() == "LOAD"); + assertTrue(planElements.get(4).getEndTime() >= (0)); + assertTrue(planElements.get(4).getEndTime() <= (24*3600)); + assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); + assertTrue(planElements.get(4).getStartTime() >= (0)); + assertTrue(planElements.get(4).getStartTime() <= (24*3600)); + assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); + assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); + + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + + assertTrue(planElements.get(3).getElementType() == "HANDLE"); + assertTrue(planElements.get(3).getEndTime() >= (0)); + assertTrue(planElements.get(3).getEndTime() <= (24*3600)); + assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); + assertTrue(planElements.get(3).getStartTime() >= (0)); + assertTrue(planElements.get(3).getStartTime() <= (24*3600)); + assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); + assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); + + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + + assertTrue(planElements.get(2).getElementType() == "UNLOAD"); + assertTrue(planElements.get(2).getEndTime() >= (0)); + assertTrue(planElements.get(2).getEndTime() <= (24*3600)); + assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); + assertTrue(planElements.get(2).getStartTime() >= (0)); + assertTrue(planElements.get(2).getStartTime() <= (24*3600)); + assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(2).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); + + assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); + assertTrue(planElements.get(1).getEndTime() >= (0)); + assertTrue(planElements.get(1).getEndTime() <= (24*3600)); + assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); + assertTrue(planElements.get(1).getStartTime() >= (0)); + assertTrue(planElements.get(1).getStartTime() <= (24*3600)); + assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(1).getSolutionElement() == collectionElement); + + assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); + + assertTrue(planElements.get(0).getElementType() == "LOAD"); + assertTrue(planElements.get(0).getEndTime() >= (0)); + assertTrue(planElements.get(0).getEndTime() <= (24*3600)); + assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); + assertTrue(planElements.get(0).getStartTime() >= (0)); + assertTrue(planElements.get(0).getStartTime() <= (24*3600)); + assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); + assertTrue(planElements.get(0).getSolutionElement() == collectionElement); + } + + assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); + ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); + eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); + assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); + reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while(iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LSPShipment shipment = entry.getValue().shipment; + LogisticsSolutionElement element = entry.getValue().element; + assertTrue(service.getLocationLinkId() == toLinkId); + assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(service.getServiceDuration() == shipment.getServiceTime()); + boolean handledByReloadingPoint = false; + for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { + if(clientElement == element) { + handledByReloadingPoint = true; + } + } + assertTrue(handledByReloadingPoint); + + assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); + assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); + } + + for(LSPShipment shipment : lsp.getShipments()) { + assertTrue(shipment.getEventHandlers().size() == 4); + eventHandlers = new ArrayList(shipment.getEventHandlers()); + ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); + ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); + ArrayList resources = new ArrayList<>(lsp.getResources()); + + assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); + CollectionTourEndEventHandler collectionEndHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); + assertTrue(collectionEndHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(collectionEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(collectionEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(collectionEndHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(collectionEndHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(collectionEndHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(collectionEndHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(collectionEndHandler.getElement() == solutionElements.get(0)); + assertTrue(collectionEndHandler.getLspShipment() == shipment); + assertTrue(collectionEndHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(collectionEndHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(collectionEndHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(collectionEndHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); + CollectionServiceEventHandler collectionServiceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); + assertTrue(collectionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); + assertTrue(collectionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(collectionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); + assertTrue(collectionServiceHandler.getElement() == planElements.get(0).getSolutionElement()); + assertTrue(collectionServiceHandler.getElement() == planElements.get(1).getSolutionElement()); + assertTrue(collectionServiceHandler.getElement() == planElements.get(2).getSolutionElement()); + assertTrue(collectionServiceHandler.getElement() == solutionElements.get(0)); + assertTrue(collectionServiceHandler.getLspShipment() == shipment); + assertTrue(collectionServiceHandler.getResourceId() == planElements.get(0).getResourceId()); + assertTrue(collectionServiceHandler.getResourceId() == planElements.get(1).getResourceId()); + assertTrue(collectionServiceHandler.getResourceId() == planElements.get(2).getResourceId()); + assertTrue(collectionServiceHandler.getResourceId() == resources.get(0).getId()); + + assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); + MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); + assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunStartHandler.getLspShipment() == shipment); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); + + assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); + MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); + assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); + assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); + assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); + assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); + assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); + assertTrue(mainRunEndHandler.getLspShipment() == shipment); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); + assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); + } + } } diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java index 73ec7f187fa..dd2d932080e 100644 --- a/test/lspScoringTests/CollectionLSPScoringTest.java +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -54,11 +54,10 @@ import lsp.shipment.LSPShipment; import lsp.shipment.LSPShipmentImpl; - public class CollectionLSPScoringTest { - + private Network network; - private LSP collectionLSP; + private LSP collectionLSP; private Carrier carrier; private Resource collectionAdapter; private LogisticsSolutionElement collectionElement; @@ -68,16 +67,16 @@ public class CollectionLSPScoringTest { private InfoFunction function; private InfoFunctionValue value; private int numberOfShipments = 25; - + @Before public void initialize() { - + Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); Id carrierId = Id.create("CollectionCarrier", Carrier.class); Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); @@ -86,9 +85,9 @@ public void initialize() { vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); vehicleTypeBuilder.setCostPerTimeUnit(0.38); vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); + vehicleTypeBuilder.setMaxVelocity(50 / 3.6); CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); Link collectionLink = network.getLinks().get(collectionLinkId); if (collectionLink == null) { @@ -97,7 +96,7 @@ public void initialize() { Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); carrierVehicle.setVehicleType(collectionType); - + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); @@ -105,93 +104,95 @@ public void initialize() { CarrierCapabilities capabilities = capabilitiesBuilder.build(); carrier = CarrierImpl.newInstance(carrierId); carrier.setCarrierCapabilities(capabilities); - - + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, + network); adapterBuilder.setCollectionScheduler(scheduler); adapterBuilder.setCarrier(carrier); adapterBuilder.setLocationLinkId(collectionLinkId); collectionAdapter = adapterBuilder.build(); - + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(elementId); collectionElementBuilder.setResource(collectionAdapter); collectionElement = collectionElementBuilder.build(); - + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder + .newInstance(collectionSolutionId); collectionSolutionBuilder.addSolutionElement(collectionElement); LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); LSPPlanImpl collectionPlan = new LSPPlanImpl(); collectionPlan.setAssigner(assigner); collectionPlan.addSolution(collectionSolution); - + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); collectionLSPBuilder.setInitialPlan(collectionPlan); Id collectionLSPId = Id.create("CollectionLSP", LSP.class); collectionLSPBuilder.setId(collectionLSPId); ArrayList resourcesList = new ArrayList(); resourcesList.add(collectionAdapter); - + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); - + TipEventHandler handler = new TipEventHandler(); value = new InfoFunctionValueImpl("TIP IN EUR"); function = new InfoFunctionImpl(); function.getValues().add(value); info = new TipInfo(function); - tipTracker = new TipSimulationTracker(handler,info); + tipTracker = new TipSimulationTracker(handler, info); collectionAdapter.addSimulationTracker(tipTracker); tipScorer = new TipScorer(collectionLSP, tipTracker); collectionLSP.setScorer(tipScorer); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id toLinkId = collectionLinkId; - - - for(int i = 1; i < (numberOfShipments + 1); i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(10); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - collectionLSP.assignShipmentToLSP(shipment); - } - - collectionLSP.scheduleSoultions(); - + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + for (int i = 1; i < (numberOfShipments + 1); i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while (true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 + && pendingFromLink.getFromNode().getCoord().getY() <= 4000 + && pendingFromLink.getToNode().getCoord().getX() <= 4000 + && pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0, (24 * 3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0, (24 * 3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + + collectionLSP.scheduleSoultions(); + ArrayList lspList = new ArrayList(); lspList.add(collectionLSP); LSPs lsps = new LSPs(lspList); - + Controler controler = new Controler(config); - - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), + EventUtils.getStandardEventCreators()); controler.addOverridingModule(module); config.controler().setFirstIteration(0); @@ -205,9 +206,10 @@ public void initialize() { public void testCollectionLSPScoring() { System.out.println(collectionLSP.getSelectedPlan().getScore()); assertTrue(collectionLSP.getShipments().size() == numberOfShipments); - assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments().size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments() + .size() == numberOfShipments); assertTrue(collectionLSP.getSelectedPlan().getScore() > 0); - assertTrue(collectionLSP.getSelectedPlan().getScore() <=(numberOfShipments*5)); + assertTrue(collectionLSP.getSelectedPlan().getScore() <= (numberOfShipments * 5)); } } diff --git a/test/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java b/test/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java new file mode 100644 index 00000000000..cf52f82c536 --- /dev/null +++ b/test/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java @@ -0,0 +1,215 @@ +package lspScoringTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.functions.InfoFunction; +import lsp.functions.InfoFunctionImpl; +import lsp.functions.InfoFunctionValue; +import lsp.functions.InfoFunctionValueImpl; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScorer; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleIterationsCollectionLSPScoringTest { + + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private LSPScorer tipScorer; + private TipSimulationTracker tipTracker; + private TipInfo info; + private InfoFunction function; + private InfoFunctionValue value; + private int numberOfShipments = 25; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50 / 3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + if (collectionLink == null) { + System.exit(1); + } + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, + network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder + .newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder + .newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + TipEventHandler handler = new TipEventHandler(); + value = new InfoFunctionValueImpl("TIP IN EUR"); + function = new InfoFunctionImpl(); + function.getValues().add(value); + info = new TipInfo(function); + tipTracker = new TipSimulationTracker(handler, info); + collectionAdapter.addSimulationTracker(tipTracker); + tipScorer = new TipScorer(collectionLSP, tipTracker); + collectionLSP.setScorer(tipScorer); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + for (int i = 1; i < (numberOfShipments + 1); i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + Random random = new Random(1); + int capacityDemand = random.nextInt(10); + builder.setCapacityDemand(capacityDemand); + + while (true) { + Collections.shuffle(linkList, random); + Link pendingFromLink = linkList.get(0); + if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 + && pendingFromLink.getFromNode().getCoord().getY() <= 4000 + && pendingFromLink.getToNode().getCoord().getX() <= 4000 + && pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0, (24 * 3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0, (24 * 3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), + EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(10); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPScoring() { + System.out.println(collectionLSP.getSelectedPlan().getScore()); + assertTrue(collectionLSP.getShipments().size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getSolutions().iterator().next().getShipments() + .size() == numberOfShipments); + assertTrue(collectionLSP.getSelectedPlan().getScore() > 0); + assertTrue(collectionLSP.getSelectedPlan().getScore() <= (numberOfShipments * 5)); + } + +} diff --git a/test/testSuite/FTLabTestSuite.java b/test/testSuite/FTLabTestSuite.java index 881a677f338..05759a8d405 100644 --- a/test/testSuite/FTLabTestSuite.java +++ b/test/testSuite/FTLabTestSuite.java @@ -25,8 +25,14 @@ import lspSchedulingTests.CompleteLSPSchedulingTest; import lspSchedulingTests.FirstReloadLSPSchedulingTest; import lspSchedulingTests.MainRunLSPSchedulingTest; +import lspSchedulingTests.MultipleShipmentsCollectionLSPSchedulingTest; +import lspSchedulingTests.MultipleShipmentsCompleteLSPSchedulingTest; +import lspSchedulingTests.MultipleShipmentsFirstReloadLSPSchedulingTest; +import lspSchedulingTests.MultipleShipmentsMainRunLSPSchedulingTest; +import lspSchedulingTests.MultipleShipmentsSecondReloadLSPSchedulingTest; import lspSchedulingTests.SecondReloadLSPSchedulingTest; import lspScoringTests.CollectionLSPScoringTest; +import lspScoringTests.MultipleIterationsCollectionLSPScoringTest; import lspShipmentAssignmentTests.CollectionLSPShipmentAssigmentTest; import lspShipmentAssignmentTests.CompleteLSPShipmentAssignerTest; import lspShipmentTest.CollectionShipmentBuilderTest; @@ -88,7 +94,12 @@ MutualReplanningAndOfferUpdateTest.class, CollectionLSPShipmentAssigmentTest.class, CompleteLSPShipmentAssignerTest.class, - + MultipleShipmentsCollectionLSPSchedulingTest.class, + MultipleShipmentsFirstReloadLSPSchedulingTest.class, + MultipleShipmentsMainRunLSPSchedulingTest.class, + MultipleShipmentsSecondReloadLSPSchedulingTest.class, + MultipleShipmentsCompleteLSPSchedulingTest.class, + MultipleIterationsCollectionLSPScoringTest.class, }) public class FTLabTestSuite { From 00d78689a9b40f4c28d5dd69d72039efc34b1fc7 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 15:42:58 +0200 Subject: [PATCH 0037/1340] Changed method notifyScoring in the MutualControlerListener to prevent double scoring of the single plans. Further, changed signature of methods scoreLSPs and scoreDemandObjects in the MutualScoringModule --- .../controler/MutualControlerListener.java | 30 ++++--------------- src/demand/scoring/MutualScoringModule.java | 5 ++-- .../scoring/MutualScoringModuleImpl.java | 10 +++---- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/demand/controler/MutualControlerListener.java b/src/demand/controler/MutualControlerListener.java index 115eceb1eb4..266be73fd1c 100644 --- a/src/demand/controler/MutualControlerListener.java +++ b/src/demand/controler/MutualControlerListener.java @@ -74,19 +74,17 @@ protected MutualControlerListener(LSPDecorators lsps, DemandObjects demandObject @Override public void notifyBeforeMobsim(BeforeMobsimEvent event) { - carrierResourceTracker = new CarrierResourceTracker(carriers, network, this, creators); - eventsManager.addHandler(carrierResourceTracker); - SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); rescheduler.notifyBeforeMobsim(event); - + + carrierResourceTracker = new CarrierResourceTracker(carriers, network, this, creators); + eventsManager.addHandler(carrierResourceTracker); registeredHandlers = new ArrayList(); for (LSP lsp : lsps.getLSPs().values()) { for (LSPShipment shipment : lsp.getShipments()) { for (EventHandler handler : shipment.getEventHandlers()) { eventsManager.addHandler(handler); - registeredHandlers.add(handler); } } LSPPlan selectedPlan = lsp.getSelectedPlan(); @@ -109,8 +107,6 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) { } } } - - @Override public void notifyIterationEnds(IterationEndsEvent event) { @@ -125,24 +121,8 @@ public void notifyReplanning(ReplanningEvent event) { @Override public void notifyScoring(ScoringEvent event) { - boolean score = true; - for (LSP lsp : lsps.getLSPs().values()) { - if (lsp.getScorer() == null) { - score = false; - } - if (score == true) { - mutualScoringModule.scoreLSPs(); - } - } - - for (DemandObject demandObject : demandObjects.getDemandObjects().values()) { - if (demandObject.getScorer() == null) { - score = false; - } - if (score == true) { - mutualScoringModule.scoreDemandObjects(); - } - } + mutualScoringModule.scoreLSPs(event); + mutualScoringModule.scoreDemandObjects(event); } @Override diff --git a/src/demand/scoring/MutualScoringModule.java b/src/demand/scoring/MutualScoringModule.java index a42e4ac3196..c06c3a2b5c7 100644 --- a/src/demand/scoring/MutualScoringModule.java +++ b/src/demand/scoring/MutualScoringModule.java @@ -1,9 +1,10 @@ package demand.scoring; +import org.matsim.core.controler.events.ScoringEvent; import org.matsim.core.controler.listener.ScoringListener; public interface MutualScoringModule extends ScoringListener{ - public void scoreDemandObjects(); - public void scoreLSPs(); + public void scoreDemandObjects(ScoringEvent event); + public void scoreLSPs(ScoringEvent event); } diff --git a/src/demand/scoring/MutualScoringModuleImpl.java b/src/demand/scoring/MutualScoringModuleImpl.java index f12122f10b5..f0bc1c90439 100644 --- a/src/demand/scoring/MutualScoringModuleImpl.java +++ b/src/demand/scoring/MutualScoringModuleImpl.java @@ -20,13 +20,13 @@ public MutualScoringModuleImpl(Collection demandObjects, Collectio } @Override - public void notifyScoring(ScoringEvent arg0) { - scoreDemandObjects(); - scoreLSPs(); + public void notifyScoring(ScoringEvent event) { + scoreDemandObjects(event); + scoreLSPs(event); } @Override - public void scoreDemandObjects() { + public void scoreDemandObjects(ScoringEvent event) { for(DemandObject demandObject : demandObjects) { if(demandObject.getScorer() != null) { demandObject.scoreSelectedPlan(); @@ -35,7 +35,7 @@ public void scoreDemandObjects() { } @Override - public void scoreLSPs() { + public void scoreLSPs(ScoringEvent event) { for(LSPDecorator lsp : lsps) { if(lsp.getScorer() != null) { lsp.scoreSelectedPlan(); From 8cb57c80ba84ae24dc970961efc3bab2ab626d8c Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 16:36:26 +0200 Subject: [PATCH 0038/1340] Minor changes without influence on the program syntax and semantics (indentings...) --- src/demand/controler/InitialDemandAssigner.java | 14 ++++++-------- src/demand/controler/MutualControlerListener.java | 1 - 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/demand/controler/InitialDemandAssigner.java b/src/demand/controler/InitialDemandAssigner.java index 44da6e9494d..a82235ee7a9 100644 --- a/src/demand/controler/InitialDemandAssigner.java +++ b/src/demand/controler/InitialDemandAssigner.java @@ -3,9 +3,7 @@ import java.util.Collection; import org.matsim.api.core.v01.Id; -import org.matsim.core.controler.events.BeforeMobsimEvent; import org.matsim.core.controler.events.StartupEvent; -import org.matsim.core.controler.listener.BeforeMobsimListener; import org.matsim.core.controler.listener.StartupListener; import demand.decoratedLSP.LSPDecorator; @@ -31,12 +29,12 @@ public InitialDemandAssigner(DemandObjects demandObjects, LSPDecorators lsps) { @Override public void notifyStartup(StartupEvent event) { - for(DemandObject demandObject : demandObjects.getDemandObjects().values()) { - if(demandObject.getSelectedPlan() == null) { - createInitialPlan(demandObject); - } - assignShipmentToLSP(demandObject); + for(DemandObject demandObject : demandObjects.getDemandObjects().values()) { + if(demandObject.getSelectedPlan() == null) { + createInitialPlan(demandObject); } + assignShipmentToLSP(demandObject); + } for(LSPDecorator lsp : lsps.getLSPs().values()) { lsp.scheduleSoultions(); @@ -46,7 +44,7 @@ public void notifyStartup(StartupEvent event) { private void createInitialPlan(DemandObject demandObject) { Collection offers = demandObject.getOfferRequester().requestOffers(lsps.getLSPs().values()); DemandPlan initialPlan = demandObject.getDemandPlanGenerator().createDemandPlan(offers); - demandObject.setSelectedPlan(initialPlan); + demandObject.setSelectedPlan(initialPlan); } private void assignShipmentToLSP(DemandObject demandObject) { diff --git a/src/demand/controler/MutualControlerListener.java b/src/demand/controler/MutualControlerListener.java index 266be73fd1c..ef032e20c79 100644 --- a/src/demand/controler/MutualControlerListener.java +++ b/src/demand/controler/MutualControlerListener.java @@ -199,7 +199,6 @@ public CarrierResourceTracker getCarrierResourceTracker() { return carrierResourceTracker; } - @Override public void notifyIterationStarts(IterationStartsEvent event) { if(event.getIteration() > 0) { From 5a5f3124d5b01ec60d8176650deb823db7ac98c7 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 16:56:00 +0200 Subject: [PATCH 0039/1340] Minor changes without influence on the syntax and semantics of the program. --- src/demand/decoratedLSP/LSPWithOffers.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/demand/decoratedLSP/LSPWithOffers.java b/src/demand/decoratedLSP/LSPWithOffers.java index 82b2505b82d..cf9dbf81893 100644 --- a/src/demand/decoratedLSP/LSPWithOffers.java +++ b/src/demand/decoratedLSP/LSPWithOffers.java @@ -310,5 +310,10 @@ public static LSPPlanDecorator copyPlan(LSPPlanDecorator plan2copy) { return copiedPlan; } + @Override + public SolutionScheduler getScheduler() { + return solutionScheduler; + } + } From 300af286f4764fcaf3a5ff954146734cb8057bd6 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 17:15:03 +0200 Subject: [PATCH 0040/1340] Enhanced and added tests to foster automatic testing with test suite. --- test/cascadingInfoTest/CascadingInfoTest.java | 2 +- .../CollectionLSPMobsimTest.java | 39 +- .../lspMobsimTests/CompleteLSPMobsimTest.java | 25 +- .../FirstReloadLSPMobsimTest.java | 45 ++- test/lspMobsimTests/MainRunLSPMobsimTest.java | 23 +- .../MainRunOnlyLSPMobsimTest.java | 23 +- ...ipleIterationsCollectionLSPMobsimTest.java | 206 ++++++++++ ...pleIterationsFirstReloadLSPMobsimTest.java | 249 ++++++++++++ ...ultipleIterationsMainRunLSPMobsimTest.java | 285 ++++++++++++++ ...leIterationsSecondReloadLSPMobsimTest.java | 311 +++++++++++++++ ...ltipleItreationsCompleteLSPMobsimTest.java | 353 +++++++++++++++++ ...tipleShipmentsCollectionLSPMobsimTest.java | 203 ++++++++++ ...ultipleShipmentsCompleteLSPMobsimTest.java | 353 +++++++++++++++++ ...ipleShipmentsFirstReloadLSPMobsimTest.java | 249 ++++++++++++ ...MultipleShipmentsMainRunLSPMobsimTest.java | 285 ++++++++++++++ ...pleShipmentsSecondReloadLSPMobsimTest.java | 311 +++++++++++++++ ...ultipleShipmentsCompleteLSPMobsimTest.java | 370 ++++++++++++++++++ .../SecondReloadLSPMobsimTest.java | 28 +- .../CollectionLSPSchedulingTest.java | 14 + .../CompleteLSPSchedulingTest.java | 25 +- .../FirstReloadLSPSchedulingTest.java | 17 +- .../MainRunLSPSchedulingTest.java | 18 +- ...eShipmentsCollectionLSPSchedulingTest.java | 15 +- ...pleShipmentsCompleteLSPSchedulingTest.java | 22 +- ...ShipmentsFirstReloadLSPSchedulingTest.java | 15 +- ...ipleShipmentsMainRunLSPSchedulingTest.java | 16 +- ...hipmentsSecondReloadLSPSchedulingTest.java | 22 +- .../SecondReloadLSPSchedulingTest.java | 22 +- .../MutualReplanningAndOfferUpdateTest.java | 4 +- test/testSuite/FTLabTestSuite.java | 22 ++ 30 files changed, 3450 insertions(+), 122 deletions(-) create mode 100644 test/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java create mode 100644 test/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java create mode 100644 test/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java index c567b88ad15..2bf4bc20715 100644 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ b/test/cascadingInfoTest/CascadingInfoTest.java @@ -150,7 +150,7 @@ public void initialize() { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); Random random = new Random(1); - int capacityDemand = random.nextInt(4); + int capacityDemand = 1 + random.nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/test/lspMobsimTests/CollectionLSPMobsimTest.java index 21fabdd9982..b6b9e937b5e 100644 --- a/test/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/test/lspMobsimTests/CollectionLSPMobsimTest.java @@ -43,6 +43,7 @@ import lsp.LogisticsSolutionImpl; import lsp.ShipmentAssigner; import lsp.SolutionScheduler; +import lsp.resources.CarrierResource; import lsp.resources.Resource; import lsp.replanning.LSPReplanningModuleImpl; import lsp.scoring.LSPScoringModuleImpl; @@ -80,9 +81,6 @@ public void initialize() { Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); Link collectionLink = network.getLinks().get(collectionLinkId); - if (collectionLink == null) { - System.exit(1); - } Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); carrierVehicle.setVehicleType(collectionType); @@ -126,6 +124,7 @@ public void initialize() { resourcesList.add(collectionAdapter); SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); @@ -136,12 +135,12 @@ public void initialize() { for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); + //Random random = new Random(1); + int capacityDemand = 1+ new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { - Collections.shuffle(linkList, random); + Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && @@ -173,7 +172,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(2); + config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -188,18 +187,20 @@ public void testCollectionLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + //Das muss besser in den SchedulingTest rein + assertTrue(collectionLSP.getResources().iterator().next() == collectionAdapter); + CarrierResource carrierResource = (CarrierResource) collectionAdapter; + assertTrue(carrierResource.getCarrier() == carrier); + assertTrue(carrier.getServices().size() == 1); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); } - - } - } - + } + } } diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/test/lspMobsimTests/CompleteLSPMobsimTest.java index 30c52971443..37b2a0a5d52 100644 --- a/test/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/test/lspMobsimTests/CompleteLSPMobsimTest.java @@ -1,5 +1,6 @@ package lspMobsimTests; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -76,7 +77,6 @@ public void initialize() { CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - collectionScheduler.setBufferTime(300); Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); @@ -123,7 +123,6 @@ public void initialize() { ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); ReloadingPointScheduler reloadScheduler = firstReloadingSchedulerBuilder.build(); - reloadScheduler.setBufferTime(300); firstReloadingPointBuilder.setReloadingScheduler(reloadScheduler); Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); @@ -160,7 +159,6 @@ public void initialize() { MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - mainRunScheduler.setBufferTime(300); Id mainRunId = Id.create("MainRunAdapter", Resource.class); MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); @@ -178,7 +176,6 @@ public void initialize() { secondSchedulerBuilder.setCapacityNeedFixed(10); secondSchedulerBuilder.setCapacityNeedLinear(1); ReloadingPointScheduler secondScheduler = secondSchedulerBuilder.build(); - secondScheduler.setBufferTime(300); Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); @@ -266,6 +263,7 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); completeLSP = completeLSPBuilder.build(); @@ -274,7 +272,7 @@ public void initialize() { for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(4); + int capacityDemand = 1 + rand.nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { @@ -325,7 +323,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(2); + config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -339,15 +337,14 @@ public void testFirstReloadLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + "\t" + scheduleElements.get(i).getResourceId() +"\t"+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + "\t End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + "\t" + logElements.get(i).getResourceId() +"\t" + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + "\t End: " + logElements.get(i).getEndTime()); - } + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } } } } diff --git a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java index 7e47245b4c9..12d73283e1c 100644 --- a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -1,5 +1,6 @@ package lspMobsimTests; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -46,6 +47,7 @@ import lsp.LogisticsSolutionImpl; import lsp.ShipmentAssigner; import lsp.SolutionScheduler; +import lsp.resources.CarrierResource; import lsp.resources.Resource; import lsp.replanning.LSPReplanningModuleImpl; import lsp.scoring.LSPScoringModuleImpl; @@ -60,8 +62,12 @@ public class FirstReloadLSPMobsimTest { private ShipmentAssigner assigner; private LSPPlanImpl completePlan; private SolutionScheduler simpleScheduler; + private Carrier collectionCarrier; + private LogisticsSolutionElement collectionElement; + private LogisticsSolutionElement firstReloadElement; private LSP lsp; - + private Resource collectionAdapter; + private Resource firstReloadingPointAdapter; @Before public void initialize() { @@ -93,7 +99,7 @@ public void initialize() { collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); collectionCarrier.setCarrierCapabilities(collectionCapabilities); @@ -102,12 +108,12 @@ public void initialize() { collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); collectionAdapterBuilder.setCarrier(collectionCarrier); collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); + collectionAdapter = collectionAdapterBuilder.build(); Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); collectionBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionBuilder.build(); + collectionElement = collectionBuilder.build(); ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); @@ -119,12 +125,12 @@ public void initialize() { ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + firstReloadElement = firstReloadingElementBuilder.build(); collectionElement.setNextElement(firstReloadElement); firstReloadElement.setPreviousElement(collectionElement); @@ -151,20 +157,21 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); + //Random random = new Random(1); + int capacityDemand = 1 + new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { - Collections.shuffle(linkList, random); + Collections.shuffle(linkList); Link pendingToLink = linkList.get(0); if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && @@ -179,7 +186,7 @@ public void initialize() { } while(true) { - Collections.shuffle(linkList, random); + Collections.shuffle(linkList); Link pendingFromLink = linkList.get(0); if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && @@ -216,6 +223,7 @@ public void initialize() { config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); } + @Test public void testFirstReloadLSPMobsim() { @@ -226,15 +234,14 @@ public void testFirstReloadLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); - } - } } } diff --git a/test/lspMobsimTests/MainRunLSPMobsimTest.java b/test/lspMobsimTests/MainRunLSPMobsimTest.java index fcf4183258d..37a48af8e69 100644 --- a/test/lspMobsimTests/MainRunLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunLSPMobsimTest.java @@ -1,5 +1,6 @@ package lspMobsimTests; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -195,15 +196,16 @@ public void initialize() { resourcesList.add(mainRunAdapter); simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(4); + int capacityDemand = 1 + new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { @@ -268,15 +270,14 @@ public void testFirstReloadLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); - } - + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } } } } diff --git a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java index dd29037e73c..31110070860 100644 --- a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java +++ b/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -1,5 +1,6 @@ package lspMobsimTests; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -135,15 +136,16 @@ public void initialize() { resourcesList.add(mainRunAdapter); simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(4); + int capacityDemand = 1 + new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { @@ -208,15 +210,14 @@ public void testFirstReloadLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); - } - + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } } } } diff --git a/test/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java b/test/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java new file mode 100644 index 00000000000..ac59ceb03d4 --- /dev/null +++ b/test/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java @@ -0,0 +1,206 @@ +package lspMobsimTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.ScheduledTour; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleIterationsCollectionLSPMobsimTest { + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private int numberOfShipments; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + numberOfShipments = 1 + new Random().nextInt(50); + for(int i = 1; i < 1 + numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1 + new Random().nextInt(10)); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPMobsim() { + + for(LSPShipment shipment : collectionLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } + +} diff --git a/test/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java b/test/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java new file mode 100644 index 00000000000..bbfdbcc5ce3 --- /dev/null +++ b/test/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java @@ -0,0 +1,249 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleIterationsFirstReloadLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private Carrier collectionCarrier; + private LogisticsSolutionElement collectionElement; + private LogisticsSolutionElement firstReloadElement; + private LSP lsp; + private Resource collectionAdapter; + private Resource firstReloadingPointAdapter; + private int numberOfShipments; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + firstReloadElement = firstReloadingElementBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + numberOfShipments = 1 + new Random().nextInt(50); + + for(int i = 1; i < 1+ numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1 + new Random().nextInt(10)); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testFirstReloadLSPMobsim() { + + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} diff --git a/test/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java b/test/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java new file mode 100644 index 00000000000..c7d4848cb13 --- /dev/null +++ b/test/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java @@ -0,0 +1,285 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleIterationsMainRunLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private int numberOfShipments; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner);; + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + numberOfShipments = 1 + new Random().nextInt(50); + for(int i = 1; i < 1 + numberOfShipments ; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1 + new Random().nextInt(10)); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} diff --git a/test/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java b/test/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java new file mode 100644 index 00000000000..736ef448732 --- /dev/null +++ b/test/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java @@ -0,0 +1,311 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; + + + +public class MultipleIterationsSecondReloadLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private int numberOfShipments; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + numberOfShipments = 1 + new Random().nextInt(50); + for(int i = 1; i < 1 + numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1 + new Random().nextInt(10)); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} diff --git a/test/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java b/test/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java new file mode 100644 index 00000000000..f3b995d1982 --- /dev/null +++ b/test/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java @@ -0,0 +1,353 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleItreationsCompleteLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP completeLSP; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + ReloadingPointScheduler reloadScheduler = firstReloadingSchedulerBuilder.build(); + firstReloadingPointBuilder.setReloadingScheduler(reloadScheduler); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + ReloadingPointScheduler secondScheduler = secondSchedulerBuilder.build(); + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + + secondReloadingPointBuilder.setReloadingScheduler(secondScheduler); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(14 2) (14 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + //Random rand = new Random(1); + int numberOfShipments = new Random().nextInt(50); + + for(int i = 1; i < 1 + numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + completeLSP.assignShipmentToLSP(shipment); + } + completeLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(completeLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1 + new Random().nextInt(10)); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCompleteLSPMobsim() { + for(LSPShipment shipment : completeLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} + diff --git a/test/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java b/test/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java new file mode 100644 index 00000000000..46c24b0b9db --- /dev/null +++ b/test/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java @@ -0,0 +1,203 @@ +package lspMobsimTests; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsCollectionLSPMobsimTest { + private Network network; + private LSP collectionLSP; + private Carrier carrier; + private Resource collectionAdapter; + private LogisticsSolutionElement collectionElement; + private int numberOfShipments; + + @Before + public void initialize() { + + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); + vehicleTypeBuilder.setCapacity(10); + vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + vehicleTypeBuilder.setCostPerTimeUnit(0.38); + vehicleTypeBuilder.setFixCost(49); + vehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = vehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Link collectionLink = network.getLinks().get(collectionLinkId); + Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); + carrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(collectionType); + capabilitiesBuilder.addVehicle(carrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities capabilities = capabilitiesBuilder.build(); + carrier = CarrierImpl.newInstance(carrierId); + carrier.setCarrierCapabilities(capabilities); + + + Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); + adapterBuilder.setCollectionScheduler(scheduler); + adapterBuilder.setCarrier(carrier); + adapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = adapterBuilder.build(); + + Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); + collectionElementBuilder.setResource(collectionAdapter); + collectionElement = collectionElementBuilder.build(); + + Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); + LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); + collectionSolutionBuilder.addSolutionElement(collectionElement); + LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); + + ShipmentAssigner assigner = new DeterministicShipmentAssigner(); + LSPPlanImpl collectionPlan = new LSPPlanImpl(); + collectionPlan.setAssigner(assigner); + collectionPlan.addSolution(collectionSolution); + + LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); + collectionLSPBuilder.setInitialPlan(collectionPlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + collectionLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + + SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + collectionLSPBuilder.setSolutionScheduler(simpleScheduler); + collectionLSP = collectionLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + Id toLinkId = collectionLinkId; + + numberOfShipments = 1 + new Random().nextInt(50); + for(int i = 1; i < 1+ numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + } + + builder.setToLinkId(toLinkId); + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + collectionLSP.assignShipmentToLSP(shipment); + } + collectionLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(collectionLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCollectionLSPMobsim() { + + for(LSPShipment shipment : collectionLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } + +} diff --git a/test/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java b/test/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java new file mode 100644 index 00000000000..8cd2c753b20 --- /dev/null +++ b/test/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java @@ -0,0 +1,353 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsCompleteLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP completeLSP; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + ReloadingPointScheduler reloadScheduler = firstReloadingSchedulerBuilder.build(); + firstReloadingPointBuilder.setReloadingScheduler(reloadScheduler); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + ReloadingPointScheduler secondScheduler = secondSchedulerBuilder.build(); + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + + secondReloadingPointBuilder.setReloadingScheduler(secondScheduler); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(14 2) (14 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + //Random rand = new Random(1); + int numberOfShipments = new Random().nextInt(50); + + for(int i = 1; i < 1 + numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + completeLSP.assignShipmentToLSP(shipment); + } + completeLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(completeLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(1 + new Random().nextInt(10)); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCompleteLSPMobsim() { + for(LSPShipment shipment : completeLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} + diff --git a/test/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java b/test/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java new file mode 100644 index 00000000000..e1678963ff1 --- /dev/null +++ b/test/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java @@ -0,0 +1,249 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsFirstReloadLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private Carrier collectionCarrier; + private LogisticsSolutionElement collectionElement; + private LogisticsSolutionElement firstReloadElement; + private LSP lsp; + private Resource collectionAdapter; + private Resource firstReloadingPointAdapter; + private int numberOfShipments; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + firstReloadElement = firstReloadingElementBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + numberOfShipments = 1 + new Random().nextInt(50); + + for(int i = 1; i < 1+ numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + //Random random = new Random(1); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testFirstReloadLSPMobsim() { + + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} diff --git a/test/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java b/test/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java new file mode 100644 index 00000000000..167ef38d68d --- /dev/null +++ b/test/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java @@ -0,0 +1,285 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class MultipleShipmentsMainRunLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private int numberOfShipments; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner);; + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + + numberOfShipments = 1 + new Random().nextInt(50); + for(int i = 1; i < 1 + numberOfShipments ; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} diff --git a/test/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java b/test/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java new file mode 100644 index 00000000000..be84fbe2b71 --- /dev/null +++ b/test/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java @@ -0,0 +1,311 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; + + + +public class MultipleShipmentsSecondReloadLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP lsp; + private int numberOfShipments; + + @Before + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + lsp = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + numberOfShipments = 1 + new Random().nextInt(50); + for(int i = 1; i < 1 + numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + lsp.assignShipmentToLSP(shipment); + } + lsp.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(lsp); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(4); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testFirstReloadLSPMobsim() { + for(LSPShipment shipment : lsp.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + assertTrue(shipment.getSchedule().getPlanElements().size() == shipment.getLog().getPlanElements().size()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } +} diff --git a/test/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java b/test/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java new file mode 100644 index 00000000000..8ecac22d6dc --- /dev/null +++ b/test/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java @@ -0,0 +1,370 @@ +package lspMobsimTests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +import org.junit.Before; +import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierCapabilities; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.core.config.Config; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.network.io.MatsimNetworkReader; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; + +import lsp.usecase.CollectionCarrierAdapter; +import lsp.usecase.CollectionCarrierScheduler; +import lsp.usecase.DeterministicShipmentAssigner; +import lsp.usecase.DistributionCarrierAdapter; +import lsp.usecase.DistributionCarrierScheduler; +import lsp.usecase.MainRunCarrierAdapter; +import lsp.usecase.MainRunCarrierScheduler; +import lsp.usecase.ReloadingPoint; +import lsp.usecase.ReloadingPointScheduler; +import lsp.usecase.SimpleForwardSolutionScheduler; +import lsp.controler.LSPModule; +import lsp.events.EventUtils; +import lsp.LSP; +import lsp.LSPImpl; +import lsp.LSPPlanImpl; +import lsp.LSPs; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.LogisticsSolutionElementImpl; +import lsp.LogisticsSolutionImpl; +import lsp.ShipmentAssigner; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.replanning.LSPReplanningModuleImpl; +import lsp.scoring.LSPScoringModuleImpl; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.AbstractShipmentPlanElementComparator; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class RepeatedMultipleShipmentsCompleteLSPMobsimTest { + private Network network; + private LogisticsSolution completeSolution; + private ShipmentAssigner assigner; + private LSPPlanImpl completePlan; + private SolutionScheduler simpleScheduler; + private LSP completeLSP; + + + public void initialize() { + Config config = new Config(); + config.addCoreModules(); + Scenario scenario = ScenarioUtils.createScenario(config); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + this.network = scenario.getNetwork(); + + + CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); + collectionVehicleTypeBuilder.setCapacity(10); + collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + collectionVehicleTypeBuilder.setFixCost(49); + collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); + + Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); + Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); + CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); + collectionCarrierVehicle.setVehicleType(collectionType); + + CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + collectionCapabilitiesBuilder.addType(collectionType); + collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); + collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); + Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); + collectionCarrier.setCarrierCapabilities(collectionCapabilities); + + + Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); + CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); + collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); + collectionAdapterBuilder.setCarrier(collectionCarrier); + collectionAdapterBuilder.setLocationLinkId(collectionLinkId); + Resource collectionAdapter = collectionAdapterBuilder.build(); + + Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); + collectionBuilder.setResource(collectionAdapter); + LogisticsSolutionElement collectionElement = collectionBuilder.build(); + + ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); + firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); + + + Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); + Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); + + ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); + ReloadingPointScheduler reloadScheduler = firstReloadingSchedulerBuilder.build(); + firstReloadingPointBuilder.setReloadingScheduler(reloadScheduler); + Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); + + Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); + firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); + LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); + + Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); + Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); + mainRunVehicleTypeBuilder.setCapacity(30); + mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); + mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); + mainRunVehicleTypeBuilder.setFixCost(120); + mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); + + + Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); + Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); + CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); + mainRunCarrierVehicle.setVehicleType(mainRunType); + + + CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + mainRunCapabilitiesBuilder.addType(mainRunType); + mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); + mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); + Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); + mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); + + + + MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); + Id mainRunId = Id.create("MainRunAdapter", Resource.class); + MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); + mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); + mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); + mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); + mainRunAdapterBuilder.setCarrier(mainRunCarrier); + Resource mainRunAdapter = mainRunAdapterBuilder.build(); + + Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); + mainRunBuilder.setResource(mainRunAdapter); + LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); + + ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); + secondSchedulerBuilder.setCapacityNeedFixed(10); + secondSchedulerBuilder.setCapacityNeedLinear(1); + ReloadingPointScheduler secondScheduler = secondSchedulerBuilder.build(); + + Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); + Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); + + ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); + + secondReloadingPointBuilder.setReloadingScheduler(secondScheduler); + Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); + + Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); + secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); + LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); + + DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); + Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); + Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); + CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); + dsitributionVehicleTypeBuilder.setCapacity(10); + dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); + dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); + dsitributionVehicleTypeBuilder.setFixCost(49); + dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); + CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); + + Id distributionLinkId = Id.createLinkId("(14 2) (14 3)"); + Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); + CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); + distributionCarrierVehicle.setVehicleType(distributionType); + + CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); + capabilitiesBuilder.addType(distributionType); + capabilitiesBuilder.addVehicle(distributionCarrierVehicle); + capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); + CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); + Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); + carrier.setCarrierCapabilities(distributionCapabilities); + + + Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); + DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); + distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); + distributionAdapterBuilder.setCarrier(carrier); + distributionAdapterBuilder.setLocationLinkId(distributionLinkId); + Resource distributionAdapter = distributionAdapterBuilder.build(); + + Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); + LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); + distributionBuilder.setResource(distributionAdapter); + LogisticsSolutionElement distributionElement = distributionBuilder.build(); + + collectionElement.setNextElement(firstReloadElement); + firstReloadElement.setPreviousElement(collectionElement); + firstReloadElement.setNextElement(mainRunElement); + mainRunElement.setPreviousElement(firstReloadElement); + mainRunElement.setNextElement(secondReloadElement); + secondReloadElement.setPreviousElement(mainRunElement); + secondReloadElement.setNextElement(distributionElement); + distributionElement.setPreviousElement(secondReloadElement); + + Id solutionId = Id.create("SolutionId", LogisticsSolution.class); + LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); + completeSolutionBuilder.addSolutionElement(collectionElement); + completeSolutionBuilder.addSolutionElement(firstReloadElement); + completeSolutionBuilder.addSolutionElement(mainRunElement); + completeSolutionBuilder.addSolutionElement(secondReloadElement); + completeSolutionBuilder.addSolutionElement(distributionElement); + completeSolution = completeSolutionBuilder.build(); + + assigner = new DeterministicShipmentAssigner(); + completePlan = new LSPPlanImpl(); + completePlan.setAssigner(assigner); + completePlan.addSolution(completeSolution); + + LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); + completeLSPBuilder.setInitialPlan(completePlan); + Id collectionLSPId = Id.create("CollectionLSP", LSP.class); + completeLSPBuilder.setId(collectionLSPId); + ArrayList resourcesList = new ArrayList(); + resourcesList.add(collectionAdapter); + resourcesList.add(firstReloadingPointAdapter); + resourcesList.add(mainRunAdapter); + resourcesList.add(secondReloadingPointAdapter); + resourcesList.add(distributionAdapter); + + + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); + completeLSPBuilder.setSolutionScheduler(simpleScheduler); + completeLSP = completeLSPBuilder.build(); + + ArrayList linkList = new ArrayList(network.getLinks().values()); + //Random rand = new Random(1); + int numberOfShipments = new Random().nextInt(50); + + for(int i = 1; i < 1 + numberOfShipments; i++) { + Id id = Id.create(i, LSPShipment.class); + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); + int capacityDemand = 1 + new Random().nextInt(4); + builder.setCapacityDemand(capacityDemand); + + while(true) { + Collections.shuffle(linkList); + Link pendingToLink = linkList.get(0); + if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && + pendingToLink.getFromNode().getCoord().getY() <= 4000 && + pendingToLink.getFromNode().getCoord().getX() >= 14000 && + pendingToLink.getToNode().getCoord().getX() <= 18000 && + pendingToLink.getToNode().getCoord().getY() <= 4000 && + pendingToLink.getToNode().getCoord().getX() >= 14000 )) { + builder.setToLinkId(pendingToLink.getId()); + break; + } + + } + + while(true) { + Collections.shuffle(linkList); + Link pendingFromLink = linkList.get(0); + if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && + pendingFromLink.getFromNode().getCoord().getY() <= 4000 && + pendingFromLink.getToNode().getCoord().getX() <= 4000 && + pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { + builder.setFromLinkId(pendingFromLink.getId()); + break; + } + + } + + TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setEndTimeWindow(endTimeWindow); + TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); + builder.setStartTimeWindow(startTimeWindow); + builder.setServiceTime(capacityDemand * 60); + LSPShipment shipment = builder.build(); + completeLSP.assignShipmentToLSP(shipment); + } + completeLSP.scheduleSoultions(); + + ArrayList lspList = new ArrayList(); + lspList.add(completeLSP); + LSPs lsps = new LSPs(lspList); + + Controler controler = new Controler(config); + + LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); + + controler.addOverridingModule(module); + config.controler().setFirstIteration(0); + config.controler().setLastIteration(0); + config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + controler.run(); + } + + @Test + public void testCompleteLSPMobsim() { + int numberOfIterations = 1 + new Random().nextInt(10); + for(int i = 0; i < numberOfIterations; i++) { + initialize(); + for(LSPShipment shipment : completeLSP.getShipments()) { + assertFalse(shipment.getLog().getPlanElements().isEmpty()); + ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); + Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); + ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); + Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + if(scheduleElement.getElementType() != logElement.getElementType()) { + System.out.println(scheduleElement.getElementType()); + System.out.println(logElement.getElementType()); + for(int j = 0; j < shipment.getSchedule().getPlanElements().size(); j++) { + System.out.println("Scheduled: " + scheduleElements.get(j).getSolutionElement().getId() + " " + scheduleElements.get(j).getResourceId()+ " " + scheduleElements.get(j).getElementType() + " Start: " + scheduleElements.get(j).getStartTime() + " End: " + scheduleElements.get(j).getEndTime()); + } + System.out.println(); + for(int j = 0; j < shipment.getLog().getPlanElements().size(); j++) { + System.out.println("Logged: " + logElements.get(j).getSolutionElement().getId() + " " + logElements.get(j).getResourceId() +" " + logElements.get(j).getElementType() + " Start: " + logElements.get(j).getStartTime() + " End: " + logElements.get(j).getEndTime()); + } + System.out.println(); + } + + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); + } + } + } + } +} + diff --git a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java index 3361390a03d..a41db6a4452 100644 --- a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java +++ b/test/lspMobsimTests/SecondReloadLSPMobsimTest.java @@ -1,5 +1,6 @@ package lspMobsimTests; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -219,19 +220,18 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); resourcesList.add(mainRunAdapter); resourcesList.add(secondReloadingPointAdapter); - - - + simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); ArrayList linkList = new ArrayList(network.getLinks().values()); - for(int i = 1; i < 4; i++) { + for(int i = 1; i < 2; i++) { Id id = Id.create(i, LSPShipment.class); LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(4); + int capacityDemand = 1 + new Random().nextInt(4); builder.setCapacityDemand(capacityDemand); while(true) { @@ -282,7 +282,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(4); + config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -297,16 +297,14 @@ public void testFirstReloadLSPMobsim() { Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); + + for(AbstractShipmentPlanElement scheduleElement : scheduleElements){ + AbstractShipmentPlanElement logElement = logElements.get(scheduleElements.indexOf(scheduleElement)); + assertTrue(scheduleElement.getElementType() == logElement.getElementType()); + assertTrue(scheduleElement.getResourceId() == logElement.getResourceId()); + assertTrue(scheduleElement.getSolutionElement() == logElement.getSolutionElement()); + assertEquals(scheduleElement.getStartTime(), logElement.getStartTime(), 300); } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); - } - } } - } diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java index 6bd6e5b1568..5dda09ffd44 100644 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java @@ -236,5 +236,19 @@ public void testCollectionLSPScheduling() { assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); assertTrue(serviceHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); } + + for(LogisticsSolution solution : collectionLSP.getSelectedPlan().getSolutions()) { + assertTrue(solution.getShipments().size() == 1); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } + } } diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java index 0e6b8e6260a..89584525b6d 100644 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java @@ -276,6 +276,7 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -379,18 +380,18 @@ public void testCompletedLSPScheduling() { assertTrue(planElements.get(8).getResourceId() == distributionAdapter.getId()); assertTrue(planElements.get(8).getSolutionElement() == distributionElement); - assertTrue(planElements.get(8).getStartTime() >= planElements.get(7).getEndTime()/ 1.0001); + assertTrue(planElements.get(8).getStartTime() >= (planElements.get(7).getEndTime()/ 1.0001) + 300); assertTrue(planElements.get(7).getElementType() == "HANDLE"); assertTrue(planElements.get(7).getEndTime() >= (0)); assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); assertTrue(planElements.get(7).getStartTime() >= (0)); assertTrue(planElements.get(7).getStartTime() <= (24*3600)); assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() == (planElements.get(6).getEndTime() +300)); assertTrue(planElements.get(6).getElementType() == "UNLOAD"); assertTrue(planElements.get(6).getEndTime() >= (0)); @@ -423,7 +424,7 @@ public void testCompletedLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + assertTrue(planElements.get(4).getStartTime() >= (planElements.get(3).getEndTime() / (1.0001)) + 300); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -434,7 +435,7 @@ public void testCompletedLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -628,7 +629,19 @@ public void testCompletedLSPScheduling() { } - + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + assertTrue(solution.getShipments().size() == 1); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } + } } diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java index c24c40878d3..2818a7fc9aa 100644 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java @@ -155,6 +155,7 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -235,7 +236,7 @@ public void testFirstReloadLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -327,5 +328,19 @@ public void testFirstReloadLSPScheduling() { assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); assertTrue(serviceHandler.getResourceId() == lsp.getResources().iterator().next().getId()); } + + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + assertTrue(solution.getShipments().size() == 1); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } + } } diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java index 366e693846b..33fc15398cf 100644 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java @@ -203,6 +203,7 @@ public void initialize() { resourcesList.add(mainRunAdapter); simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -305,7 +306,7 @@ public void testMainRunLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + assertTrue(planElements.get(4).getStartTime() >= ( planElements.get(3).getEndTime() / (1.0001)) + 300); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -316,7 +317,7 @@ public void testMainRunLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -451,5 +452,18 @@ public void testMainRunLSPScheduling() { assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); } + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + assertTrue(solution.getShipments().size() == 1); + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } + } } diff --git a/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java index 53f5ad588f4..4d2e7a6b1e4 100644 --- a/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java @@ -126,6 +126,7 @@ public void initialize() { resourcesList.add(collectionAdapter); SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); collectionLSPBuilder.setSolutionScheduler(simpleScheduler); collectionLSP = collectionLSPBuilder.build(); @@ -235,6 +236,18 @@ public void testCollectionLSPScheduling() { assertTrue(serviceHandler.getLspShipment() == shipment); assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); assertTrue(serviceHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); - } + } + + for(LogisticsSolution solution : collectionLSP.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } } } diff --git a/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java index 78d9a3321d0..3d8af0415ab 100644 --- a/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java @@ -276,6 +276,7 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -379,18 +380,18 @@ public void testCompletedLSPScheduling() { assertTrue(planElements.get(8).getResourceId() == distributionAdapter.getId()); assertTrue(planElements.get(8).getSolutionElement() == distributionElement); - assertTrue(planElements.get(8).getStartTime() >= planElements.get(7).getEndTime()/ 1.0001); + assertTrue(planElements.get(8).getStartTime() >= planElements.get(7).getEndTime()/ 1.0001 + 300); assertTrue(planElements.get(7).getElementType() == "HANDLE"); assertTrue(planElements.get(7).getEndTime() >= (0)); assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); assertTrue(planElements.get(7).getStartTime() >= (0)); assertTrue(planElements.get(7).getStartTime() <= (24*3600)); assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime() + 300); assertTrue(planElements.get(6).getElementType() == "UNLOAD"); assertTrue(planElements.get(6).getEndTime() >= (0)); @@ -423,7 +424,7 @@ public void testCompletedLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001) + 300); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -434,7 +435,7 @@ public void testCompletedLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime() + 300); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -628,6 +629,17 @@ public void testCompletedLSPScheduling() { } + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } } diff --git a/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java index c3910a1ae83..ab388f65868 100644 --- a/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java @@ -155,6 +155,7 @@ public void initialize() { simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -235,7 +236,7 @@ public void testFirstReloadLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime() + 300); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -327,5 +328,17 @@ public void testFirstReloadLSPScheduling() { assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); assertTrue(serviceHandler.getResourceId() == lsp.getResources().iterator().next().getId()); } + + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } } } diff --git a/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java index eaf680fb367..a63433dff0c 100644 --- a/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java @@ -203,6 +203,7 @@ public void initialize() { resourcesList.add(mainRunAdapter); simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -305,7 +306,7 @@ public void testMainRunLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001) + 300); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -316,7 +317,7 @@ public void testMainRunLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() +300)); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -451,5 +452,16 @@ public void testMainRunLSPScheduling() { assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); } + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } } } diff --git a/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java index 21d6504771a..fdd50ec1a97 100644 --- a/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -229,10 +229,9 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); resourcesList.add(mainRunAdapter); resourcesList.add(secondReloadingPointAdapter); - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -305,13 +304,13 @@ public void testSecondReloadLSPScheduling() { assertTrue(planElements.get(7).getElementType() == "HANDLE"); assertTrue(planElements.get(7).getEndTime() >= (0)); assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); assertTrue(planElements.get(7).getStartTime() >= (0)); assertTrue(planElements.get(7).getStartTime() <= (24*3600)); assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() == (planElements.get(6).getEndTime() + 300)); assertTrue(planElements.get(6).getElementType() == "UNLOAD"); assertTrue(planElements.get(6).getEndTime() >= (0)); @@ -344,7 +343,7 @@ public void testSecondReloadLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime()/ (1.0001)); + assertTrue(planElements.get(4).getStartTime() >= (planElements.get(3).getEndTime()/ (1.0001)) + 300); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -355,7 +354,7 @@ public void testSecondReloadLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -516,5 +515,16 @@ public void testSecondReloadLSPScheduling() { assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); } + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } } } diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java index 9acf7daee1c..63e8e8c83fd 100644 --- a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java +++ b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java @@ -229,10 +229,9 @@ public void initialize() { resourcesList.add(firstReloadingPointAdapter); resourcesList.add(mainRunAdapter); resourcesList.add(secondReloadingPointAdapter); - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); + simpleScheduler.setBufferTime(300); completeLSPBuilder.setSolutionScheduler(simpleScheduler); lsp = completeLSPBuilder.build(); @@ -305,13 +304,13 @@ public void testSecondReloadLSPScheduling() { assertTrue(planElements.get(7).getElementType() == "HANDLE"); assertTrue(planElements.get(7).getEndTime() >= (0)); assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); assertTrue(planElements.get(7).getStartTime() >= (0)); assertTrue(planElements.get(7).getStartTime() <= (24*3600)); assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime()); + assertTrue(planElements.get(7).getStartTime() == (planElements.get(6).getEndTime() + 300)); assertTrue(planElements.get(6).getElementType() == "UNLOAD"); assertTrue(planElements.get(6).getEndTime() >= (0)); @@ -344,7 +343,7 @@ public void testSecondReloadLSPScheduling() { assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001)); + assertTrue(planElements.get(4).getStartTime() >= (planElements.get(3).getEndTime() / (1.0001)) + 300); assertTrue(planElements.get(3).getElementType() == "HANDLE"); assertTrue(planElements.get(3).getEndTime() >= (0)); @@ -355,7 +354,7 @@ public void testSecondReloadLSPScheduling() { assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime()); + assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); assertTrue(planElements.get(2).getElementType() == "UNLOAD"); assertTrue(planElements.get(2).getEndTime() >= (0)); @@ -516,5 +515,16 @@ public void testSecondReloadLSPScheduling() { assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); } + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + assertTrue(element.getIncomingShipments().getShipments().isEmpty()); + if(element.getNextElement() != null) { + assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); + } + else { + assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); + } + } + } } } diff --git a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java index fba815da97a..e5d52ee392c 100644 --- a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java +++ b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java @@ -74,6 +74,7 @@ import testMutualReplanning.SimpleOfferTransferrer; +@SuppressWarnings("unused") public class MutualReplanningAndOfferUpdateTest { private LSPDecorator lsp; @@ -82,8 +83,7 @@ public class MutualReplanningAndOfferUpdateTest { private LinearOfferVisitor linearVisitor; private LogisticsSolutionDecorator solution; private double initialFixed; - private - double initialVariable; + private double initialVariable; @Before public void initialize() { diff --git a/test/testSuite/FTLabTestSuite.java b/test/testSuite/FTLabTestSuite.java index 05759a8d405..ec8b2fd9e0d 100644 --- a/test/testSuite/FTLabTestSuite.java +++ b/test/testSuite/FTLabTestSuite.java @@ -17,6 +17,17 @@ import lspMobsimTests.FirstReloadLSPMobsimTest; import lspMobsimTests.MainRunLSPMobsimTest; import lspMobsimTests.MainRunOnlyLSPMobsimTest; +import lspMobsimTests.MultipleIterationsCollectionLSPMobsimTest; +import lspMobsimTests.MultipleIterationsFirstReloadLSPMobsimTest; +import lspMobsimTests.MultipleIterationsMainRunLSPMobsimTest; +import lspMobsimTests.MultipleIterationsSecondReloadLSPMobsimTest; +import lspMobsimTests.MultipleItreationsCompleteLSPMobsimTest; +import lspMobsimTests.MultipleShipmentsCollectionLSPMobsimTest; +import lspMobsimTests.MultipleShipmentsCompleteLSPMobsimTest; +import lspMobsimTests.MultipleShipmentsFirstReloadLSPMobsimTest; +import lspMobsimTests.MultipleShipmentsMainRunLSPMobsimTest; +import lspMobsimTests.MultipleShipmentsSecondReloadLSPMobsimTest; +import lspMobsimTests.RepeatedMultipleShipmentsCompleteLSPMobsimTest; import lspMobsimTests.SecondReloadLSPMobsimTest; import lspPlanTests.CollectionLSPPlanTest; import lspPlanTests.CompleteLSPPlanTest; @@ -100,6 +111,17 @@ MultipleShipmentsSecondReloadLSPSchedulingTest.class, MultipleShipmentsCompleteLSPSchedulingTest.class, MultipleIterationsCollectionLSPScoringTest.class, + MultipleIterationsCollectionLSPMobsimTest.class, + MultipleIterationsFirstReloadLSPMobsimTest.class, + MultipleIterationsMainRunLSPMobsimTest.class, + MultipleIterationsSecondReloadLSPMobsimTest.class, + MultipleItreationsCompleteLSPMobsimTest.class, + MultipleShipmentsCollectionLSPMobsimTest.class, + MultipleShipmentsCompleteLSPMobsimTest.class, + MultipleShipmentsFirstReloadLSPMobsimTest.class, + MultipleShipmentsMainRunLSPMobsimTest.class, + MultipleShipmentsSecondReloadLSPMobsimTest.class, + RepeatedMultipleShipmentsCompleteLSPMobsimTest.class, }) public class FTLabTestSuite { From e10e7d8ff243b811779959da7a16e1348ec7a7e5 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 17:18:07 +0200 Subject: [PATCH 0041/1340] Deleted unused imports and removed console message used for debugging. --- test/lspScoringTests/TipEventHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/lspScoringTests/TipEventHandler.java b/test/lspScoringTests/TipEventHandler.java index 8110ad33c1d..97bb0a8c001 100644 --- a/test/lspScoringTests/TipEventHandler.java +++ b/test/lspScoringTests/TipEventHandler.java @@ -25,7 +25,6 @@ public void reset(int iteration) { @Override public void handleEvent(ServiceEndEvent event) { double tip = tipRandom.nextDouble() * 5; - System.out.println("ServiceEvent " + tip); tipSum += tip; } From 5388701893ab38bbe43fe15af2221caf39a9aac4 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 17:18:49 +0200 Subject: [PATCH 0042/1340] Changed code to prevent double scoring --- test/lspScoringTests/TipSimulationTracker.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/lspScoringTests/TipSimulationTracker.java b/test/lspScoringTests/TipSimulationTracker.java index 5185bc689a0..861f49aa649 100644 --- a/test/lspScoringTests/TipSimulationTracker.java +++ b/test/lspScoringTests/TipSimulationTracker.java @@ -38,10 +38,11 @@ public Collection getInfos() { @Override public void notifyAfterMobsim(AfterMobsimEvent event) { double tip = handler.getTip(); - InfoFunctionValue value = new InfoFunctionValueImpl("TIP IN EUR"); + info.getFunction().getValues().clear(); + InfoFunctionValue value = new InfoFunctionValueImpl<>("TIP IN EUR"); value.setValue(tip); info.getFunction().getValues().add(value); - } + } @Override public void reset() { From 125500867746f624f5b3fb3f277fdb0c291a1592 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 17:19:12 +0200 Subject: [PATCH 0043/1340] Removed unused imports and console message used for debugging --- test/lspScoringTests/TipEventHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/lspScoringTests/TipEventHandler.java b/test/lspScoringTests/TipEventHandler.java index 97bb0a8c001..f7a8dd35fad 100644 --- a/test/lspScoringTests/TipEventHandler.java +++ b/test/lspScoringTests/TipEventHandler.java @@ -2,8 +2,6 @@ import java.util.Random; -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; import lsp.events.ServiceEndEvent; import lsp.events.ServiceEndEventHandler; From ffb588b99e2563daf908a03d8c7b3075000a8a52 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 17:20:17 +0200 Subject: [PATCH 0044/1340] Removed code used for debugging and changes last iteration from 0 to 1. --- test/lspScoringTests/CollectionLSPScoringTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/test/lspScoringTests/CollectionLSPScoringTest.java index dd2d932080e..2e4b42300bf 100644 --- a/test/lspScoringTests/CollectionLSPScoringTest.java +++ b/test/lspScoringTests/CollectionLSPScoringTest.java @@ -65,7 +65,7 @@ public class CollectionLSPScoringTest { private TipSimulationTracker tipTracker; private TipInfo info; private InfoFunction function; - private InfoFunctionValue value; + private InfoFunctionValueImpl value; private int numberOfShipments = 25; @Before @@ -90,9 +90,6 @@ public void initialize() { Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); Link collectionLink = network.getLinks().get(collectionLinkId); - if (collectionLink == null) { - System.exit(1); - } Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); carrierVehicle.setVehicleType(collectionType); @@ -196,7 +193,7 @@ public void initialize() { controler.addOverridingModule(module); config.controler().setFirstIteration(0); - config.controler().setLastIteration(1); + config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.network().setInputFile("input\\lsp\\network\\2regions.xml"); controler.run(); @@ -210,6 +207,12 @@ public void testCollectionLSPScoring() { .size() == numberOfShipments); assertTrue(collectionLSP.getSelectedPlan().getScore() > 0); assertTrue(collectionLSP.getSelectedPlan().getScore() <= (numberOfShipments * 5)); + /*noch zu testen + * tipTracker + * InfoFunction + * Info + * Scorer + */ } } From 80c300e8d3d4adc87d335162ab63ba20f8db1f91 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Tue, 8 May 2018 17:23:49 +0200 Subject: [PATCH 0045/1340] Removed unused imports --- .../ExampleCheckRequirementsOfOfferTransferrer.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java index d4e30b621b7..ded16d1ebff 100644 --- a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java +++ b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java @@ -1,10 +1,7 @@ package example.requirementsChecking; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Random; import org.matsim.api.core.v01.Id; @@ -16,7 +13,6 @@ import org.matsim.contrib.freight.carrier.CarrierImpl; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; @@ -41,8 +37,6 @@ import lsp.LogisticsSolutionElementImpl; import lsp.SolutionScheduler; import lsp.resources.Resource; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; import lsp.shipment.Requirement; import lsp.usecase.CollectionCarrierAdapter; import lsp.usecase.CollectionCarrierScheduler; From f328f98b95d95978552a4ebdeb842d4a605a8ab9 Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 16:18:34 +0200 Subject: [PATCH 0046/1340] rearrange directories; add geotools to pom.xml --- pom.xml | 8 +- .../controler/InitialDemandAssigner.java | 68 ---- src/demand/controler/MutualModule.java | 112 ------ src/demand/controler/SupplyRescheduler.java | 26 -- src/demand/decoratedLSP/DefaultAssigner.java | 32 -- src/demand/decoratedLSP/LSPDecorator.java | 22 -- src/demand/decoratedLSP/LSPDecorators.java | 40 --- src/demand/decoratedLSP/LSPPlanDecorator.java | 20 -- .../LSPPlanWithOfferTransferrer.java | 114 ------- src/demand/decoratedLSP/LSPWithOffers.java | 319 ----------------- .../LogisticsSolutionDecorator.java | 15 - src/demand/demandAgent/DemandAgent.java | 15 - src/demand/demandAgent/DemandAgentImpl.java | 67 ---- src/demand/demandObject/DemandObject.java | 41 --- src/demand/demandObject/DemandObjectImpl.java | 322 ------------------ src/demand/demandObject/DemandObjects.java | 37 -- src/demand/demandObject/DemandPlan.java | 19 -- .../demandObject/DemandPlanGenerator.java | 11 - src/demand/demandObject/DemandPlanImpl.java | 95 ------ src/demand/demandObject/OfferRequester.java | 12 - src/demand/demandObject/ShipperShipment.java | 24 -- .../demandObject/ShipperShipmentImpl.java | 140 -------- .../DemandPlanStrategyImpl.java | 115 ------- .../mutualReplanning/DemandReplanner.java | 17 - .../mutualReplanning/DemandReplannerImpl.java | 64 ---- .../LSPWithOffersReplanner.java | 80 ----- .../MutualReplanningModule.java | 37 -- .../MutualReplanningModuleImpl.java | 41 --- .../OfferReplanningStrategyModule.java | 71 ---- .../OfferReplanningStrategyModuleImpl.java | 52 --- src/demand/offer/DefaultOfferImpl.java | 53 --- src/demand/offer/Offer.java | 17 - src/demand/offer/OfferFactory.java | 22 -- src/demand/offer/OfferFactoryImpl.java | 74 ---- src/demand/offer/OfferTransferrer.java | 16 - src/demand/offer/OfferTransferrerImpl.java | 38 --- src/demand/offer/OfferUpdater.java | 12 - src/demand/offer/OfferUpdaterImpl.java | 48 --- src/demand/offer/OfferVisitor.java | 10 - src/demand/scoring/DemandScorer.java | 10 - .../scoring/MutualScoringModuleImpl.java | 46 --- .../utilityFunctions/UtilityFunction.java | 11 - .../lsp/ForwardSolutionSchedulerImpl.java | 135 ++++++++ src/main/java/lsp/HasEventHandlers.java | 10 + src/main/java/lsp/LSP.java | 42 +++ src/main/java/lsp/LSPImpl.java | 238 +++++++++++++ src/main/java/lsp/LSPPlan.java | 21 ++ src/main/java/lsp/LSPPlanImpl.java | 62 ++++ src/main/java/lsp/LSPs.java | 36 ++ src/main/java/lsp/LogisticsSolution.java | 37 ++ .../java/lsp/LogisticsSolutionElement.java | 47 +++ .../lsp/LogisticsSolutionElementImpl.java | 153 +++++++++ .../java/lsp/LogisticsSolutionImpl.java} | 102 ++---- src/main/java/lsp/ShipmentAssigner.java | 10 + src/main/java/lsp/ShipmentTuple.java | 23 ++ src/main/java/lsp/SolutionScheduler.java | 12 + src/main/java/lsp/WaitingShipments.java | 17 + src/main/java/lsp/WaitingShipmentsImpl.java | 43 +++ .../controler/FreightControlerListener.java | 9 + .../lsp/controler/LSPControlerListener.java} | 172 +++++----- src/main/java/lsp/controler/LSPModule.java | 67 ++++ .../java/lsp/controler/LSPRescheduler.java} | 35 +- .../lsp/controler/MobSimVehicleRoute.java | 35 ++ .../LSPPlanStrategyManagerFactory.java | 13 + .../java/lsp/replanning/LSPReplanner.java | 15 + .../java/lsp/replanning/LSPReplannerImpl.java | 49 +++ .../lsp/replanning/LSPReplanningModule.java | 10 + .../replanning/LSPReplanningModuleImpl.java | 30 ++ src/main/java/lsp/scoring/LSPScorer.java | 9 + .../java/lsp/scoring/LSPScoringModule.java} | 8 +- .../lsp/scoring/LSPScoringModuleImpl.java | 30 ++ src/main/java/lsp/scoring/Scorer.java | 8 + .../lsp/shipment/AbstractShipmentPlan.java | 19 ++ .../shipment/AbstractShipmentPlanElement.java | 20 ++ ...AbstractShipmentPlanElementComparator.java | 25 ++ src/main/java/lsp/shipment/LSPShipment.java | 43 +++ .../java/lsp/shipment/LSPShipmentImpl.java | 200 +++++++++++ src/main/java/lsp/shipment/LSPShipments.java | 39 +++ src/main/java/lsp/shipment/Log.java | 70 ++++ .../lsp/shipment/LoggedShipmentHandle.java | 101 ++++++ .../java/lsp/shipment/LoggedShipmentLoad.java | 108 ++++++ .../lsp/shipment/LoggedShipmentTransport.java | 127 +++++++ .../lsp/shipment/LoggedShipmentUnload.java | 105 ++++++ src/main/java/lsp/shipment/Requirement.java | 9 + src/main/java/lsp/shipment/Schedule.java | 77 +++++ .../lsp/shipment/ScheduledShipmentHandle.java | 98 ++++++ .../lsp/shipment/ScheduledShipmentLoad.java | 129 +++++++ .../shipment/ScheduledShipmentTransport.java | 141 ++++++++ .../lsp/shipment/ScheduledShipmentUnload.java | 128 +++++++ .../java/lsp/shipment/ShipmentComparator.java | 21 ++ .../lsp/usecase/CollectionCarrierAdapter.java | 172 ++++++++++ .../usecase/CollectionCarrierScheduler.java | 269 +++++++++++++++ .../CollectionServiceEventHandler.java | 93 +++++ .../CollectionTourEndEventHandler.java | 116 +++++++ .../DeterministicShipmentAssigner.java | 27 ++ .../usecase/DistributionCarrierAdapter.java | 169 +++++++++ .../usecase/DistributionCarrierScheduler.java | 320 +++++++++++++++++ .../DistributionServiceEventHandler.java | 85 +++++ .../DistributionStartEventHandler.java | 113 ++++++ .../usecase/FreightLinkEnterEventHandler.java | 11 + .../java/lsp/usecase/LSPShipmentMaker.java | 61 ++++ .../lsp/usecase/MainRunCarrierAdapter.java | 158 +++++++++ .../lsp/usecase/MainRunCarrierScheduler.java | 279 +++++++++++++++ .../lsp/usecase/MainRunEndEventHandler.java | 112 ++++++ .../lsp/usecase/MainRunStartEventHandler.java | 116 +++++++ src/main/java/lsp/usecase/NetworkMaker.java | 147 ++++++++ src/main/java/lsp/usecase/ReloadingPoint.java | 135 ++++++++ .../usecase/ReloadingPointEventHandler.java | 181 ++++++++++ .../lsp/usecase/ReloadingPointScheduler.java | 127 +++++++ .../SimpleForwardSolutionScheduler.java | 63 ++++ 110 files changed, 5523 insertions(+), 2562 deletions(-) delete mode 100644 src/demand/controler/InitialDemandAssigner.java delete mode 100644 src/demand/controler/MutualModule.java delete mode 100644 src/demand/controler/SupplyRescheduler.java delete mode 100644 src/demand/decoratedLSP/DefaultAssigner.java delete mode 100644 src/demand/decoratedLSP/LSPDecorator.java delete mode 100644 src/demand/decoratedLSP/LSPDecorators.java delete mode 100644 src/demand/decoratedLSP/LSPPlanDecorator.java delete mode 100644 src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java delete mode 100644 src/demand/decoratedLSP/LSPWithOffers.java delete mode 100644 src/demand/decoratedLSP/LogisticsSolutionDecorator.java delete mode 100644 src/demand/demandAgent/DemandAgent.java delete mode 100644 src/demand/demandAgent/DemandAgentImpl.java delete mode 100644 src/demand/demandObject/DemandObject.java delete mode 100644 src/demand/demandObject/DemandObjectImpl.java delete mode 100644 src/demand/demandObject/DemandObjects.java delete mode 100644 src/demand/demandObject/DemandPlan.java delete mode 100644 src/demand/demandObject/DemandPlanGenerator.java delete mode 100644 src/demand/demandObject/DemandPlanImpl.java delete mode 100644 src/demand/demandObject/OfferRequester.java delete mode 100644 src/demand/demandObject/ShipperShipment.java delete mode 100644 src/demand/demandObject/ShipperShipmentImpl.java delete mode 100644 src/demand/mutualReplanning/DemandPlanStrategyImpl.java delete mode 100644 src/demand/mutualReplanning/DemandReplanner.java delete mode 100644 src/demand/mutualReplanning/DemandReplannerImpl.java delete mode 100644 src/demand/mutualReplanning/LSPWithOffersReplanner.java delete mode 100644 src/demand/mutualReplanning/MutualReplanningModule.java delete mode 100644 src/demand/mutualReplanning/MutualReplanningModuleImpl.java delete mode 100644 src/demand/mutualReplanning/OfferReplanningStrategyModule.java delete mode 100644 src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java delete mode 100644 src/demand/offer/DefaultOfferImpl.java delete mode 100644 src/demand/offer/Offer.java delete mode 100644 src/demand/offer/OfferFactory.java delete mode 100644 src/demand/offer/OfferFactoryImpl.java delete mode 100644 src/demand/offer/OfferTransferrer.java delete mode 100644 src/demand/offer/OfferTransferrerImpl.java delete mode 100644 src/demand/offer/OfferUpdater.java delete mode 100644 src/demand/offer/OfferUpdaterImpl.java delete mode 100644 src/demand/offer/OfferVisitor.java delete mode 100644 src/demand/scoring/DemandScorer.java delete mode 100644 src/demand/scoring/MutualScoringModuleImpl.java delete mode 100644 src/demand/utilityFunctions/UtilityFunction.java create mode 100644 src/main/java/lsp/ForwardSolutionSchedulerImpl.java create mode 100644 src/main/java/lsp/HasEventHandlers.java create mode 100644 src/main/java/lsp/LSP.java create mode 100644 src/main/java/lsp/LSPImpl.java create mode 100644 src/main/java/lsp/LSPPlan.java create mode 100644 src/main/java/lsp/LSPPlanImpl.java create mode 100644 src/main/java/lsp/LSPs.java create mode 100644 src/main/java/lsp/LogisticsSolution.java create mode 100644 src/main/java/lsp/LogisticsSolutionElement.java create mode 100644 src/main/java/lsp/LogisticsSolutionElementImpl.java rename src/{demand/decoratedLSP/LogisticsSolutionWithOffers.java => main/java/lsp/LogisticsSolutionImpl.java} (60%) create mode 100644 src/main/java/lsp/ShipmentAssigner.java create mode 100644 src/main/java/lsp/ShipmentTuple.java create mode 100644 src/main/java/lsp/SolutionScheduler.java create mode 100644 src/main/java/lsp/WaitingShipments.java create mode 100644 src/main/java/lsp/WaitingShipmentsImpl.java create mode 100644 src/main/java/lsp/controler/FreightControlerListener.java rename src/{demand/controler/MutualControlerListener.java => main/java/lsp/controler/LSPControlerListener.java} (52%) create mode 100644 src/main/java/lsp/controler/LSPModule.java rename src/{demand/controler/SupplyClearer.java => main/java/lsp/controler/LSPRescheduler.java} (51%) create mode 100644 src/main/java/lsp/controler/MobSimVehicleRoute.java create mode 100644 src/main/java/lsp/replanning/LSPPlanStrategyManagerFactory.java create mode 100644 src/main/java/lsp/replanning/LSPReplanner.java create mode 100644 src/main/java/lsp/replanning/LSPReplannerImpl.java create mode 100644 src/main/java/lsp/replanning/LSPReplanningModule.java create mode 100644 src/main/java/lsp/replanning/LSPReplanningModuleImpl.java create mode 100644 src/main/java/lsp/scoring/LSPScorer.java rename src/{demand/scoring/MutualScoringModule.java => main/java/lsp/scoring/LSPScoringModule.java} (52%) create mode 100644 src/main/java/lsp/scoring/LSPScoringModuleImpl.java create mode 100644 src/main/java/lsp/scoring/Scorer.java create mode 100644 src/main/java/lsp/shipment/AbstractShipmentPlan.java create mode 100644 src/main/java/lsp/shipment/AbstractShipmentPlanElement.java create mode 100644 src/main/java/lsp/shipment/AbstractShipmentPlanElementComparator.java create mode 100644 src/main/java/lsp/shipment/LSPShipment.java create mode 100644 src/main/java/lsp/shipment/LSPShipmentImpl.java create mode 100644 src/main/java/lsp/shipment/LSPShipments.java create mode 100644 src/main/java/lsp/shipment/Log.java create mode 100644 src/main/java/lsp/shipment/LoggedShipmentHandle.java create mode 100644 src/main/java/lsp/shipment/LoggedShipmentLoad.java create mode 100644 src/main/java/lsp/shipment/LoggedShipmentTransport.java create mode 100644 src/main/java/lsp/shipment/LoggedShipmentUnload.java create mode 100644 src/main/java/lsp/shipment/Requirement.java create mode 100644 src/main/java/lsp/shipment/Schedule.java create mode 100644 src/main/java/lsp/shipment/ScheduledShipmentHandle.java create mode 100644 src/main/java/lsp/shipment/ScheduledShipmentLoad.java create mode 100644 src/main/java/lsp/shipment/ScheduledShipmentTransport.java create mode 100644 src/main/java/lsp/shipment/ScheduledShipmentUnload.java create mode 100644 src/main/java/lsp/shipment/ShipmentComparator.java create mode 100644 src/main/java/lsp/usecase/CollectionCarrierAdapter.java create mode 100644 src/main/java/lsp/usecase/CollectionCarrierScheduler.java create mode 100644 src/main/java/lsp/usecase/CollectionServiceEventHandler.java create mode 100644 src/main/java/lsp/usecase/CollectionTourEndEventHandler.java create mode 100644 src/main/java/lsp/usecase/DeterministicShipmentAssigner.java create mode 100644 src/main/java/lsp/usecase/DistributionCarrierAdapter.java create mode 100644 src/main/java/lsp/usecase/DistributionCarrierScheduler.java create mode 100644 src/main/java/lsp/usecase/DistributionServiceEventHandler.java create mode 100644 src/main/java/lsp/usecase/DistributionStartEventHandler.java create mode 100644 src/main/java/lsp/usecase/FreightLinkEnterEventHandler.java create mode 100644 src/main/java/lsp/usecase/LSPShipmentMaker.java create mode 100644 src/main/java/lsp/usecase/MainRunCarrierAdapter.java create mode 100644 src/main/java/lsp/usecase/MainRunCarrierScheduler.java create mode 100644 src/main/java/lsp/usecase/MainRunEndEventHandler.java create mode 100644 src/main/java/lsp/usecase/MainRunStartEventHandler.java create mode 100644 src/main/java/lsp/usecase/NetworkMaker.java create mode 100644 src/main/java/lsp/usecase/ReloadingPoint.java create mode 100644 src/main/java/lsp/usecase/ReloadingPointEventHandler.java create mode 100644 src/main/java/lsp/usecase/ReloadingPointScheduler.java create mode 100644 src/main/java/lsp/usecase/SimpleForwardSolutionScheduler.java diff --git a/pom.xml b/pom.xml index 7c54cd0211a..9344fc86147 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,13 @@ ojo-snapshots http://oss.jfrog.org/libs-snapshot - + + + osgeo + Geotools repository + http://download.osgeo.org/webdav/geotools + + diff --git a/src/demand/controler/InitialDemandAssigner.java b/src/demand/controler/InitialDemandAssigner.java deleted file mode 100644 index a82235ee7a9..00000000000 --- a/src/demand/controler/InitialDemandAssigner.java +++ /dev/null @@ -1,68 +0,0 @@ -package demand.controler; - -import java.util.Collection; - -import org.matsim.api.core.v01.Id; -import org.matsim.core.controler.events.StartupEvent; -import org.matsim.core.controler.listener.StartupListener; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPDecorators; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; -import demand.demandObject.DemandPlan; -import demand.offer.Offer; -import lsp.functions.Info; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class InitialDemandAssigner implements StartupListener{ - - private DemandObjects demandObjects; - private LSPDecorators lsps; - - public InitialDemandAssigner(DemandObjects demandObjects, LSPDecorators lsps) { - this.demandObjects = demandObjects; - this.lsps = lsps; - } - - @Override - public void notifyStartup(StartupEvent event) { - - for(DemandObject demandObject : demandObjects.getDemandObjects().values()) { - if(demandObject.getSelectedPlan() == null) { - createInitialPlan(demandObject); - } - assignShipmentToLSP(demandObject); - } - - for(LSPDecorator lsp : lsps.getLSPs().values()) { - lsp.scheduleSoultions(); - } - } - - private void createInitialPlan(DemandObject demandObject) { - Collection offers = demandObject.getOfferRequester().requestOffers(lsps.getLSPs().values()); - DemandPlan initialPlan = demandObject.getDemandPlanGenerator().createDemandPlan(offers); - demandObject.setSelectedPlan(initialPlan); - } - - private void assignShipmentToLSP(DemandObject demandObject) { - Id id = Id.create(demandObject.getSelectedPlan().getShipment().getId(), LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - builder.setFromLinkId(demandObject.getFromLinkId()); - builder.setToLinkId(demandObject.getToLinkId()); - builder.setCapacityDemand((int)demandObject.getSelectedPlan().getShipment().getShipmentSize()); - builder.setServiceTime(demandObject.getSelectedPlan().getShipment().getServiceTime()); - builder.setStartTimeWindow(demandObject.getSelectedPlan().getShipment().getStartTimeWindow()); - builder.setEndTimeWindow(demandObject.getSelectedPlan().getShipment().getEndTimeWindow()); - for(Info info : demandObject.getInfos()) { - builder.addInfo(info); - } - LSPShipment lspShipment = builder.build(); - demandObject.getSelectedPlan().getLsp().assignShipmentToSolution(lspShipment, demandObject.getSelectedPlan().getSolutionId()); - demandObject.getSelectedPlan().getShipment().setLSPShipment(lspShipment); - } - - -} diff --git a/src/demand/controler/MutualModule.java b/src/demand/controler/MutualModule.java deleted file mode 100644 index bddb1cd1cd1..00000000000 --- a/src/demand/controler/MutualModule.java +++ /dev/null @@ -1,112 +0,0 @@ -package demand.controler; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.contrib.freight.CarrierConfig; -import org.matsim.core.controler.AbstractModule; - -import com.google.inject.Provides; - -import demand.decoratedLSP.LSPDecorators; -import demand.demandObject.DemandObjects; -import demand.mutualReplanning.MutualReplanningModule; -import demand.scoring.MutualScoringModule; -import lsp.events.EventCreator; -import lsp.mobsim.CarrierResourceTracker; -import lsp.mobsim.FreightQSimFactory; -import lsp.scoring.LSPScoringModule; - -public class MutualModule extends AbstractModule{ - - private LSPDecorators lsps; - private DemandObjects demandObjects; - private MutualScoringModule mutualScoringModule; - private MutualReplanningModule replanningModule; - private CarrierConfig carrierConfig = new CarrierConfig(); - private Collection creators; - - public static class Builder{ - - private LSPDecorators lsps; - private DemandObjects demandObjects; - private MutualScoringModule mutualScoringModule; - private MutualReplanningModule replanningModule; - private Collection creators; - - public static Builder newInstance() { - return new Builder(); - } - - public Builder setLsps(LSPDecorators lsps) { - this.lsps = lsps; - return this; - } - - public Builder setMutualScoringModule(MutualScoringModule demandScoringModule) { - this.mutualScoringModule = demandScoringModule; - return this; - } - - public Builder setMutualReplanningModule(MutualReplanningModule replanningModule) { - this.replanningModule = replanningModule; - return this; - } - - public Builder setDemandObjects(DemandObjects demandObjects) { - this.demandObjects = demandObjects; - return this; - } - - public Builder setEventCreators(Collection creators) { - this.creators = creators; - return this; - } - - public MutualModule build() { - return new MutualModule(this); - } - } - - private MutualModule(Builder builder) { - this.lsps = builder.lsps; - this.demandObjects = builder.demandObjects; - this.mutualScoringModule = builder.mutualScoringModule; - this.replanningModule = builder.replanningModule; - this.creators = builder.creators; - } - - - @Override - public void install() { - bind(CarrierConfig.class).toInstance(carrierConfig); - bind(LSPDecorators.class).toInstance(lsps); - bind(DemandObjects.class).toInstance(demandObjects); - - if(replanningModule != null) { - bind(MutualReplanningModule.class).toInstance(replanningModule); - } - if(mutualScoringModule != null) { - bind(MutualScoringModule.class).toInstance(mutualScoringModule); - } - bind(MutualControlerListener.class).asEagerSingleton(); - addControlerListenerBinding().to(MutualControlerListener.class); - bindMobsim().toProvider(FreightQSimFactory.class); - - } - - @Provides - Collection provideEventCreators(){ - return this.creators; - } - - @Provides - CarrierResourceTracker provideCarrierResourceTracker(MutualControlerListener mutualControlerListener) { - return mutualControlerListener.getCarrierResourceTracker(); - } - - public void setPhysicallyEnforceTimeWindowBeginnings(boolean physicallyEnforceTimeWindowBeginnings) { - this.carrierConfig.setPhysicallyEnforceTimeWindowBeginnings(physicallyEnforceTimeWindowBeginnings); - } - -} diff --git a/src/demand/controler/SupplyRescheduler.java b/src/demand/controler/SupplyRescheduler.java deleted file mode 100644 index d52c5e2ff3b..00000000000 --- a/src/demand/controler/SupplyRescheduler.java +++ /dev/null @@ -1,26 +0,0 @@ -package demand.controler; - -import org.matsim.core.controler.events.BeforeMobsimEvent; -import org.matsim.core.controler.listener.BeforeMobsimListener; - -import demand.decoratedLSP.LSPDecorators; -import lsp.LSP; - - -public class SupplyRescheduler implements BeforeMobsimListener{ - - private LSPDecorators lsps; - - public SupplyRescheduler(LSPDecorators lsps) { - this.lsps = lsps; - } - - - public void notifyBeforeMobsim(BeforeMobsimEvent arg0) { - if(arg0.getIteration() != 0) { - for(LSP lsp : lsps.getLSPs().values()){ - lsp.scheduleSoultions(); - } - } - } -} diff --git a/src/demand/decoratedLSP/DefaultAssigner.java b/src/demand/decoratedLSP/DefaultAssigner.java deleted file mode 100644 index 4453a3efd5e..00000000000 --- a/src/demand/decoratedLSP/DefaultAssigner.java +++ /dev/null @@ -1,32 +0,0 @@ -package demand.decoratedLSP; - -import lsp.LSP; -import lsp.ShipmentAssigner; -import lsp.shipment.LSPShipment; - -public class DefaultAssigner implements ShipmentAssigner{ - - private LSP lsp; - - public DefaultAssigner (LSP lsp) { - this.lsp = lsp; - } - - @Override - public void assignShipment(LSPShipment shipment) { - //Has to be empty, as an LSPWithOffers does not assign with the assigner. - //This job is done by the OfferTransferrer who gives the right solution in the offer - } - - @Override - public void setLSP(LSP lsp) { - this.lsp = lsp; - - } - - @Override - public LSP getLSP() { - return lsp; - } - -} diff --git a/src/demand/decoratedLSP/LSPDecorator.java b/src/demand/decoratedLSP/LSPDecorator.java deleted file mode 100644 index 7e41583b148..00000000000 --- a/src/demand/decoratedLSP/LSPDecorator.java +++ /dev/null @@ -1,22 +0,0 @@ -package demand.decoratedLSP; - -import org.matsim.api.core.v01.Id; -import org.matsim.core.controler.events.ReplanningEvent; - -import demand.demandObject.DemandObject; -import demand.offer.Offer; -import demand.offer.OfferTransferrer; -import demand.offer.OfferUpdater; -import lsp.LSP; -import lsp.LSPPlan; -import lsp.LogisticsSolution; -import lsp.shipment.LSPShipment; - -public interface LSPDecorator extends LSP { - - public Offer getOffer(DemandObject object, String type, Id solutionId); - public void assignShipmentToSolution(LSPShipment shipment, Id id); - public OfferUpdater getOfferUpdater(); - public void setOfferUpdater(OfferUpdater offerUpdater); - public LSPPlanDecorator getSelectedPlan(); -} diff --git a/src/demand/decoratedLSP/LSPDecorators.java b/src/demand/decoratedLSP/LSPDecorators.java deleted file mode 100644 index fbdbb224df8..00000000000 --- a/src/demand/decoratedLSP/LSPDecorators.java +++ /dev/null @@ -1,40 +0,0 @@ -package demand.decoratedLSP; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.Id; - -import lsp.LSP; - - - -public class LSPDecorators { - - private Map, LSPDecorator> lsps = new HashMap<>(); - - public LSPDecorators(Collection lsps) { - makeMap(lsps); - } - - private void makeMap(Collection lsps) { - for (LSPDecorator c : lsps) { - this.lsps.put(c.getId(), c); - } - } - - public LSPDecorators() { - - } - - public Map, LSPDecorator> getLSPs() { - return lsps; - } - - public void addLSP(LSPDecorator lsp) { - if(!lsps.containsKey(lsp.getId())){ - lsps.put(lsp.getId(), lsp); - } - } -} diff --git a/src/demand/decoratedLSP/LSPPlanDecorator.java b/src/demand/decoratedLSP/LSPPlanDecorator.java deleted file mode 100644 index d97abba5308..00000000000 --- a/src/demand/decoratedLSP/LSPPlanDecorator.java +++ /dev/null @@ -1,20 +0,0 @@ -package demand.decoratedLSP; - -import java.util.Collection; - -import demand.offer.OfferTransferrer; -import demand.offer.OfferUpdater; -import lsp.LSP; -import lsp.LSPPlan; -import lsp.LogisticsSolution; -import lsp.ShipmentAssigner; - -public interface LSPPlanDecorator extends LSPPlan{ - - public void setOfferTransferrer(OfferTransferrer transferrer); - public OfferTransferrer getOfferTransferrer(); - public Collection getSolutionDecorators(); - public void addSolution (LogisticsSolutionDecorator solution); - public void setLSP(LSPDecorator lsp); - public LSPDecorator getLsp(); -} diff --git a/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java b/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java deleted file mode 100644 index 6dec808b65b..00000000000 --- a/src/demand/decoratedLSP/LSPPlanWithOfferTransferrer.java +++ /dev/null @@ -1,114 +0,0 @@ -package demand.decoratedLSP; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.offer.OfferTransferrer; -import demand.offer.OfferUpdater; -import lsp.LSP; -import lsp.LSPPlan; -import lsp.LogisticsSolution; -import lsp.ShipmentAssigner; - -public class LSPPlanWithOfferTransferrer implements LSPPlanDecorator{ - - private LSPDecorator lsp; - private double score; - private Collection solutions; - private ShipmentAssigner assigner; - private OfferTransferrer transferrer; - - public LSPPlanWithOfferTransferrer() { - this.solutions = new ArrayList(); - this.assigner = new DefaultAssigner(this.lsp); - } - - @Override - public void addSolution(LogisticsSolution solution) { - try { - LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; - this.solutions.add(solutionDecorator); - solution.setLSP(this.lsp); - } - catch(ClassCastException e) { - System.out.println("The class " + this.toString() + " expects an LogisticsSolutionDecorator and not any other implementation of LogisticsSolution"); - System.exit(1); - } - } - - @Override - public Collection getSolutions() { - Collection solutionDecorators = new ArrayList(); - for(LogisticsSolution solution : solutions) { - LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; - solutionDecorators.add(solutionDecorator); - } - return solutionDecorators; - } - - @Override - public ShipmentAssigner getAssigner() { - return assigner; - } - - @Override - public void setAssigner(ShipmentAssigner assigner) { - - } - - @Override - public void setLSP(LSP lsp) { - try { - this.lsp = (LSPDecorator) lsp; - } - catch(ClassCastException e) { - System.out.println("The class " + this.toString() + " expects an LSPDecorator and not any other implementation of LSP"); - System.exit(1); - } - } - - @Override - public LSPDecorator getLsp() { - return lsp; - } - - @Override - public void setScore(Double score) { - this.score = score; - } - - @Override - public Double getScore() { - return score; - } - - public OfferTransferrer getOfferTransferrer() { - return transferrer; - } - - public void setOfferTransferrer(OfferTransferrer offerTransferrer) { - this.transferrer = offerTransferrer; - this.transferrer.setLSP(lsp); - } - - @Override - public Collection getSolutionDecorators() { - Collection solutionDecorators = new ArrayList(); - for(LogisticsSolution solution : solutions) { - LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; - solutionDecorators.add(solutionDecorator); - } - return solutionDecorators; - } - - @Override - public void addSolution(LogisticsSolutionDecorator solution) { - this.solutions.add(solution); - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - -} diff --git a/src/demand/decoratedLSP/LSPWithOffers.java b/src/demand/decoratedLSP/LSPWithOffers.java deleted file mode 100644 index cf9dbf81893..00000000000 --- a/src/demand/decoratedLSP/LSPWithOffers.java +++ /dev/null @@ -1,319 +0,0 @@ -package demand.decoratedLSP; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.matsim.api.core.v01.Id; - -import demand.demandObject.DemandObject; -import demand.offer.Offer; -import demand.offer.OfferTransferrer; -import demand.offer.OfferTransferrerImpl; -import demand.offer.OfferUpdater; -import lsp.LogisticsSolutionImpl; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlan; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.SolutionScheduler; -import lsp.LSPImpl.Builder; -import lsp.replanning.LSPReplanner; -import lsp.resources.Resource; -import lsp.scoring.LSPScorer; -import lsp.shipment.LSPShipment; - -public class LSPWithOffers implements LSPDecorator { - - private Id id; - private Collection shipments; - private ArrayList plans; - private SolutionScheduler solutionScheduler; - private LSPPlanDecorator selectedPlan; - private Collection resources; - private LSPScorer scorer; - private LSPReplanner replanner; - private OfferUpdater offerUpdater; - - public static class Builder{ - private Id id; - private SolutionScheduler solutionScheduler; - private LSPPlanDecorator initialPlan; - private Collection resources; - private LSPScorer scorer; - private LSPReplanner replanner; - private OfferUpdater offerUpdater; - - - public static Builder getInstance(){ - return new Builder(); - } - - private Builder(){ - this.resources = new ArrayList(); - - } - - public Builder setSolutionScheduler(SolutionScheduler solutionScheduler){ - this.solutionScheduler = solutionScheduler; - return this; - } - - public Builder setSolutionScorer(LSPScorer scorer){ - this.scorer = scorer; - return this; - } - - public Builder setReplanner(LSPReplanner replanner){ - this.replanner= replanner; - return this; - } - - public Builder setOfferUpdater(OfferUpdater offerUpdater){ - this.offerUpdater= offerUpdater; - return this; - } - - public Builder setInitialPlan(LSPPlanDecorator plan){ - this.initialPlan = plan; - for(LogisticsSolution solution : plan.getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - if(!resources.contains(element.getResource())) { - resources.add(element.getResource()); - } - } - } - return this; - } - - public Builder setId(Id id){ - this.id = id; - return this; - } - - public LSPWithOffers build(){ - return new LSPWithOffers(this); - } - - } - - private LSPWithOffers(LSPWithOffers.Builder builder){ - this.shipments = new ArrayList(); - this.plans= new ArrayList(); - this.id = builder.id; - this.solutionScheduler = builder.solutionScheduler; - this.solutionScheduler.setLSP(this); - builder.initialPlan.setLSP(this); - this.selectedPlan=builder.initialPlan; - this.plans.add(builder.initialPlan); - this.selectedPlan.setLSP(this); - this.selectedPlan.getOfferTransferrer().setLSP(this); - this.resources = builder.resources; - this.scorer = builder.scorer; - if(this.scorer != null) { - this.scorer.setLSP(this); - } - this.replanner = builder.replanner; - if(this.replanner != null) { - this.replanner .setLSP(this); - } - this.offerUpdater = builder.offerUpdater; - if(offerUpdater != null) { - offerUpdater.setLSP(this); - } - } - - @Override - public Id getId() { - return id; - } - - @Override - public Collection getShipments() { - return shipments; - } - - @Override - public void scheduleSoultions() { - solutionScheduler.scheduleSolutions(); - } - - @Override - public ArrayList getPlans() { - for(LSPPlan plan : plans) { - plan.setLSP(this); - for(LogisticsSolution solution : plan.getSolutions()) { - if(solution instanceof LogisticsSolutionWithOffers) { - LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; - solutionWithOffers.setLSP(this); - solutionWithOffers.getOfferFactory().setLSP(this); - for(Offer offer : solutionWithOffers.getOfferFactory().getOffers()) { - offer.setLSP(this); - } - } - } - } - return plans; - } - - @Override - public Collection getResources() { - return resources; - } - - @Override - public LSPPlanDecorator getSelectedPlan() { - selectedPlan.setLSP(this); - for(LogisticsSolution solution : selectedPlan.getSolutions()) { - if(solution instanceof LogisticsSolutionWithOffers) { - LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; - solutionWithOffers.setLSP(this); - solutionWithOffers.getOfferFactory().setLSP(this); - } - } - return selectedPlan; - } - - @Override - public void setSelectedPlan(LSPPlan plan) { - try { - plan.setLSP(this); - this.selectedPlan = (LSPPlanDecorator) plan; - for(LogisticsSolution solution : selectedPlan.getSolutions()) { - if(solution instanceof LogisticsSolutionWithOffers) { - LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; - solutionWithOffers.setLSP(this); - solutionWithOffers.getOfferFactory().setLSP(this); - } - } - if(!plans.contains(selectedPlan)) { - plans.add(selectedPlan); - } - } - catch(ClassCastException e) { - System.out.println("The class " + this.toString() + " expects an LSPPlanDecorator and not any other implementation of LSPPlan"); - System.exit(1); - } - } - - @Override - public void scoreSelectedPlan() { - double score = scorer.scoreCurrentPlan(this); - this.selectedPlan.setScore(score); - } - - @Override - public void assignShipmentToLSP(LSPShipment shipment) { - this.shipments.add(shipment); - } - - @Override - public LSPScorer getScorer() { - return scorer; - } - - @Override - public void setScorer(LSPScorer scorer) { - this.scorer = scorer; - } - - @Override - public boolean addPlan(LSPPlan p) { - try { - LSPPlanDecorator plan = (LSPPlanDecorator) p; - for(LogisticsSolution solution : plan.getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - if(!resources.contains(element.getResource())) { - resources.add(element.getResource()); - } - } - } - return plans.add(plan); - } - catch(ClassCastException e) { - System.out.println("The class " + this.toString() + " expects an LSPPlanDecorator and not any other implementation of LSPPlan"); - System.exit(1); - } - return false; - } - - @Override - public boolean removePlan(LSPPlan plan) { - if(plans.contains(plan)) { - plans.remove(plan); - return true; - } - else { - return false; - } - } - - @Override - public LSPPlan createCopyOfSelectedPlanAndMakeSelected() { - LSPPlanDecorator newPlan = LSPWithOffers.copyPlan(this.selectedPlan) ; - this.setSelectedPlan( newPlan ) ; - return newPlan ; - } - - @Override - public Offer getOffer(DemandObject object, String type, Id solutionId) { - return selectedPlan.getOfferTransferrer().transferOffer(object, type, solutionId); - } - - @Override - public void assignShipmentToSolution(LSPShipment shipment, Id id) { - assignShipmentToLSP(shipment); - for(LogisticsSolution solution : selectedPlan.getSolutions()) { - if(solution.getId() == id) { - solution.assignShipment(shipment); - } - } - } - - @Override - public LSPReplanner getReplanner() { - return replanner; - } - - @Override - public void setReplanner(LSPReplanner replanner) { - this.replanner = replanner; - } - - @Override - public OfferUpdater getOfferUpdater() { - return offerUpdater; - } - - @Override - public void setOfferUpdater(OfferUpdater offerUpdater) { - this.offerUpdater = offerUpdater; - } - - public static LSPPlanDecorator copyPlan(LSPPlanDecorator plan2copy) { - List copiedSolutions = new ArrayList(); - for (LogisticsSolution solution : plan2copy.getSolutions()) { - LogisticsSolutionDecorator solutionDecorator = (LogisticsSolutionDecorator) solution; - LogisticsSolutionDecorator copiedSolution = LogisticsSolutionWithOffers.Builder.newInstance(solutionDecorator.getId()).build(); - copiedSolution.getSolutionElements().addAll(solutionDecorator.getSolutionElements()); - copiedSolution.setOfferFactory(solutionDecorator.getOfferFactory()); - copiedSolutions.add(copiedSolution); - } - LSPPlanDecorator copiedPlan = new LSPPlanWithOfferTransferrer(); - copiedPlan.setOfferTransferrer(plan2copy.getOfferTransferrer()); - copiedPlan.setLSP(plan2copy.getLsp()); - double initialScoreOfCopiedPlan = plan2copy.getScore(); - copiedPlan.setScore(initialScoreOfCopiedPlan); - copiedPlan.getSolutions().addAll(copiedSolutions); - return copiedPlan; - } - - @Override - public SolutionScheduler getScheduler() { - return solutionScheduler; - } - - -} diff --git a/src/demand/decoratedLSP/LogisticsSolutionDecorator.java b/src/demand/decoratedLSP/LogisticsSolutionDecorator.java deleted file mode 100644 index 3aeac837601..00000000000 --- a/src/demand/decoratedLSP/LogisticsSolutionDecorator.java +++ /dev/null @@ -1,15 +0,0 @@ -package demand.decoratedLSP; - -import demand.demandObject.DemandObject; -import demand.offer.Offer; -import demand.offer.OfferFactory; -import lsp.LogisticsSolution; - -public interface LogisticsSolutionDecorator extends LogisticsSolution { - - public Offer getOffer(DemandObject object, String type); - public void setOfferFactory(OfferFactory factory); - public OfferFactory getOfferFactory(); - public LSPDecorator getLSP(); - -} diff --git a/src/demand/demandAgent/DemandAgent.java b/src/demand/demandAgent/DemandAgent.java deleted file mode 100644 index 55c1582d8ad..00000000000 --- a/src/demand/demandAgent/DemandAgent.java +++ /dev/null @@ -1,15 +0,0 @@ -package demand.demandAgent; - -import java.util.Collection; - -import org.matsim.api.core.v01.Id; - -import demand.demandObject.DemandObject; -import demand.utilityFunctions.UtilityFunction; - -public interface DemandAgent { - - public Id getId(); - public Collection getDemandObjects(); - public Collection getUtilityFunctions(); -} diff --git a/src/demand/demandAgent/DemandAgentImpl.java b/src/demand/demandAgent/DemandAgentImpl.java deleted file mode 100644 index e48b971d815..00000000000 --- a/src/demand/demandAgent/DemandAgentImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -package demand.demandAgent; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.Id; - -import demand.demandObject.DemandObject; -import demand.utilityFunctions.UtilityFunction; - -public class DemandAgentImpl implements DemandAgent { - - private Id id; - private ArrayList demandObjects; - private ArrayList utilityFunctions; - - public static class Builder{ - private Id id; - private ArrayList utilityFunctions; - - public static Builder newInstance() { - return new Builder(); - } - - private Builder() { - this.utilityFunctions = new ArrayList(); - } - - public Builder setId(Id id) { - this.id = id; - return this; - } - - public Builder addUtilityFunction(UtilityFunction utilityFunction) { - this.utilityFunctions.add(utilityFunction); - return this; - } - - public DemandAgentImpl build() { - return new DemandAgentImpl(this); - } - } - - private DemandAgentImpl(Builder builder) { - this.demandObjects = new ArrayList(); - this.utilityFunctions = new ArrayList(); - this.utilityFunctions = builder.utilityFunctions; - this.id = builder.id; - } - - - @Override - public Id getId() { - return id; - } - - @Override - public Collection getDemandObjects() { - return demandObjects; - } - - @Override - public Collection getUtilityFunctions() { - return utilityFunctions; - } - -} diff --git a/src/demand/demandObject/DemandObject.java b/src/demand/demandObject/DemandObject.java deleted file mode 100644 index eaf51afad5b..00000000000 --- a/src/demand/demandObject/DemandObject.java +++ /dev/null @@ -1,41 +0,0 @@ -package demand.demandObject; - -import java.util.Collection; -import java.util.List; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.population.HasPlansAndId; - -import demand.demandAgent.DemandAgent; -import demand.mutualReplanning.DemandReplanner; -import demand.scoring.DemandScorer; -import demand.utilityFunctions.UtilityFunction; -import lsp.functions.Info; -import lsp.shipment.Requirement; - - -public interface DemandObject extends HasPlansAndId{ - - public DemandAgent getShipper(); - public DemandAgent getRecipient(); - public Id getId(); - public List getPlans(); - public double getStrengthOfFlow(); - public Id getFromLinkId(); - public Id getToLinkId(); - public Collection getUtilityFunctions(); - public void scoreSelectedPlan(); - public DemandPlan getSelectedPlan(); - public void setSelectedPlan(DemandPlan plan); - public void setScorer(DemandScorer scorer); - public DemandScorer getScorer(); - public DemandReplanner getReplanner(); - public void setReplanner(DemandReplanner replanner); - public void setOfferRequester(OfferRequester requester); - public OfferRequester getOfferRequester(); - public void setDemandPlanGenerator(DemandPlanGenerator generator); - public DemandPlanGenerator getDemandPlanGenerator(); - public Collection getRequirements(); - public Collection getInfos(); -} diff --git a/src/demand/demandObject/DemandObjectImpl.java b/src/demand/demandObject/DemandObjectImpl.java deleted file mode 100644 index 38eeae532c5..00000000000 --- a/src/demand/demandObject/DemandObjectImpl.java +++ /dev/null @@ -1,322 +0,0 @@ -package demand.demandObject; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.core.replanning.GenericStrategyManager; - -import demand.decoratedLSP.LSPWithOffers; -import demand.demandAgent.DemandAgent; -import demand.mutualReplanning.DemandReplanner; -import demand.offer.Offer; -import demand.scoring.DemandScorer; -import demand.utilityFunctions.UtilityFunction; -import lsp.functions.Info; -import lsp.shipment.Requirement; - -public class DemandObjectImpl implements DemandObject{ - - private DemandAgent shipper; - private DemandAgent recipient; - private Id id; - private ArrayList plans; - private double strengthOfFlow; - private Id fromLinkId; - private Id toLinkId; - private ArrayList utilityFunctions; - private DemandPlan selectedPlan; - private DemandScorer scorer; - private DemandReplanner replanner; - private Collection requirements; - private OfferRequester offerRequester; - private DemandPlanGenerator generator; - private Collection infos; - - public static class Builder{ - private DemandAgent shipper; - private DemandAgent recipient; - private Id id; - private double strengthOfFlow; - private Id fromLinkId; - private Id toLinkId; - private ArrayList utilityFunctions; - private DemandPlan initialPlan; - private DemandScorer scorer; - private DemandReplanner replanner; - private Collection requirements; - private OfferRequester offerRequester; - private DemandPlanGenerator generator; - private Collection infos; - - public static Builder newInstance() { - return new Builder(); - } - - private Builder() { - this.requirements = new ArrayList(); - this.utilityFunctions = new ArrayList(); - this.infos = new ArrayList(); - } - - public Builder setShipper(DemandAgent shipper) { - this.shipper = shipper; - return this; - } - - public Builder setRecipient(DemandAgent recipient) { - this.recipient = recipient; - return this; - } - - public Builder setId(Id id) { - this.id = id; - return this; - } - - public Builder setInitialPlan(DemandPlan plan){ - this.initialPlan = plan; - return this; - } - - public Builder setStrengthOfFlow(double strength){ - this.strengthOfFlow = strength; - return this; - } - - public Builder setFromLinkId(Id fromLinkId){ - this.fromLinkId = fromLinkId; - return this; - } - - public Builder setToLinkId(Id toLinkId){ - this.toLinkId = toLinkId; - return this; - } - - public Builder setOfferRequester(OfferRequester offerRequester){ - this.offerRequester = offerRequester; - return this; - } - - public Builder setDemandPlanGenerator(DemandPlanGenerator generator){ - this.generator = generator; - return this; - } - - public Builder addUtilityFunction(UtilityFunction utilityFunction) { - this.utilityFunctions.add(utilityFunction); - return this; - } - - public Builder addRequirement(Requirement requirement) { - this.requirements.add(requirement); - return this; - } - - public Builder addInfo(Info info) { - this.infos.add(info); - return this; - } - - public Builder setScorer(DemandScorer scorer) { - this.scorer = scorer; - return this; - } - - public Builder setReplanner(DemandReplanner replanner) { - this.replanner = replanner; - return this; - } - - public DemandObject build() { - return new DemandObjectImpl(this); - } - - } - - private DemandObjectImpl(Builder builder) { - this.plans = new ArrayList(); - this.utilityFunctions = new ArrayList(); - this.shipper = builder.shipper; - if(this.shipper != null) { - this.shipper.getDemandObjects().add(this); - } - this.recipient = builder.recipient; - if(this.recipient != null) { - this.recipient.getDemandObjects().add(this); - } - this.id = builder.id; - this.strengthOfFlow = builder.strengthOfFlow; - this.fromLinkId = builder.fromLinkId; - this.toLinkId = builder.toLinkId; - this.selectedPlan=builder.initialPlan; - if(this.selectedPlan != null) { - this.selectedPlan.setDemandObject(this); - this.selectedPlan.getShipment().setDemandObject(this); - } - this.plans.add(builder.initialPlan); - this.utilityFunctions = builder.utilityFunctions; - this.scorer = builder.scorer; - if(this.scorer != null) { - this.scorer.setDemandObject(this); - } - this.replanner = builder.replanner; - if(this.replanner != null) { - this.replanner.setDemandObject(this); - } - this.requirements = builder.requirements; - this.offerRequester = builder.offerRequester; - if(this.offerRequester != null) { - this.offerRequester.setDemandObject(this); - } - this.infos = builder.infos; - this.generator = builder.generator; - if(this.generator != null) { - generator.setDemandObject(this); - } - } - - - @Override - public boolean addPlan(DemandPlan plan) { - return plans.add(plan); - } - - @Override - public boolean removePlan(DemandPlan plan) { - if(plans.contains(plan)) { - plans.remove(plan); - return true; - } - else { - return false; - } - } - - @Override - public DemandPlan getSelectedPlan() { - return selectedPlan; - } - - @Override - public void setSelectedPlan(DemandPlan selectedPlan) { - if(!plans.contains(selectedPlan)) plans.add(selectedPlan); - this.selectedPlan = selectedPlan; - } - - @Override - public DemandPlan createCopyOfSelectedPlanAndMakeSelected() { - DemandPlan newPlan = DemandObjectImpl.copyPlan(this.selectedPlan) ; - this.setSelectedPlan( newPlan ) ; - return newPlan; - } - - @Override - public DemandAgent getShipper() { - return shipper; - } - - @Override - public DemandAgent getRecipient() { - return recipient; - } - - @Override - public Id getId() { - return id; - } - - @Override - public List getPlans() { - return plans; - } - - @Override - public double getStrengthOfFlow() { - return strengthOfFlow; - } - - @Override - public Id getFromLinkId() { - return fromLinkId; - } - - @Override - public Id getToLinkId() { - return toLinkId; - } - - @Override - public Collection getUtilityFunctions() { - return utilityFunctions; - } - - private static DemandPlan copyPlan(DemandPlan plan2copy) { - DemandPlanImpl.Builder builder = DemandPlanImpl.Builder.newInstance(); - builder.setLogisticsSolutionId(plan2copy.getSolutionId()); - builder.setLsp(plan2copy.getLsp()); - builder.setShipperShipment(plan2copy.getShipment()); - DemandPlan copiedPlan = builder.build(); - copiedPlan.setScore(plan2copy.getScore()); - return copiedPlan; - } - - @Override - public void scoreSelectedPlan() { - double score = scorer.scoreCurrentPlan(this); - this.selectedPlan.setScore(score); - } - - @Override - public void setScorer(DemandScorer scorer) { - this.scorer = scorer; - } - - @Override - public DemandScorer getScorer() { - return scorer; - } - - @Override - public DemandReplanner getReplanner() { - return replanner; - } - - @Override - public void setReplanner(DemandReplanner replanner) { - this.replanner = replanner; - } - - @Override - public void setOfferRequester(OfferRequester requester) { - this.offerRequester = requester; - } - - @Override - public OfferRequester getOfferRequester() { - return offerRequester; - } - - @Override - public void setDemandPlanGenerator(DemandPlanGenerator generator) { - this.generator = generator; - } - - @Override - public DemandPlanGenerator getDemandPlanGenerator() { - return generator; - } - - @Override - public Collection getRequirements() { - return requirements; - } - - @Override - public Collection getInfos() { - return infos; - } -} diff --git a/src/demand/demandObject/DemandObjects.java b/src/demand/demandObject/DemandObjects.java deleted file mode 100644 index 04ad2087f9f..00000000000 --- a/src/demand/demandObject/DemandObjects.java +++ /dev/null @@ -1,37 +0,0 @@ -package demand.demandObject; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.Id; - -public class DemandObjects { - - private Map, DemandObject> demandObjects = new HashMap<>(); - - public DemandObjects(Collection demandObjects) { - makeMap(demandObjects); - } - - public DemandObjects() { - - } - - public Map, DemandObject> getDemandObjects(){ - return demandObjects; - } - - private void makeMap(Collection demandObjects) { - for(DemandObject d : demandObjects) { - this.demandObjects.put(d.getId(), d); - } - } - - public void addDemandObject(DemandObject demandObject) { - if(!demandObjects.containsKey(demandObject.getId())) { - demandObjects.put(demandObject.getId(), demandObject); - } - } - -} diff --git a/src/demand/demandObject/DemandPlan.java b/src/demand/demandObject/DemandPlan.java deleted file mode 100644 index b7a5d2f2f23..00000000000 --- a/src/demand/demandObject/DemandPlan.java +++ /dev/null @@ -1,19 +0,0 @@ -package demand.demandObject; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.population.BasicPlan; - -import demand.decoratedLSP.LSPDecorator; -import lsp.LogisticsSolution; - -public interface DemandPlan extends BasicPlan{ - - public Double getScore(); - public void setScore(Double arg0); - public ShipperShipment getShipment(); - public LSPDecorator getLsp(); - public Id getSolutionId(); - public DemandObject getDemandObject(); - public void setDemandObject(DemandObject demandObject); - -} diff --git a/src/demand/demandObject/DemandPlanGenerator.java b/src/demand/demandObject/DemandPlanGenerator.java deleted file mode 100644 index 8809ff47ab7..00000000000 --- a/src/demand/demandObject/DemandPlanGenerator.java +++ /dev/null @@ -1,11 +0,0 @@ -package demand.demandObject; - -import java.util.Collection; - -import demand.offer.Offer; - -public interface DemandPlanGenerator { - - public DemandPlan createDemandPlan(Collection offers); - public void setDemandObject(DemandObject demandObject); -} diff --git a/src/demand/demandObject/DemandPlanImpl.java b/src/demand/demandObject/DemandPlanImpl.java deleted file mode 100644 index 69856c1d343..00000000000 --- a/src/demand/demandObject/DemandPlanImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -package demand.demandObject; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.population.BasicPlan; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import lsp.LogisticsSolution; - - -public class DemandPlanImpl implements DemandPlan{ - - private double score; - private ShipperShipment shipment; - private LSPDecorator lsp; - private Id solutionId; - private DemandObject demandObject; - - public static class Builder{ - private ShipperShipment shipment; - private LSPDecorator lsp; - private Id solutionId; - private DemandObject demandObject; - - public static Builder newInstance(){ - return new Builder(); - } - - private Builder(){ - } - - public Builder setShipperShipment(ShipperShipment shipment){ - this.shipment = shipment; - return this; - } - - public Builder setLsp(LSPDecorator lsp){ - this.lsp = lsp; - return this; - } - - public Builder setDemandObject(DemandObject demandObject){ - this.demandObject = demandObject; - return this; - } - - public Builder setLogisticsSolutionId(Id solutionId){ - this.solutionId = solutionId; - return this; - } - - public DemandPlanImpl build() { - return new DemandPlanImpl(this); - } - - } - - private DemandPlanImpl(Builder builder) { - this.shipment = builder.shipment; - this.lsp = builder.lsp; - this.solutionId = builder.solutionId; - this.demandObject = builder.demandObject; - } - - @Override - public Double getScore() { - return score; - } - - @Override - public void setScore(Double arg0) { - this.score = arg0; - } - - public ShipperShipment getShipment() { - return shipment; - } - - public LSPDecorator getLsp() { - return lsp; - } - - public Id getSolutionId() { - return solutionId; - } - - public DemandObject getDemandObject() { - return demandObject; - } - - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/src/demand/demandObject/OfferRequester.java b/src/demand/demandObject/OfferRequester.java deleted file mode 100644 index 3286fa9a118..00000000000 --- a/src/demand/demandObject/OfferRequester.java +++ /dev/null @@ -1,12 +0,0 @@ -package demand.demandObject; - -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.offer.Offer; - -public interface OfferRequester { - - public Collection requestOffers(Collection lsps); - public void setDemandObject(DemandObject demandObject); -} diff --git a/src/demand/demandObject/ShipperShipment.java b/src/demand/demandObject/ShipperShipment.java deleted file mode 100644 index 3910ca5e883..00000000000 --- a/src/demand/demandObject/ShipperShipment.java +++ /dev/null @@ -1,24 +0,0 @@ -package demand.demandObject; - -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.freight.carrier.TimeWindow; - -import lsp.shipment.LSPShipment; - - - -public interface ShipperShipment { - - public Id getId(); - public double getShipmentSize(); - public TimeWindow getStartTimeWindow(); - public void setStartTimeWindow(TimeWindow timeWindow); - public TimeWindow getEndTimeWindow(); - public void setEndTimeWindow(TimeWindow timeWindow); - public double getServiceTime(); - public void setLSPShipment(LSPShipment lspShipment); - public LSPShipment getLSPShipment(); - public void setDemandObject(DemandObject demandObject); - public DemandObject getDemandObject(); - -} diff --git a/src/demand/demandObject/ShipperShipmentImpl.java b/src/demand/demandObject/ShipperShipmentImpl.java deleted file mode 100644 index c673bfdfd1b..00000000000 --- a/src/demand/demandObject/ShipperShipmentImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -package demand.demandObject; - -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.freight.carrier.TimeWindow; - -import lsp.shipment.LSPShipment; - -public class ShipperShipmentImpl implements ShipperShipment{ - - private Id id; - private double shipmentSize; - private TimeWindow startTimeWindow; - private TimeWindow endTimeWindow; - private double serviceTime; - private LSPShipment lspShipment; - private DemandObject demandObject; - - public static class Builder{ - private Id id; - private double shipmentSize; - private TimeWindow startTimeWindow; - private TimeWindow endTimeWindow; - private double serviceTime; - private DemandObject demandObject; - - public static Builder newInstance() { - return new Builder(); - } - - public Builder setId(Id id) { - this.id = id; - return this; - } - - public Builder setShipmentSize(double shipmentSize) { - this.shipmentSize = shipmentSize; - return this; - } - - public Builder setStartTimeWindow(TimeWindow startTimeWindow) { - this.startTimeWindow = startTimeWindow; - return this; - } - - public Builder setEndTimeWindow(TimeWindow endTimeWindow) { - this.endTimeWindow = endTimeWindow; - return this; - } - - public Builder setServiceTime(double serviceTime) { - this.serviceTime = serviceTime; - return this; - } - - public Builder setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - return this; - } - - public ShipperShipment build() { - return new ShipperShipmentImpl(this); - } - } - - private ShipperShipmentImpl(Builder builder) { - this.id = builder.id; - this.shipmentSize = builder.shipmentSize; - if(builder.startTimeWindow == null) { - this.startTimeWindow = TimeWindow.newInstance(0, Double.MAX_VALUE); - } - else { - this.startTimeWindow = builder.startTimeWindow; - } - if(builder.endTimeWindow == null) { - this.endTimeWindow = TimeWindow.newInstance(0, Double.MAX_VALUE); - } - else { - this.endTimeWindow = builder.endTimeWindow; - } - this.serviceTime = builder.serviceTime; - this.demandObject = builder.demandObject; - } - - @Override - public Id getId() { - return id; - } - - @Override - public double getShipmentSize() { - return shipmentSize; - } - - @Override - public TimeWindow getStartTimeWindow() { - return startTimeWindow; - } - - @Override - public TimeWindow getEndTimeWindow() { - return endTimeWindow; - } - - @Override - public double getServiceTime() { - return serviceTime; - } - - @Override - public void setLSPShipment(LSPShipment lspShipment) { - this.lspShipment = lspShipment; - } - - @Override - public LSPShipment getLSPShipment() { - return lspShipment; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - - @Override - public DemandObject getDemandObject() { - return demandObject; - } - - @Override - public void setStartTimeWindow(TimeWindow timeWindow) { - this.startTimeWindow = timeWindow; - } - - @Override - public void setEndTimeWindow(TimeWindow timeWindow) { - this.endTimeWindow = timeWindow; - } - - -} diff --git a/src/demand/mutualReplanning/DemandPlanStrategyImpl.java b/src/demand/mutualReplanning/DemandPlanStrategyImpl.java deleted file mode 100644 index 7f037c3b019..00000000000 --- a/src/demand/mutualReplanning/DemandPlanStrategyImpl.java +++ /dev/null @@ -1,115 +0,0 @@ -package demand.mutualReplanning; - -import java.util.ArrayList; - -import org.apache.log4j.Logger; -import org.matsim.api.core.v01.population.HasPlansAndId; -import org.matsim.core.replanning.GenericPlanStrategy; -import org.matsim.core.replanning.PlanStrategyImpl; -import org.matsim.core.replanning.ReplanningContext; -import org.matsim.core.replanning.modules.GenericPlanStrategyModule; -import org.matsim.core.replanning.selectors.PlanSelector; -import org.matsim.core.replanning.selectors.RandomUnscoredPlanSelector; - -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; - -public class DemandPlanStrategyImpl implements GenericPlanStrategy { - - private PlanSelector planSelector = null; - private OfferReplanningStrategyModule firstModule = null; - private final ArrayList plans = new ArrayList<>(); - private DemandObject demandObject; - - public DemandPlanStrategyImpl(final PlanSelector planSelector) { - this.planSelector = planSelector; - } - - public DemandPlanStrategyImpl(final PlanSelector planSelector, DemandObject demandObject) { - this.planSelector = planSelector; - this.demandObject = demandObject; - } - - public void addStrategyModule(final GenericPlanStrategyModule module) { - try { - OfferReplanningStrategyModule offerModule = (OfferReplanningStrategyModule) module; - offerModule.setDemandObject(demandObject); - this.firstModule = offerModule; - } - catch(ClassCastException e) { - System.out.println("DemandPlanStrategyImpl expects a module of instance OfferReplanningStrategyModule and not any GenericPlanStrategyModule"); - System.exit(1); - } - } - - public int getNumberOfStrategyModules() { - return 1; - } - - @Override - public void run(final HasPlansAndId person) { - - - // if there is at least one unscored plan, find that one: - DemandPlan plan = new RandomUnscoredPlanSelector().selectPlan(person) ; - - // otherwise, find one according to selector (often defined in PlanStrategy ctor): - if (plan == null) { - plan = this.planSelector.selectPlan(person); - } - - // "select" that plan: - if ( plan != null ) { - person.setSelectedPlan(plan); - } - - // if there is a "module" (i.e. "innovation"): - if (this.firstModule != null) { - - // set the working plan to a copy of the selected plan: - plan = person.createCopyOfSelectedPlanAndMakeSelected(); - - // add new plan to container that contains the plans that are handled by this PlanStrategy: - this.plans.add(plan); - - // start working on this new plan: - this.firstModule.handlePlan(plan); - } - - } - - @Override - public void init(ReplanningContext replanningContext0) { - - if (this.firstModule != null) { - this.firstModule.prepareReplanning(replanningContext0); - } - } - - @Override - public void finish() { - if (this.firstModule != null) { - this.firstModule.finishReplanning(); - - } - this.plans.clear(); - } - - public PlanSelector getPlanSelector() { - return planSelector; - } - - public OfferReplanningStrategyModule getModule() { - return firstModule; - } - - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - - public DemandObject getDemandObject() { - return demandObject; - } -} - - diff --git a/src/demand/mutualReplanning/DemandReplanner.java b/src/demand/mutualReplanning/DemandReplanner.java deleted file mode 100644 index 84bef2c7a9f..00000000000 --- a/src/demand/mutualReplanning/DemandReplanner.java +++ /dev/null @@ -1,17 +0,0 @@ -package demand.mutualReplanning; - -import java.util.Collection; - -import org.matsim.core.controler.events.ReplanningEvent; -import org.matsim.core.replanning.GenericStrategyManager; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; - -public interface DemandReplanner { - public void replan(Collection lsps, ReplanningEvent event); - public void addStrategy(DemandPlanStrategyImpl strategy); - public void setDemandObject(DemandObject demandObject); - public DemandObject getDemandObject(); -} diff --git a/src/demand/mutualReplanning/DemandReplannerImpl.java b/src/demand/mutualReplanning/DemandReplannerImpl.java deleted file mode 100644 index 11001b2f664..00000000000 --- a/src/demand/mutualReplanning/DemandReplannerImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -package demand.mutualReplanning; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.core.controler.events.ReplanningEvent; -import org.matsim.core.replanning.GenericPlanStrategy; -import org.matsim.core.replanning.GenericStrategyManager; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; - -public class DemandReplannerImpl implements DemandReplanner{ - - private DemandObject demandObject; - private GenericStrategyManager strategyManager; - - - public DemandReplannerImpl(DemandObject demandObject) { - this.demandObject = demandObject; - this.strategyManager = new GenericStrategyManager(); - } - - public DemandReplannerImpl() { - this.strategyManager = new GenericStrategyManager(); - } - - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - - @Override - public void replan(Collection lsps, ReplanningEvent event) { - for(GenericPlanStrategy strategy : strategyManager.getStrategies(null)) { - DemandPlanStrategyImpl demandPlanStrategy = (DemandPlanStrategyImpl) strategy; - demandPlanStrategy.setDemandObject(demandObject); - demandPlanStrategy.getModule().setDemandObject(demandObject); - demandPlanStrategy.getModule().setLSPS(lsps); - } - - if(strategyManager != null) { - ArrayList demandObjectList = new ArrayList <>(); - demandObjectList.add(demandObject); - strategyManager.run(demandObjectList, null, event.getIteration(), event.getReplanningContext()); - } - - } - - - @Override - public void addStrategy(DemandPlanStrategyImpl strategy) { - strategy.setDemandObject(demandObject); - strategyManager.addStrategy(strategy, null, 1); - } - - @Override - public DemandObject getDemandObject() { - return demandObject; - } - -} diff --git a/src/demand/mutualReplanning/LSPWithOffersReplanner.java b/src/demand/mutualReplanning/LSPWithOffersReplanner.java deleted file mode 100644 index e96f32c14d9..00000000000 --- a/src/demand/mutualReplanning/LSPWithOffersReplanner.java +++ /dev/null @@ -1,80 +0,0 @@ -package demand.mutualReplanning; - -import java.util.ArrayList; - -import org.matsim.core.controler.events.ReplanningEvent; -import org.matsim.core.replanning.GenericStrategyManager; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.offer.OfferUpdater; -import lsp.LSP; -import lsp.LSPPlan; -import lsp.replanning.LSPReplanner; - -public class LSPWithOffersReplanner implements LSPReplanner{ - - private LSPDecorator lsp; - private GenericStrategyManager strategyManager; - private OfferUpdater offerUpdater; - - public LSPWithOffersReplanner(LSPDecorator lsp) { - this.lsp = lsp; - } - - public LSPWithOffersReplanner() { - - } - - @Override - public void replan(ReplanningEvent event) { - if(strategyManager != null) { - ArrayList lspList = new ArrayList (); - lspList.add(lsp); - strategyManager.run(lspList, null, event.getIteration(), event.getReplanningContext()); - } - if(offerUpdater != null) { - offerUpdater.updateOffers(); - } - } - - @Override - public GenericStrategyManager getStrategyManager() { - return strategyManager; - } - - @Override - public void setStrategyManager(GenericStrategyManager strategyManager) { - this.strategyManager = strategyManager; - } - - public void setOfferUpdater(OfferUpdater offerUpdater) { - this.offerUpdater = offerUpdater; - offerUpdater.setLSP(lsp); - } - - public OfferUpdater getOfferUpdater() { - return offerUpdater; - } - - @Override - public void setLSP(LSP lsp) { - try { - this.lsp = (LSPWithOffers) lsp; - if(this.lsp.getOfferUpdater() != null) { - this.offerUpdater = this.lsp.getOfferUpdater(); - } - } - catch(ClassCastException e) { - System.out.println("The class " + this.toString() + " expects an LSPWithOffers and not any other implementation of LSP"); - System.exit(1); - } - } - - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - if(this.lsp.getOfferUpdater() != null) { - this.offerUpdater = this.lsp.getOfferUpdater(); - } - } -} diff --git a/src/demand/mutualReplanning/MutualReplanningModule.java b/src/demand/mutualReplanning/MutualReplanningModule.java deleted file mode 100644 index 4a8a23034a0..00000000000 --- a/src/demand/mutualReplanning/MutualReplanningModule.java +++ /dev/null @@ -1,37 +0,0 @@ -package demand.mutualReplanning; - -import java.util.Collection; - -import org.matsim.core.controler.events.ReplanningEvent; -import org.matsim.core.controler.listener.ReplanningListener; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; - -public abstract class MutualReplanningModule implements ReplanningListener{ - - protected Collection lsps; - protected Collection demandObjects; - - public MutualReplanningModule(Collection lsps, Collection demandObjects) { - this.lsps = lsps; - this.demandObjects = demandObjects; - } - - public void notifyReplanning(ReplanningEvent event) { - replan(event); - } - - public void replan(ReplanningEvent arg0) { - replanLSPs(arg0); - replanDemandObjects(arg0, lsps); - } - - abstract void replanLSPs(ReplanningEvent event); - - abstract void replanDemandObjects(ReplanningEvent event, Collection lsps); - -} - - diff --git a/src/demand/mutualReplanning/MutualReplanningModuleImpl.java b/src/demand/mutualReplanning/MutualReplanningModuleImpl.java deleted file mode 100644 index e9f0b4ce598..00000000000 --- a/src/demand/mutualReplanning/MutualReplanningModuleImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package demand.mutualReplanning; - -import java.util.Collection; - -import org.matsim.core.controler.events.ReplanningEvent; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPDecorators; -import demand.decoratedLSP.LSPWithOffers; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; -import lsp.LSP; - -public class MutualReplanningModuleImpl extends MutualReplanningModule{ - - public MutualReplanningModuleImpl(Collection lsps, Collection demandObjects) { - super(lsps, demandObjects); - } - - @Override - void replanLSPs(ReplanningEvent event) { - for(LSPDecorator lsp : lsps) { - if(lsp.getReplanner()!= null) { - lsp.getReplanner().replan(event); - } - if(lsp.getOfferUpdater()!= null) { - lsp.getOfferUpdater().updateOffers(); - } - } - } - - @Override - void replanDemandObjects(ReplanningEvent event, Collection lsps) { - for(DemandObject demandObject : demandObjects) { - if(demandObject.getReplanner()!= null) { - demandObject.getReplanner().replan(lsps, event); - } - } - } - -} diff --git a/src/demand/mutualReplanning/OfferReplanningStrategyModule.java b/src/demand/mutualReplanning/OfferReplanningStrategyModule.java deleted file mode 100644 index 496d25ddc61..00000000000 --- a/src/demand/mutualReplanning/OfferReplanningStrategyModule.java +++ /dev/null @@ -1,71 +0,0 @@ -package demand.mutualReplanning; - -import java.util.Collection; - -import org.matsim.api.core.v01.Id; -import org.matsim.core.replanning.modules.GenericPlanStrategyModule; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; -import demand.demandObject.DemandPlanImpl; -import demand.offer.Offer; -import lsp.functions.Info; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public abstract class OfferReplanningStrategyModule implements GenericPlanStrategyModule{ - - protected DemandObject demandObject; - protected Collection lsps; - protected DemandPlan plan; - - - public OfferReplanningStrategyModule() { - - } - - public OfferReplanningStrategyModule(DemandObject demandObject) { - this.demandObject = demandObject; - } - - @Override - public void handlePlan(DemandPlan demandPlan) { - Collection offers = recieveOffers(lsps); - plan = createPlan(demandPlan, offers); - demandObject.setSelectedPlan(plan); - } - - protected abstract Collection recieveOffers(Collection lsps); - protected abstract DemandPlan createPlan(DemandPlan demandPlan, Collection offers); - - @Override - public void finishReplanning() { - Id id = Id.create(plan.getShipment().getId(), LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - builder.setFromLinkId(demandObject.getFromLinkId()); - builder.setToLinkId(demandObject.getToLinkId()); - builder.setCapacityDemand((int)plan.getShipment().getShipmentSize()); - builder.setServiceTime(plan.getShipment().getServiceTime()); - builder.setStartTimeWindow(plan.getShipment().getStartTimeWindow()); - builder.setEndTimeWindow(plan.getShipment().getEndTimeWindow()); - for(Info info : demandObject.getInfos()) { - builder.addInfo(info); - } - LSPShipment lspShipment = builder.build(); - plan.getLsp().assignShipmentToSolution(lspShipment, plan.getSolutionId()); - plan.getShipment().setLSPShipment(lspShipment); - } - - public void setLSPS(Collection lsps) { - this.lsps = lsps; - } - - public void setDemandObject (DemandObject demandObject) { - this.demandObject = demandObject; - } - - public DemandObject getDemandObject () { - return demandObject; - } -} diff --git a/src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java b/src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java deleted file mode 100644 index 39291971562..00000000000 --- a/src/demand/mutualReplanning/OfferReplanningStrategyModuleImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package demand.mutualReplanning; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.Id; -import org.matsim.core.replanning.ReplanningContext; -import org.matsim.core.replanning.modules.GenericPlanStrategyModule; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; -import demand.demandObject.DemandPlanImpl; -import demand.offer.Offer; -import lsp.functions.Info; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class OfferReplanningStrategyModuleImpl extends OfferReplanningStrategyModule{ - - - public OfferReplanningStrategyModuleImpl(DemandObject demandObject) { - super(demandObject); - } - - public OfferReplanningStrategyModuleImpl() { - super(); - } - - @Override - public void handlePlan(DemandPlan demandPlan) { - Collection offers = recieveOffers(lsps); - plan = createPlan(demandPlan, offers); - demandObject.setSelectedPlan(plan); - } - - protected Collection recieveOffers(Collection lsps){ - return demandObject.getOfferRequester().requestOffers(lsps); - } - - protected DemandPlan createPlan(DemandPlan demandPlan, Collection offers) { - return demandObject.getDemandPlanGenerator().createDemandPlan(offers); - } - - @Override - public void prepareReplanning(ReplanningContext replanningContext) { - - } - - -} diff --git a/src/demand/offer/DefaultOfferImpl.java b/src/demand/offer/DefaultOfferImpl.java deleted file mode 100644 index b3acf2745cd..00000000000 --- a/src/demand/offer/DefaultOfferImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -package demand.offer; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import lsp.LSP; -import lsp.LogisticsSolution; - -public class DefaultOfferImpl implements Offer { - - private LSPDecorator lsp; - private LogisticsSolutionDecorator solution; - - public DefaultOfferImpl(LSPDecorator lsp, LogisticsSolutionDecorator logisticsSolution) { - this.lsp = lsp; - this.solution = logisticsSolution; - } - - @Override - public LSPDecorator getLsp() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getSolution() { - return solution; - } - - @Override - public String getType() { - return "DEFAULT"; - } - - public void update() { - - } - - @Override - public void accept(OfferVisitor visitor) { - visitor.visit(this); - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public void setSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - - -} diff --git a/src/demand/offer/Offer.java b/src/demand/offer/Offer.java deleted file mode 100644 index dcee02dcd3d..00000000000 --- a/src/demand/offer/Offer.java +++ /dev/null @@ -1,17 +0,0 @@ -package demand.offer; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import lsp.LSP; -import lsp.LogisticsSolution; - -public interface Offer { - - public LSPDecorator getLsp(); - public LogisticsSolutionDecorator getSolution(); - public String getType(); - public void accept(OfferVisitor visitor); - public void update(); - public void setLSP (LSPDecorator lsp); - public void setSolution(LogisticsSolutionDecorator solution); -} diff --git a/src/demand/offer/OfferFactory.java b/src/demand/offer/OfferFactory.java deleted file mode 100644 index 68738c5cdc2..00000000000 --- a/src/demand/offer/OfferFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -package demand.offer; - -import java.util.Collection; - -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.demandObject.DemandObject; -import lsp.LSP; -import lsp.LogisticsSolution; - -public interface OfferFactory { - - public Offer makeOffer(DemandObject object, String offerType); - public Collection getOffers(); - public LSPDecorator getLSP(); - public LogisticsSolutionDecorator getLogisticsSolution(); - public void setLogisticsSolution(LogisticsSolutionDecorator solution); - public void setLSP(LSPDecorator lsp); - public void addOffer(Offer offer); -} diff --git a/src/demand/offer/OfferFactoryImpl.java b/src/demand/offer/OfferFactoryImpl.java deleted file mode 100644 index 71b9d20bb26..00000000000 --- a/src/demand/offer/OfferFactoryImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -package demand.offer; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.demandObject.DemandObject; -import demand.offer.DefaultOfferImpl; -import demand.offer.Offer; -import demand.offer.OfferFactory; -import lsp.LSP; -import lsp.LogisticsSolution; - -public class OfferFactoryImpl implements OfferFactory{ - - - private ArrayList offerList; - private LogisticsSolutionDecorator solution; - private LSPDecorator lsp; - - public OfferFactoryImpl(LogisticsSolutionDecorator solution) { - this.solution = solution; - this.lsp = solution.getLSP(); - offerList = new ArrayList(); - } - - @Override - public Offer makeOffer(DemandObject object, String offerType) { - for(Offer offer : offerList) { - if(offer.getType() == offerType) { - offer.setLSP(lsp); - return offer; - } - } - return new DefaultOfferImpl(this.lsp, this.solution); - } - - @Override - public Collection getOffers() { - return offerList; - } - - @Override - public LSPDecorator getLSP() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getLogisticsSolution() { - return solution; - } - - @Override - public void setLogisticsSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public void addOffer(Offer offer) { - offer.setLSP(lsp); - offer.setSolution(solution); - offerList.add(offer); - } - - -} diff --git a/src/demand/offer/OfferTransferrer.java b/src/demand/offer/OfferTransferrer.java deleted file mode 100644 index 5b2df94ea8f..00000000000 --- a/src/demand/offer/OfferTransferrer.java +++ /dev/null @@ -1,16 +0,0 @@ -package demand.offer; - -import org.matsim.api.core.v01.Id; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.demandObject.DemandObject; -import lsp.LSP; -import lsp.LogisticsSolution; - -public interface OfferTransferrer { - - public Offer transferOffer(DemandObject object, String type, Id solutionId); - public void setLSP(LSPDecorator lsp); - public LSPDecorator getLSP(); -} diff --git a/src/demand/offer/OfferTransferrerImpl.java b/src/demand/offer/OfferTransferrerImpl.java deleted file mode 100644 index dcc04748732..00000000000 --- a/src/demand/offer/OfferTransferrerImpl.java +++ /dev/null @@ -1,38 +0,0 @@ -package demand.offer; - -import org.matsim.api.core.v01.Id; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.demandObject.DemandObject; -import lsp.LogisticsSolution; - -public class OfferTransferrerImpl implements OfferTransferrer{ - - private LSPDecorator lsp; - - - @Override - public Offer transferOffer(DemandObject object, String type, Id solutionId) { - for(LogisticsSolution planSolution : lsp.getSelectedPlan().getSolutions()) { - if(planSolution instanceof LogisticsSolutionDecorator) { - LogisticsSolutionDecorator offerSolution = (LogisticsSolutionDecorator) planSolution; - if(offerSolution.getId() == solutionId) { - if(!(offerSolution.getOffer(object, type) instanceof DefaultOfferImpl)) { - return offerSolution.getOffer(object, type); - } - } - } - } - return new DefaultOfferImpl(lsp, null); - } - - public void setLSP(LSPDecorator lsp){ - this.lsp = lsp; - } - - public LSPDecorator getLSP(){ - return lsp; - } -} - diff --git a/src/demand/offer/OfferUpdater.java b/src/demand/offer/OfferUpdater.java deleted file mode 100644 index 5a84ef6f479..00000000000 --- a/src/demand/offer/OfferUpdater.java +++ /dev/null @@ -1,12 +0,0 @@ -package demand.offer; - -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; - -public interface OfferUpdater { - - public void updateOffers(); - public Collection getOfferVisitors(); - public void setLSP (LSPDecorator lsp); -} diff --git a/src/demand/offer/OfferUpdaterImpl.java b/src/demand/offer/OfferUpdaterImpl.java deleted file mode 100644 index d57c88f47c9..00000000000 --- a/src/demand/offer/OfferUpdaterImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package demand.offer; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import lsp.LogisticsSolution; - -public class OfferUpdaterImpl implements OfferUpdater{ - - private LSPDecorator lsp; - private Collection visitors; - - public OfferUpdaterImpl() { - this.visitors = new ArrayList(); - } - - - @Override - public void updateOffers() { - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - if(solution instanceof LogisticsSolutionDecorator) { - LogisticsSolutionDecorator offerSolution = (LogisticsSolutionDecorator) solution; - for(OfferVisitor visitor : visitors) { - if(visitor.getLogisticsSolution() == solution) { - for(Offer offer : offerSolution.getOfferFactory().getOffers()) { - if(offer.getClass() == visitor.getOfferClass()) { - visitor.visit(offer); - } - } - } - } - } - } - - } - - @Override - public Collection getOfferVisitors() { - return visitors; - } - - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } -} diff --git a/src/demand/offer/OfferVisitor.java b/src/demand/offer/OfferVisitor.java deleted file mode 100644 index 59bdf105677..00000000000 --- a/src/demand/offer/OfferVisitor.java +++ /dev/null @@ -1,10 +0,0 @@ -package demand.offer; - -import lsp.LogisticsSolution; - -public interface OfferVisitor { - - public void visit(Offer offer); - public Class getOfferClass(); - public LogisticsSolution getLogisticsSolution(); -} diff --git a/src/demand/scoring/DemandScorer.java b/src/demand/scoring/DemandScorer.java deleted file mode 100644 index 5ef870fba78..00000000000 --- a/src/demand/scoring/DemandScorer.java +++ /dev/null @@ -1,10 +0,0 @@ -package demand.scoring; - -import demand.demandObject.DemandObject; -import lsp.scoring.Scorer; - -public interface DemandScorer extends Scorer{ - - public double scoreCurrentPlan(DemandObject demandObject); - public void setDemandObject(DemandObject demandObject); -} diff --git a/src/demand/scoring/MutualScoringModuleImpl.java b/src/demand/scoring/MutualScoringModuleImpl.java deleted file mode 100644 index f0bc1c90439..00000000000 --- a/src/demand/scoring/MutualScoringModuleImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -package demand.scoring; - -import java.util.Collection; - -import org.matsim.core.controler.events.ScoringEvent; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; - - -public class MutualScoringModuleImpl implements MutualScoringModule{ - - private Collection demandObjects; - private Collection lsps; - - public MutualScoringModuleImpl(Collection demandObjects, Collection lsps) { - this.demandObjects = demandObjects; - this.lsps = lsps; - } - - @Override - public void notifyScoring(ScoringEvent event) { - scoreDemandObjects(event); - scoreLSPs(event); - } - - @Override - public void scoreDemandObjects(ScoringEvent event) { - for(DemandObject demandObject : demandObjects) { - if(demandObject.getScorer() != null) { - demandObject.scoreSelectedPlan(); - } - } - } - - @Override - public void scoreLSPs(ScoringEvent event) { - for(LSPDecorator lsp : lsps) { - if(lsp.getScorer() != null) { - lsp.scoreSelectedPlan(); - } - } - - } -} diff --git a/src/demand/utilityFunctions/UtilityFunction.java b/src/demand/utilityFunctions/UtilityFunction.java deleted file mode 100644 index ab3932addd8..00000000000 --- a/src/demand/utilityFunctions/UtilityFunction.java +++ /dev/null @@ -1,11 +0,0 @@ -package demand.utilityFunctions; - -import demand.demandObject.ShipperShipment; -import demand.offer.Offer; - -public interface UtilityFunction { - - public String getName(); - public double getUtilityValue(Offer offer, ShipperShipment shipment); - -} diff --git a/src/main/java/lsp/ForwardSolutionSchedulerImpl.java b/src/main/java/lsp/ForwardSolutionSchedulerImpl.java new file mode 100644 index 00000000000..0a1144c623a --- /dev/null +++ b/src/main/java/lsp/ForwardSolutionSchedulerImpl.java @@ -0,0 +1,135 @@ +package lsp; + +import java.util.ArrayList; + +import lsp.resources.Resource; +import lsp.shipment.LSPShipment; + +public class ForwardSolutionSchedulerImpl implements SolutionScheduler { + + private class ResourceNeighbours{ + private ArrayList predecessors; + private ArrayList successors; + private Resource resource; + + private ResourceNeighbours(Resource resource) { + this.resource = resource; + this.predecessors = new ArrayList(); + this.successors = new ArrayList(); + } + + private void addPredecessor(Resource resource) { + this.predecessors.add(resource); + } + + private void addSuccessor(Resource resource) { + this.successors.add(resource); + } + } + + private LSP lsp; + private ArrayList sortedResourceList; + private ArrayList neighbourList; + private int bufferTime; + + public ForwardSolutionSchedulerImpl() { + this.sortedResourceList = new ArrayList(); + this.neighbourList = new ArrayList(); + } + + + @Override + public void scheduleSolutions() { + insertShipmentsAtBeginning(); + setResourceNeighbours(); + sortResources(); + for(Resource resource : sortedResourceList ) { + resource.schedule(bufferTime); + } + + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + private void setResourceNeighbours() { + neighbourList.clear(); + for(Resource resource : lsp.getResources()) { + ResourceNeighbours neighbours = new ResourceNeighbours(resource); + for(LogisticsSolutionElement element : resource.getClientElements()) { + LogisticsSolutionElement predecessor = element.getPreviousElement(); + Resource previousResource = predecessor.getResource(); + neighbours.addPredecessor(previousResource); + LogisticsSolutionElement successor = element.getNextElement(); + Resource nextResource = successor.getResource(); + neighbours.addSuccessor(nextResource); + } + neighbourList.add(neighbours); + } + } + + private void sortResources() { + sortedResourceList.clear(); + while(!neighbourList.isEmpty()) { + for(ResourceNeighbours neighbours : neighbourList) { + if(allPredecessorsAlreadyScheduled(neighbours) && noSuccessorAlreadyScheduled(neighbours)) { + sortedResourceList.add(neighbours.resource); + neighbourList.remove(neighbours); + } + } + } + } + + private boolean allPredecessorsAlreadyScheduled(ResourceNeighbours neighbours) { + if(neighbours.predecessors.isEmpty()) { + return true; + } + + for(Resource predecessor : neighbours.predecessors) { + if(!sortedResourceList.contains(predecessor)) { + return true; + } + } + return false; + } + + private boolean noSuccessorAlreadyScheduled(ResourceNeighbours neighbours) { + if(neighbours.successors.isEmpty()) { + return true; + } + + for(Resource successor : neighbours.successors) { + if(! sortedResourceList.contains(successor)) { + return true; + } + } + return false; + } + + private void insertShipmentsAtBeginning() { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + LogisticsSolutionElement firstElement = getFirstElement(solution); + for(LSPShipment shipment : solution.getShipments() ) { + firstElement.getIncomingShipments().addShipment(shipment.getStartTimeWindow().getStart(), shipment); + } + } + } + + private LogisticsSolutionElement getFirstElement(LogisticsSolution solution){ + for(LogisticsSolutionElement element : solution.getSolutionElements()){ + if(element.getPreviousElement() == null){ + return element; + } + + } + return null; + } + + + @Override + public void setBufferTime(int bufferTime) { + this.bufferTime = bufferTime; + } +} diff --git a/src/main/java/lsp/HasEventHandlers.java b/src/main/java/lsp/HasEventHandlers.java new file mode 100644 index 00000000000..4e92ee78307 --- /dev/null +++ b/src/main/java/lsp/HasEventHandlers.java @@ -0,0 +1,10 @@ +package lsp; + +import java.util.Collection; + +import org.matsim.core.events.handler.EventHandler; + +public interface HasEventHandlers { + + public CollectiongetEventHandlers(); +} diff --git a/src/main/java/lsp/LSP.java b/src/main/java/lsp/LSP.java new file mode 100644 index 00000000000..de31d7d2d01 --- /dev/null +++ b/src/main/java/lsp/LSP.java @@ -0,0 +1,42 @@ +package lsp; + +import java.util.ArrayList; +import java.util.Collection; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.HasPlansAndId; + +import lsp.resources.Resource; +import lsp.replanning.LSPReplanner; +import lsp.scoring.LSPScorer; +import lsp.shipment.LSPShipment; + +public interface LSP extends HasPlansAndId{ + + public Id getId(); + + public Collection getShipments(); + + public void scheduleSoultions(); + + public ArrayList getPlans(); + + public Collection getResources(); + + public LSPPlan getSelectedPlan(); + + public void setSelectedPlan(LSPPlan plan); + + public void scoreSelectedPlan(); + + public LSPReplanner getReplanner(); + + public void assignShipmentToLSP(LSPShipment shipment); + + public LSPScorer getScorer(); + + public void setScorer(LSPScorer scorer); + + public void setReplanner(LSPReplanner replanner); + + public SolutionScheduler getScheduler(); +} \ No newline at end of file diff --git a/src/main/java/lsp/LSPImpl.java b/src/main/java/lsp/LSPImpl.java new file mode 100644 index 00000000000..f2760377d08 --- /dev/null +++ b/src/main/java/lsp/LSPImpl.java @@ -0,0 +1,238 @@ +package lsp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.resources.Resource; +import lsp.replanning.LSPReplanner; +import lsp.scoring.LSPScorer; +import lsp.shipment.LSPShipment; + +public class LSPImpl implements LSP { + + private Id id; + private Collection shipments; + private ArrayList plans; + private SolutionScheduler solutionScheduler; + private LSPPlan selectedPlan; + private Collection resources; + private LSPScorer scorer; + private LSPReplanner replanner; + + public static class Builder{ + private Id id; + private SolutionScheduler solutionScheduler; + private LSPPlan initialPlan; + private Collection resources; + private LSPScorer scorer; + private LSPReplanner replanner; + + + + public static Builder getInstance(){ + return new Builder(); + } + + private Builder(){ + this.resources = new ArrayList(); + + } + + public Builder setSolutionScheduler(SolutionScheduler solutionScheduler){ + this.solutionScheduler = solutionScheduler; + return this; + } + + public Builder setSolutionScorer(LSPScorer scorer){ + this.scorer = scorer; + return this; + } + + public Builder setReplanner(LSPReplanner replanner){ + this.replanner= replanner; + return this; + } + + + public Builder setInitialPlan(LSPPlan plan){ + this.initialPlan = plan; + for(LogisticsSolution solution : plan.getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(!resources.contains(element.getResource())) { + resources.add(element.getResource()); + } + } + } + return this; + } + + public Builder setId(Id id){ + this.id = id; + return this; + } + + public LSPImpl build(){ + return new LSPImpl(this); + } + + } + + + private LSPImpl(LSPImpl.Builder builder){ + this.shipments = new ArrayList(); + this.plans= new ArrayList(); + this.id = builder.id; + this.solutionScheduler = builder.solutionScheduler; + this.solutionScheduler.setLSP(this); + this.selectedPlan=builder.initialPlan; + this.selectedPlan.setLSP(this); + this.plans.add(builder.initialPlan); + this.resources = builder.resources; + this.scorer = builder.scorer; + if(this.scorer != null) { + this.scorer.setLSP(this); + } + this.replanner = builder.replanner; + if(this.replanner != null) { + this.replanner.setLSP(this); + } + } + + + @Override + public Id getId() { + return id; + } + + @Override + public Collection getShipments() { + return shipments; + } + + + @Override + public void scheduleSoultions() { + solutionScheduler.scheduleSolutions(); + } + + + @Override + public boolean addPlan(LSPPlan plan) { + for(LogisticsSolution solution : plan.getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(!resources.contains(element.getResource())) { + resources.add(element.getResource()); + } + } + } + return plans.add(plan); + } + + + @Override + public LSPPlan createCopyOfSelectedPlanAndMakeSelected() { + LSPPlan newPlan = LSPImpl.copyPlan(this.selectedPlan) ; + this.setSelectedPlan( newPlan ) ; + return newPlan ; + } + + + @Override + public ArrayList getPlans() { + return plans; + } + + + @Override + public LSPPlan getSelectedPlan() { + return selectedPlan; + } + + + @Override + public boolean removePlan(LSPPlan plan) { + if(plans.contains(plan)) { + plans.remove(plan); + return true; + } + else { + return false; + } + } + + + @Override + public void setSelectedPlan(LSPPlan selectedPlan) { + if(!plans.contains(selectedPlan)) { + plans.add(selectedPlan); + } + this.selectedPlan = selectedPlan; + + } + + public static LSPPlan copyPlan(LSPPlan plan2copy) { + List copiedSolutions = new ArrayList(); + for (LogisticsSolution solution : plan2copy.getSolutions()) { + LogisticsSolutionImpl copiedSolution = LogisticsSolutionImpl.Builder.newInstance(solution.getId()).build(); + copiedSolution.getSolutionElements().addAll(solution.getSolutionElements()); + copiedSolutions.add(copiedSolution); + } + LSPPlan copiedPlan = new LSPPlanImpl(); + copiedPlan.setAssigner(plan2copy.getAssigner()); + copiedPlan.setLSP(plan2copy.getLsp()); + double initialScoreOfCopiedPlan = plan2copy.getScore(); + copiedPlan.setScore(initialScoreOfCopiedPlan); + copiedPlan.getSolutions().addAll(copiedSolutions); + return copiedPlan; + } + + + @Override + public Collection getResources() { + return resources; + } + + public void scoreSelectedPlan() { + double score = scorer.scoreCurrentPlan(this); + this.selectedPlan.setScore(score); + } + + public LSPReplanner getReplanner() { + return replanner; + } + + + @Override + public void assignShipmentToLSP(LSPShipment shipment) { + shipments.add(shipment); + selectedPlan.getAssigner().assignShipment(shipment); + } + + + @Override + public LSPScorer getScorer() { + return scorer; + } + + @Override + public void setScorer(LSPScorer scorer) { + this.scorer = scorer; + } + + + @Override + public void setReplanner(LSPReplanner replanner) { + this.replanner = replanner; + } + + + @Override + public SolutionScheduler getScheduler() { + return solutionScheduler; + } + +} diff --git a/src/main/java/lsp/LSPPlan.java b/src/main/java/lsp/LSPPlan.java new file mode 100644 index 00000000000..732b413cd3b --- /dev/null +++ b/src/main/java/lsp/LSPPlan.java @@ -0,0 +1,21 @@ +package lsp; + +import java.util.Collection; + +import org.matsim.api.core.v01.population.BasicPlan; + +public interface LSPPlan extends BasicPlan{ + + public void addSolution (LogisticsSolution solution); + + public Collection getSolutions(); + + public ShipmentAssigner getAssigner(); + + public void setAssigner(ShipmentAssigner assigner); + + public void setLSP(LSP lsp); + + public LSP getLsp(); + +} diff --git a/src/main/java/lsp/LSPPlanImpl.java b/src/main/java/lsp/LSPPlanImpl.java new file mode 100644 index 00000000000..563f995632e --- /dev/null +++ b/src/main/java/lsp/LSPPlanImpl.java @@ -0,0 +1,62 @@ + +package lsp; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.population.BasicPlan; + +public class LSPPlanImpl implements LSPPlan{ + + private LSP lsp; + private double score; + private Collection solutions; + private ShipmentAssigner assigner; + + public LSPPlanImpl() { + this.solutions = new ArrayList(); + } + + public void addSolution (LogisticsSolution solution) { + this.solutions.add(solution); + solution.setLSP(this.lsp); + } + + public Collection getSolutions() { + return solutions; + } + + public ShipmentAssigner getAssigner() { + return assigner; + } + + public void setAssigner(ShipmentAssigner assigner) { + this.assigner = assigner; + this.assigner.setLSP(this.lsp); + } + + @Override + public Double getScore() { + return score; + } + + @Override + public void setScore(Double score) { + this.score = score; + } + + public void setLSP(LSP lsp) { + this.lsp = lsp; + if(assigner != null) { + this.assigner.setLSP(lsp); + } + for(LogisticsSolution solution : solutions) { + solution.setLSP(lsp); + } + } + + public LSP getLsp() { + return lsp; + } + +} diff --git a/src/main/java/lsp/LSPs.java b/src/main/java/lsp/LSPs.java new file mode 100644 index 00000000000..4319c27cfa4 --- /dev/null +++ b/src/main/java/lsp/LSPs.java @@ -0,0 +1,36 @@ +package lsp; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.matsim.api.core.v01.Id; + +public class LSPs { + + private Map, LSP> lsps = new HashMap<>(); + + public LSPs(Collection lsps) { + makeMap(lsps); + } + + private void makeMap(Collection lsps) { + for (LSP c : lsps) { + this.lsps.put(c.getId(), c); + } + } + + public LSPs() { + + } + + public Map, LSP> getLSPs() { + return lsps; + } + + public void addLSP(LSP lsp) { + if(!lsps.containsKey(lsp.getId())){ + lsps.put(lsp.getId(), lsp); + } + } +} diff --git a/src/main/java/lsp/LogisticsSolution.java b/src/main/java/lsp/LogisticsSolution.java new file mode 100644 index 00000000000..ef1d82698a2 --- /dev/null +++ b/src/main/java/lsp/LogisticsSolution.java @@ -0,0 +1,37 @@ +package lsp; + +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.shipment.LSPShipment; +import lsp.tracking.SimulationTracker; + + +public interface LogisticsSolution { + + public Id getId(); + + public void setLSP(LSP lsp); + + public LSP getLSP(); + + public Collection getSolutionElements(); + + public Collection getShipments(); + + public void assignShipment(LSPShipment shipment); + + public Collection getInfos(); + + public Collection getEventHandlers(); + + public void addSimulationTracker(SimulationTracker tracker); + + public Collection getSimulationTrackers(); + + public void setEventsManager(EventsManager eventsManager); +} diff --git a/src/main/java/lsp/LogisticsSolutionElement.java b/src/main/java/lsp/LogisticsSolutionElement.java new file mode 100644 index 00000000000..576a12a9230 --- /dev/null +++ b/src/main/java/lsp/LogisticsSolutionElement.java @@ -0,0 +1,47 @@ +package lsp; + +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.resources.Resource; +import lsp.tracking.SimulationTracker; + + +public interface LogisticsSolutionElement { + + public Id getId(); + + public void setLogisticsSolution(LogisticsSolution solution); + + public LogisticsSolution getLogisticsSolution(); + + public void setPreviousElement(LogisticsSolutionElement element); + + public void setNextElement(LogisticsSolutionElement element); + + public Resource getResource(); + + public LogisticsSolutionElement getPreviousElement(); + + public LogisticsSolutionElement getNextElement(); + + public WaitingShipments getIncomingShipments(); + + public WaitingShipments getOutgoingShipments(); + + public void schedulingOfResourceCompleted(); + + public void addSimulationTracker(SimulationTracker tracker); + + public Collection getInfos(); + + public Collection getEventHandlers(); + + public Collection getSimulationTrackers(); + + public void setEventsManager(EventsManager eventsManager); +} diff --git a/src/main/java/lsp/LogisticsSolutionElementImpl.java b/src/main/java/lsp/LogisticsSolutionElementImpl.java new file mode 100644 index 00000000000..e798db6741b --- /dev/null +++ b/src/main/java/lsp/LogisticsSolutionElementImpl.java @@ -0,0 +1,153 @@ +package lsp; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.resources.Resource; +import lsp.tracking.SimulationTracker; + + + +public class LogisticsSolutionElementImpl implements LogisticsSolutionElement { + + private Idid; + //die beiden nicht im Builder. Die können erst in der Solution als ganzes gesetzt werden + private LogisticsSolutionElement previousElement; + private LogisticsSolutionElement nextElement; + private Resource resource; + private WaitingShipments incomingShipments; + private WaitingShipments outgoingShipments; + private LogisticsSolution solution; + private Collection infos; + private Collection trackers; + private Collection handlers; + private EventsManager eventsManager; + + public static class Builder { + private Idid; + private Resource resource; + private WaitingShipments incomingShipments; + private WaitingShipments outgoingShipments; + + public static Builder newInstance(Idid){ + return new Builder(id); + } + + private Builder(Idid){ + this.id = id; + this.incomingShipments = new WaitingShipmentsImpl(); + this.outgoingShipments = new WaitingShipmentsImpl(); + } + + + public Builder setResource(Resource resource){ + this.resource = resource; + return this; + } + + public LogisticsSolutionElementImpl build(){ + return new LogisticsSolutionElementImpl(this); + } + } + + private LogisticsSolutionElementImpl(LogisticsSolutionElementImpl.Builder builder){ + this.id = builder.id; + this.resource = builder.resource; + this.incomingShipments = builder.incomingShipments; + this.outgoingShipments = builder.outgoingShipments; + resource.getClientElements().add(this); + this.handlers = new ArrayList(); + this.infos = new ArrayList(); + this.trackers = new ArrayList(); + } + + @Override + public Id getId() { + return id; + } + + @Override + public void setPreviousElement(LogisticsSolutionElement element) { + this.previousElement = element; + } + + @Override + public void setNextElement(LogisticsSolutionElement element) { + this.nextElement =element; + } + + @Override + public Resource getResource() { + return resource; + } + + @Override + public WaitingShipments getIncomingShipments() { + return incomingShipments; + } + + @Override + public WaitingShipments getOutgoingShipments() { + return outgoingShipments; + } + + @Override + public void schedulingOfResourceCompleted() { + for(ShipmentTuple tuple : outgoingShipments.getSortedShipments()){ + nextElement.getIncomingShipments().addShipment(tuple.getTime(), tuple.getShipment()); + } + } + + @Override + public void setLogisticsSolution(LogisticsSolution solution) { + this.solution = solution; + } + + @Override + public LogisticsSolution getLogisticsSolution() { + return solution; + } + + @Override + public LogisticsSolutionElement getPreviousElement() { + return previousElement; + } + + @Override + public LogisticsSolutionElement getNextElement() { + return nextElement; + } + + @Override + public void addSimulationTracker(SimulationTracker tracker) { + trackers.add(tracker); + infos.addAll(tracker.getInfos()); + handlers.addAll(tracker.getEventHandlers()); + } + + @Override + public Collection getInfos() { + return infos; + } + + public Collection getEventHandlers(){ + return handlers; + } + + @Override + public Collection getSimulationTrackers() { + return trackers; + } + + @Override + public void setEventsManager(EventsManager eventsManager) { + this.eventsManager = eventsManager; + } + + +} diff --git a/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java b/src/main/java/lsp/LogisticsSolutionImpl.java similarity index 60% rename from src/demand/decoratedLSP/LogisticsSolutionWithOffers.java rename to src/main/java/lsp/LogisticsSolutionImpl.java index 2f5e62bedf8..be33a04e88e 100644 --- a/src/demand/decoratedLSP/LogisticsSolutionWithOffers.java +++ b/src/main/java/lsp/LogisticsSolutionImpl.java @@ -1,35 +1,27 @@ -package demand.decoratedLSP; +package lsp; import java.util.ArrayList; import java.util.Collection; - +import java.util.TreeMap; import org.matsim.api.core.v01.Id; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.events.handler.EventHandler; -import demand.demandObject.DemandObject; -import demand.offer.Offer; -import demand.offer.OfferFactory; import lsp.functions.Info; -import lsp.LogisticsSolutionImpl; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionImpl.Builder; import lsp.shipment.LSPShipment; import lsp.tracking.SimulationTracker; -public class LogisticsSolutionWithOffers implements LogisticsSolutionDecorator { +public class LogisticsSolutionImpl implements LogisticsSolution { + private Id id; - private LSPWithOffers lsp; + private LSP lsp; private Collection solutionElements; private Collection shipments; private Collection solutionInfos; private Collection eventHandlers; private Collectiontrackers; private EventsManager eventsManager; - private OfferFactory offerFactory; public static class Builder{ private Id id; @@ -37,7 +29,6 @@ public static class Builder{ private Collection solutionInfos; private Collection eventHandlers; private Collectiontrackers; - private OfferFactory offerFactory; public static Builder newInstance(Idid){ return new Builder(id); @@ -71,18 +62,33 @@ public Builder addTracker(SimulationTracker tracker) { return this; } - public Builder addOfferFactory(OfferFactory offerFactory) { - this.offerFactory = offerFactory; - return this; - } - - public LogisticsSolutionWithOffers build(){ - return new LogisticsSolutionWithOffers(this); + public LogisticsSolutionImpl build(){ + //linkSolutionElements(elements); + return new LogisticsSolutionImpl(this); } + + /*private void linkSolutionElements(Collection solutionElements){ + + LogisticsSolutionElement previousElement = null; + LogisticsSolutionElement currentElement = null; + + + for(LogisticsSolutionElement element : solutionElements){ + if((previousElement == null) && (currentElement == null)){ + previousElement = element; + } + else{ + currentElement = element; + previousElement.setNextElement(currentElement); + currentElement.setPreviousElement(previousElement); + previousElement = currentElement; + } + } + }*/ } - private LogisticsSolutionWithOffers(LogisticsSolutionWithOffers.Builder builder){ + private LogisticsSolutionImpl(LogisticsSolutionImpl.Builder builder){ this.id = builder.id; this.solutionElements = builder.elements; for(LogisticsSolutionElement element : this.solutionElements) { @@ -92,15 +98,9 @@ private LogisticsSolutionWithOffers(LogisticsSolutionWithOffers.Builder builder) this.solutionInfos = builder.solutionInfos; this.eventHandlers = builder.eventHandlers; this.trackers = builder.trackers; - this.offerFactory = builder.offerFactory; - if(this.offerFactory != null) { - this.offerFactory.setLogisticsSolution(this); - this.offerFactory.setLSP(lsp); - } } - @Override public Id getId() { return id; @@ -108,20 +108,14 @@ public Id getId() { @Override public void setLSP(LSP lsp) { - try { - this.lsp = (LSPWithOffers) lsp; - } - catch(ClassCastException e) { - System.out.println("The class " + this.toString() + " expects an LSPWithOffers and not any other implementation of LSP"); - System.exit(1); - } + this.lsp = lsp; } @Override - public LSPDecorator getLSP() { + public LSP getLSP() { return lsp; } - + @Override public Collection getSolutionElements() { return solutionElements; @@ -134,29 +128,21 @@ public Collection getShipments() { @Override public void assignShipment(LSPShipment shipment) { - shipments.add(shipment); + shipments.add(shipment); } - private LogisticsSolutionElement getFirstElement(){ - for(LogisticsSolutionElement element : solutionElements){ - if(element.getPreviousElement() == null){ - return element; - } - - } - return null; - } - @Override public Collection getInfos() { return solutionInfos; } + @Override public Collection getEventHandlers() { return eventHandlers; } + @Override public void addSimulationTracker(SimulationTracker tracker) { this.trackers.add(tracker); @@ -164,6 +150,7 @@ public void addSimulationTracker(SimulationTracker tracker) { this.solutionInfos.addAll(tracker.getInfos()); } + @Override public Collection getSimulationTrackers() { return trackers; @@ -174,21 +161,4 @@ public void setEventsManager(EventsManager eventsManager) { this.eventsManager = eventsManager; } - @Override - public Offer getOffer(DemandObject object, String type) { - return offerFactory.makeOffer(object, type); - } - - @Override - public void setOfferFactory(OfferFactory factory) { - this.offerFactory = factory; - this.offerFactory.setLogisticsSolution(this); - this.offerFactory.setLSP(lsp); - } - - @Override - public OfferFactory getOfferFactory() { - return offerFactory; - } - -} +} \ No newline at end of file diff --git a/src/main/java/lsp/ShipmentAssigner.java b/src/main/java/lsp/ShipmentAssigner.java new file mode 100644 index 00000000000..6afdc37d879 --- /dev/null +++ b/src/main/java/lsp/ShipmentAssigner.java @@ -0,0 +1,10 @@ +package lsp; + +import lsp.shipment.LSPShipment; + +public interface ShipmentAssigner { + + public void assignShipment(LSPShipment shipment); + public void setLSP(LSP lsp); + public LSP getLSP(); +} diff --git a/src/main/java/lsp/ShipmentTuple.java b/src/main/java/lsp/ShipmentTuple.java new file mode 100644 index 00000000000..5040ce3771f --- /dev/null +++ b/src/main/java/lsp/ShipmentTuple.java @@ -0,0 +1,23 @@ +package lsp; + + +import lsp.shipment.LSPShipment; + +public class ShipmentTuple { + private LSPShipment shipment; + private double time; + + public ShipmentTuple(double time ,LSPShipment shipment) { + this.shipment= shipment; + this.time = time; + } + + public LSPShipment getShipment() { + return shipment; + } + + public double getTime() { + return time; + } + +} diff --git a/src/main/java/lsp/SolutionScheduler.java b/src/main/java/lsp/SolutionScheduler.java new file mode 100644 index 00000000000..834ebabd9f4 --- /dev/null +++ b/src/main/java/lsp/SolutionScheduler.java @@ -0,0 +1,12 @@ +package lsp; + + + +public interface SolutionScheduler { + + public void scheduleSolutions(); + + public void setLSP(LSP lsp); + + public void setBufferTime(int bufferTime); +} diff --git a/src/main/java/lsp/WaitingShipments.java b/src/main/java/lsp/WaitingShipments.java new file mode 100644 index 00000000000..c0f38c92d52 --- /dev/null +++ b/src/main/java/lsp/WaitingShipments.java @@ -0,0 +1,17 @@ +package lsp; + +import java.util.Collection; + +import lsp.shipment.LSPShipment; + +public interface WaitingShipments { + + public void addShipment(double time ,LSPShipment shipment); + + public Collection getSortedShipments(); + + public Collection getShipments(); + + public void clear(); + +} diff --git a/src/main/java/lsp/WaitingShipmentsImpl.java b/src/main/java/lsp/WaitingShipmentsImpl.java new file mode 100644 index 00000000000..802844b59f3 --- /dev/null +++ b/src/main/java/lsp/WaitingShipmentsImpl.java @@ -0,0 +1,43 @@ +package lsp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; + +import lsp.shipment.LSPShipment; +import lsp.shipment.ShipmentComparator; + +public class WaitingShipmentsImpl implements WaitingShipments { + + + private ArrayList shipments; + + public WaitingShipmentsImpl() { + this.shipments = new ArrayList(); + } + + + @Override + public void addShipment(double time, LSPShipment shipment) { + ShipmentTuple tuple = new ShipmentTuple(time, shipment); + this.shipments.add(tuple); + Collections.sort(shipments, new ShipmentComparator()); + } + + @Override + public Collection getSortedShipments() { + Collections.sort(shipments, new ShipmentComparator()); + return shipments; + } + + public void clear(){ + shipments.clear(); + } + + @Override + public Collection getShipments() { + return shipments; + } + +} diff --git a/src/main/java/lsp/controler/FreightControlerListener.java b/src/main/java/lsp/controler/FreightControlerListener.java new file mode 100644 index 00000000000..094682c4c66 --- /dev/null +++ b/src/main/java/lsp/controler/FreightControlerListener.java @@ -0,0 +1,9 @@ +package lsp.controler; + +import org.matsim.api.core.v01.events.Event; + +public interface FreightControlerListener { + + public void processEvent(Event event); + +} diff --git a/src/demand/controler/MutualControlerListener.java b/src/main/java/lsp/controler/LSPControlerListener.java similarity index 52% rename from src/demand/controler/MutualControlerListener.java rename to src/main/java/lsp/controler/LSPControlerListener.java index ef032e20c79..4dc0f9ab1c6 100644 --- a/src/demand/controler/MutualControlerListener.java +++ b/src/main/java/lsp/controler/LSPControlerListener.java @@ -1,4 +1,5 @@ -package demand.controler; +package lsp.controler; + import java.util.ArrayList; import java.util.Collection; @@ -16,183 +17,174 @@ import org.matsim.core.controler.events.IterationStartsEvent; import org.matsim.core.controler.events.ReplanningEvent; import org.matsim.core.controler.events.ScoringEvent; -import org.matsim.core.controler.events.StartupEvent; import org.matsim.core.controler.listener.AfterMobsimListener; import org.matsim.core.controler.listener.BeforeMobsimListener; import org.matsim.core.controler.listener.IterationEndsListener; import org.matsim.core.controler.listener.IterationStartsListener; import org.matsim.core.controler.listener.ReplanningListener; import org.matsim.core.controler.listener.ScoringListener; -import org.matsim.core.controler.listener.StartupListener; import org.matsim.core.events.handler.EventHandler; -import demand.decoratedLSP.LSPDecorators; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjects; -import demand.mutualReplanning.MutualReplanningModule; -import demand.scoring.MutualScoringModule; +import lsp.functions.Info; import lsp.LSP; import lsp.LSPPlan; +import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; -import lsp.controler.FreightControlerListener; import lsp.events.EventCreator; -import lsp.functions.Info; import lsp.mobsim.CarrierResourceTracker; +import lsp.replanning.LSPReplanningModule; import lsp.resources.CarrierResource; import lsp.scoring.LSPScoringModule; import lsp.shipment.LSPShipment; import lsp.tracking.SimulationTracker; -public class MutualControlerListener implements FreightControlerListener, BeforeMobsimListener, AfterMobsimListener, - ScoringListener, ReplanningListener, IterationEndsListener, StartupListener, IterationStartsListener { + +public class LSPControlerListener implements FreightControlerListener, BeforeMobsimListener, AfterMobsimListener, ScoringListener, +ReplanningListener, IterationEndsListener, IterationStartsListener{ + + private CarrierResourceTracker carrierResourceTracker; - private Carriers carriers; - private LSPDecorators lsps; - private DemandObjects demandObjects; - private MutualScoringModule mutualScoringModule; - private MutualReplanningModule replanningModule; + private Carriers carriers; + private LSPs lsps; + private LSPReplanningModule replanningModule; + private LSPScoringModule scoringModule; private Collection creators; - private ArrayList registeredHandlers; - - @Inject EventsManager eventsManager; - @Inject Network network; + + private ArrayList registeredHandlers; + + + @Inject EventsManager eventsManager; + @Inject Network network; + @Inject - protected MutualControlerListener(LSPDecorators lsps, DemandObjects demandObjects, - MutualScoringModule demandScoringModule, MutualReplanningModule replanningModule, Collection creators) { - this.lsps = lsps; - this.demandObjects = demandObjects; - this.mutualScoringModule = demandScoringModule; - this.replanningModule = replanningModule; - this.creators = creators; - this.carriers = getCarriers(); + protected LSPControlerListener(LSPs lsps, LSPReplanningModule replanningModule, LSPScoringModule scoringModule, Collection creators) { + this.lsps = lsps; + this.replanningModule = replanningModule; + this.scoringModule = scoringModule; + this.creators = creators; + this.carriers = getCarriers(); } - @Override public void notifyBeforeMobsim(BeforeMobsimEvent event) { - - SupplyRescheduler rescheduler = new SupplyRescheduler(lsps); + + LSPRescheduler rescheduler = new LSPRescheduler(lsps); rescheduler.notifyBeforeMobsim(event); carrierResourceTracker = new CarrierResourceTracker(carriers, network, this, creators); eventsManager.addHandler(carrierResourceTracker); registeredHandlers = new ArrayList(); - - for (LSP lsp : lsps.getLSPs().values()) { - for (LSPShipment shipment : lsp.getShipments()) { - for (EventHandler handler : shipment.getEventHandlers()) { + + for(LSP lsp : lsps.getLSPs().values()) { + for(LSPShipment shipment : lsp.getShipments()) { + for(EventHandler handler : shipment.getEventHandlers()) { eventsManager.addHandler(handler); } } LSPPlan selectedPlan = lsp.getSelectedPlan(); - for (LogisticsSolution solution : selectedPlan.getSolutions()) { - for (EventHandler handler : solution.getEventHandlers()) { - eventsManager.addHandler(handler); - } - for (LogisticsSolutionElement element : solution.getSolutionElements()) { - for (EventHandler handler : element.getEventHandlers()) { + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + for(EventHandler handler : solution.getEventHandlers()) { eventsManager.addHandler(handler); } - ArrayList resourceHandlers = (ArrayList) element.getResource().getEventHandlers(); - for (EventHandler handler : resourceHandlers) { - if (!registeredHandlers.contains(handler)) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(EventHandler handler : element.getEventHandlers()) { eventsManager.addHandler(handler); - registeredHandlers.add(handler); + } + ArrayList resourceHandlers = (ArrayList)element.getResource().getEventHandlers(); + for(EventHandler handler : resourceHandlers) { + if(!registeredHandlers.contains(handler)) { + eventsManager.addHandler(handler); + registeredHandlers.add(handler); + } + } } - } - } + } } - } } - @Override - public void notifyIterationEnds(IterationEndsEvent event) { - SupplyClearer supplyClearer = new SupplyClearer(lsps); - supplyClearer.notifyIterationEnds(event); - } - + + //Hier muss noch die Möglichkeit reinkommen, dass nicht alle LSPs nach jeder Iteration neu planen, sondern nur ein Teil von denen + //Das kann durch ein entsprechendes replanningModule erreicht werden. Hier muss man dann nix ändern @Override public void notifyReplanning(ReplanningEvent event) { - replanningModule.replan(event); + replanningModule.replanLSPs(event); } @Override public void notifyScoring(ScoringEvent event) { - mutualScoringModule.scoreLSPs(event); - mutualScoringModule.scoreDemandObjects(event); + scoringModule.scoreLSPs(event); } @Override public void notifyAfterMobsim(AfterMobsimEvent event) { eventsManager.removeHandler(carrierResourceTracker); - + ArrayList alreadyUpdatedTrackers = new ArrayList(); - for (LSP lsp : lsps.getLSPs().values()) { - for (LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for (LogisticsSolutionElement element : solution.getSolutionElements()) { - for (SimulationTracker tracker : element.getResource().getSimulationTrackers()) { - if (!alreadyUpdatedTrackers.contains(tracker)) { + for(LSP lsp : lsps.getLSPs().values()) { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(SimulationTracker tracker : element.getResource().getSimulationTrackers()) { + if(!alreadyUpdatedTrackers.contains(tracker)) { tracker.notifyAfterMobsim(event); alreadyUpdatedTrackers.add(tracker); } } - for (SimulationTracker tracker : element.getSimulationTrackers()) { + for(SimulationTracker tracker : element.getSimulationTrackers()) { tracker.notifyAfterMobsim(event); } } - for (SimulationTracker tracker : solution.getSimulationTrackers()) { + for(SimulationTracker tracker : solution.getSimulationTrackers()) { tracker.notifyAfterMobsim(event); } } } - - for (LSP lsp : lsps.getLSPs().values()) { - for (LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for (LogisticsSolutionElement element : solution.getSolutionElements()) { - for (Info info : element.getInfos()) { + + for(LSP lsp : lsps.getLSPs().values()) { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + for(Info info : element.getInfos()) { info.update(); } } - for (Info info : solution.getInfos()) { + for(Info info : solution.getInfos()) { info.update(); - } + } } } - } - public void processEvent(Event event) { - eventsManager.processEvent(event); - } - private Carriers getCarriers() { Carriers carriers = new Carriers(); - for (LSP lsp : lsps.getLSPs().values()) { + for(LSP lsp : lsps.getLSPs().values()) { LSPPlan selectedPlan = lsp.getSelectedPlan(); - for (LogisticsSolution solution : selectedPlan.getSolutions()) { - for (LogisticsSolutionElement element : solution.getSolutionElements()) { - if (element.getResource() instanceof CarrierResource) { - + for(LogisticsSolution solution : selectedPlan.getSolutions()) { + for(LogisticsSolutionElement element : solution.getSolutionElements()) { + if(element.getResource() instanceof CarrierResource) { + CarrierResource carrierResource = (CarrierResource) element.getResource(); Carrier carrier = carrierResource.getCarrier(); - if (!carriers.getCarriers().containsKey(carrier.getId())) { + if(!carriers.getCarriers().containsKey(carrier.getId())) { carriers.addCarrier(carrier); } - } + } } } } return carriers; } + public void processEvent(Event event){ + eventsManager.processEvent(event); + } + @Override - public void notifyStartup(StartupEvent event) { - InitialDemandAssigner initialAssigner = new InitialDemandAssigner(demandObjects, lsps); - initialAssigner.notifyStartup(event); + public void notifyIterationEnds(IterationEndsEvent event) { + + } public CarrierResourceTracker getCarrierResourceTracker() { @@ -235,7 +227,5 @@ public void notifyIterationStarts(IterationStartsEvent event) { } } } - - } - + } } diff --git a/src/main/java/lsp/controler/LSPModule.java b/src/main/java/lsp/controler/LSPModule.java new file mode 100644 index 00000000000..e818501d502 --- /dev/null +++ b/src/main/java/lsp/controler/LSPModule.java @@ -0,0 +1,67 @@ +package lsp.controler; + +import java.util.Collection; + +import org.matsim.contrib.freight.CarrierConfig; +import org.matsim.core.controler.AbstractModule; + +import com.google.inject.Provides; +import com.google.inject.multibindings.Multibinder; + +import lsp.LSPs; +import lsp.events.EventCreator; +import lsp.mobsim.CarrierResourceTracker; +import lsp.mobsim.FreightQSimFactory; +import lsp.replanning.LSPReplanningModule; +import lsp.scoring.LSPScoringModule; + + +public class LSPModule extends AbstractModule { + + + private LSPs lsps; + private LSPReplanningModule replanningModule; + private LSPScoringModule scoringModule; + private Collection creators; + + private CarrierConfig carrierConfig = new CarrierConfig(); + + public LSPModule(LSPs lsps, LSPReplanningModule replanningModule, LSPScoringModule scoringModule, Collection creators) { + this.lsps = lsps; + this.replanningModule = replanningModule; + this.scoringModule = scoringModule; + this.creators = creators; + } + + + @Override + public void install() { + bind(CarrierConfig.class).toInstance(carrierConfig); + bind(LSPs.class).toInstance(lsps); + if(replanningModule != null) { + bind(LSPReplanningModule.class).toInstance(replanningModule); + } + if(scoringModule != null) { + bind(LSPScoringModule.class).toInstance(scoringModule); + } + + bind(LSPControlerListener.class).asEagerSingleton(); + addControlerListenerBinding().to(LSPControlerListener.class); + bindMobsim().toProvider(FreightQSimFactory.class); + } + + @Provides + Collection provideEventCreators(){ + return this.creators; + } + + @Provides + CarrierResourceTracker provideCarrierResourceTracker(LSPControlerListener lSPControlerListener) { + return lSPControlerListener.getCarrierResourceTracker(); + } + + public void setPhysicallyEnforceTimeWindowBeginnings(boolean physicallyEnforceTimeWindowBeginnings) { + this.carrierConfig.setPhysicallyEnforceTimeWindowBeginnings(physicallyEnforceTimeWindowBeginnings); + } + +} diff --git a/src/demand/controler/SupplyClearer.java b/src/main/java/lsp/controler/LSPRescheduler.java similarity index 51% rename from src/demand/controler/SupplyClearer.java rename to src/main/java/lsp/controler/LSPRescheduler.java index 88086ff4a4a..bbc6aed7909 100644 --- a/src/demand/controler/SupplyClearer.java +++ b/src/main/java/lsp/controler/LSPRescheduler.java @@ -1,41 +1,46 @@ -package demand.controler; +package lsp.controler; -import org.matsim.core.controler.events.IterationEndsEvent; -import org.matsim.core.controler.listener.IterationEndsListener; +import org.matsim.core.controler.events.BeforeMobsimEvent; +import org.matsim.core.controler.events.IterationStartsEvent; +import org.matsim.core.controler.listener.BeforeMobsimListener; +import org.matsim.core.controler.listener.IterationStartsListener; +import org.matsim.core.events.handler.EventHandler; -import demand.decoratedLSP.LSPDecorators; import lsp.LSP; +import lsp.LSPs; import lsp.LogisticsSolution; import lsp.LogisticsSolutionElement; import lsp.shipment.LSPShipment; -public class SupplyClearer implements IterationEndsListener{ + + +public class LSPRescheduler implements BeforeMobsimListener{ + - private LSPDecorators lsps; + private LSPs lsps; - public SupplyClearer(LSPDecorators lsps) { + public LSPRescheduler(LSPs lsps) { this.lsps = lsps; } - - @Override - public void notifyIterationEnds(IterationEndsEvent arg0) { + + public void notifyBeforeMobsim(BeforeMobsimEvent arg0) { + if(arg0.getIteration() != 0) { for(LSP lsp : lsps.getLSPs().values()){ - lsp.getShipments().clear(); for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { solution.getShipments().clear(); for(LogisticsSolutionElement element : solution.getSolutionElements()) { element.getIncomingShipments().clear(); element.getOutgoingShipments().clear(); } - } - + } + for(LSPShipment shipment : lsp.getShipments()) { shipment.getSchedule().clear(); shipment.getLog().clear(); lsp.getSelectedPlan().getAssigner().assignShipment(shipment); } - + lsp.scheduleSoultions(); } + } } - } diff --git a/src/main/java/lsp/controler/MobSimVehicleRoute.java b/src/main/java/lsp/controler/MobSimVehicleRoute.java new file mode 100644 index 00000000000..1db447dd64d --- /dev/null +++ b/src/main/java/lsp/controler/MobSimVehicleRoute.java @@ -0,0 +1,35 @@ +package lsp.controler; + +import org.matsim.api.core.v01.population.Plan; +import org.matsim.vehicles.Vehicle; + + +class MobSimVehicleRoute { + + private Plan plan; + + private Vehicle vehicle; + + public MobSimVehicleRoute(Plan plan, Vehicle vehicle) { + super(); + this.plan = plan; + this.vehicle = vehicle; + } + + /** + * @return the plan + */ + public Plan getPlan() { + return plan; + } + + /** + * @return the vehicle + */ + public Vehicle getVehicle() { + return vehicle; + } + + + +} diff --git a/src/main/java/lsp/replanning/LSPPlanStrategyManagerFactory.java b/src/main/java/lsp/replanning/LSPPlanStrategyManagerFactory.java new file mode 100644 index 00000000000..5a47bf01e0d --- /dev/null +++ b/src/main/java/lsp/replanning/LSPPlanStrategyManagerFactory.java @@ -0,0 +1,13 @@ +package lsp.replanning; + +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.LSP; +import lsp.LSPPlan; +import lsp.LSPPlanImpl; + +public interface LSPPlanStrategyManagerFactory { + + public GenericStrategyManager createStrategyManager(LSP lsp); + +} diff --git a/src/main/java/lsp/replanning/LSPReplanner.java b/src/main/java/lsp/replanning/LSPReplanner.java new file mode 100644 index 00000000000..9a1f91fb325 --- /dev/null +++ b/src/main/java/lsp/replanning/LSPReplanner.java @@ -0,0 +1,15 @@ +package lsp.replanning; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.LSP; +import lsp.LSPPlan; + +public interface LSPReplanner { + + public void replan(ReplanningEvent event); + public GenericStrategyManager getStrategyManager(); + public void setStrategyManager(GenericStrategyManager manager); + public void setLSP(LSP lsp); +} diff --git a/src/main/java/lsp/replanning/LSPReplannerImpl.java b/src/main/java/lsp/replanning/LSPReplannerImpl.java new file mode 100644 index 00000000000..cfb83f6ed98 --- /dev/null +++ b/src/main/java/lsp/replanning/LSPReplannerImpl.java @@ -0,0 +1,49 @@ +package lsp.replanning; + +import java.util.ArrayList; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.replanning.GenericStrategyManager; + +import lsp.LSP; +import lsp.LSPPlan; + + +public class LSPReplannerImpl implements LSPReplanner{ + + private LSP lsp; + private GenericStrategyManager strategyManager; + + public LSPReplannerImpl(LSP lsp) { + this.lsp = lsp; + } + + public LSPReplannerImpl() { + + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + @Override + public void replan(ReplanningEvent event) { + if(strategyManager != null) { + ArrayList lspList = new ArrayList (); + lspList.add(lsp); + strategyManager.run(lspList, null, event.getIteration(), event.getReplanningContext()); + } + } + + @Override + public GenericStrategyManager getStrategyManager() { + return strategyManager; + } + + @Override + public void setStrategyManager(GenericStrategyManager manager) { + this.strategyManager = manager; + } + +} diff --git a/src/main/java/lsp/replanning/LSPReplanningModule.java b/src/main/java/lsp/replanning/LSPReplanningModule.java new file mode 100644 index 00000000000..2e59520b523 --- /dev/null +++ b/src/main/java/lsp/replanning/LSPReplanningModule.java @@ -0,0 +1,10 @@ +package lsp.replanning; + +import org.matsim.core.controler.events.ReplanningEvent; +import org.matsim.core.controler.listener.ReplanningListener; + +public interface LSPReplanningModule extends ReplanningListener{ + + public void replanLSPs(ReplanningEvent arg0); + +} diff --git a/src/main/java/lsp/replanning/LSPReplanningModuleImpl.java b/src/main/java/lsp/replanning/LSPReplanningModuleImpl.java new file mode 100644 index 00000000000..8ef17e3de66 --- /dev/null +++ b/src/main/java/lsp/replanning/LSPReplanningModuleImpl.java @@ -0,0 +1,30 @@ +package lsp.replanning; + +import org.matsim.core.controler.events.ReplanningEvent; + +import lsp.LSP; +import lsp.LSPs; + +public class LSPReplanningModuleImpl implements LSPReplanningModule{ + + private LSPs lsps; + + public LSPReplanningModuleImpl(LSPs lsps) { + this.lsps = lsps; + } + + @Override + public void notifyReplanning(ReplanningEvent arg0) { + replanLSPs(arg0); + + } + + @Override + public void replanLSPs(ReplanningEvent arg0) { + for(LSP lsp : lsps.getLSPs().values()) { + if(lsp.getReplanner() != null) { + lsp.getReplanner().replan(arg0); + } + } + } +} diff --git a/src/main/java/lsp/scoring/LSPScorer.java b/src/main/java/lsp/scoring/LSPScorer.java new file mode 100644 index 00000000000..6a1af63d712 --- /dev/null +++ b/src/main/java/lsp/scoring/LSPScorer.java @@ -0,0 +1,9 @@ +package lsp.scoring; + +import lsp.LSP; + +public interface LSPScorer extends Scorer{ + + public double scoreCurrentPlan(LSP lsp); + public void setLSP (LSP lsp); +} diff --git a/src/demand/scoring/MutualScoringModule.java b/src/main/java/lsp/scoring/LSPScoringModule.java similarity index 52% rename from src/demand/scoring/MutualScoringModule.java rename to src/main/java/lsp/scoring/LSPScoringModule.java index c06c3a2b5c7..929f6c2e199 100644 --- a/src/demand/scoring/MutualScoringModule.java +++ b/src/main/java/lsp/scoring/LSPScoringModule.java @@ -1,10 +1,10 @@ -package demand.scoring; +package lsp.scoring; import org.matsim.core.controler.events.ScoringEvent; import org.matsim.core.controler.listener.ScoringListener; -public interface MutualScoringModule extends ScoringListener{ - - public void scoreDemandObjects(ScoringEvent event); +public interface LSPScoringModule extends ScoringListener{ + public void scoreLSPs(ScoringEvent event); + } diff --git a/src/main/java/lsp/scoring/LSPScoringModuleImpl.java b/src/main/java/lsp/scoring/LSPScoringModuleImpl.java new file mode 100644 index 00000000000..bc3c984a7bd --- /dev/null +++ b/src/main/java/lsp/scoring/LSPScoringModuleImpl.java @@ -0,0 +1,30 @@ +package lsp.scoring; + +import org.matsim.core.controler.events.ScoringEvent; + +import demand.decoratedLSP.LSPDecorators; +import lsp.LSP; +import lsp.LSPs; + +public class LSPScoringModuleImpl implements LSPScoringModule{ + + private LSPs lsps; + + public LSPScoringModuleImpl(LSPs lsps) { + this.lsps = lsps; + } + + @Override + public void notifyScoring(ScoringEvent event) { + scoreLSPs(event); + } + + @Override + public void scoreLSPs(ScoringEvent arg0) { + for(LSP lsp : lsps.getLSPs().values()) { + if(lsp.getScorer() != null) { + lsp.scoreSelectedPlan(); + } + } + } +} diff --git a/src/main/java/lsp/scoring/Scorer.java b/src/main/java/lsp/scoring/Scorer.java new file mode 100644 index 00000000000..d687b241396 --- /dev/null +++ b/src/main/java/lsp/scoring/Scorer.java @@ -0,0 +1,8 @@ +package lsp.scoring; + + + +public interface Scorer { + + +} diff --git a/src/main/java/lsp/shipment/AbstractShipmentPlan.java b/src/main/java/lsp/shipment/AbstractShipmentPlan.java new file mode 100644 index 00000000000..9591734afb1 --- /dev/null +++ b/src/main/java/lsp/shipment/AbstractShipmentPlan.java @@ -0,0 +1,19 @@ +package lsp.shipment; + +import java.util.HashMap; + +import org.matsim.api.core.v01.Id; + +public interface AbstractShipmentPlan { + + public LSPShipment getShipment(); + + public HashMap , AbstractShipmentPlanElement> getPlanElements(); + + public void addPlanElement(Id id, AbstractShipmentPlanElement element); + + public AbstractShipmentPlanElement getMostRecentEntry(); + + public void clear(); + +} \ No newline at end of file diff --git a/src/main/java/lsp/shipment/AbstractShipmentPlanElement.java b/src/main/java/lsp/shipment/AbstractShipmentPlanElement.java new file mode 100644 index 00000000000..e484494bf94 --- /dev/null +++ b/src/main/java/lsp/shipment/AbstractShipmentPlanElement.java @@ -0,0 +1,20 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + +public interface AbstractShipmentPlanElement { + + public LogisticsSolutionElement getSolutionElement(); + + public Id getResourceId(); + + public String getElementType(); + + public double getStartTime(); + + public double getEndTime(); + +} diff --git a/src/main/java/lsp/shipment/AbstractShipmentPlanElementComparator.java b/src/main/java/lsp/shipment/AbstractShipmentPlanElementComparator.java new file mode 100644 index 00000000000..14bef46c879 --- /dev/null +++ b/src/main/java/lsp/shipment/AbstractShipmentPlanElementComparator.java @@ -0,0 +1,25 @@ +package lsp.shipment; + +import java.util.Comparator; + +public class AbstractShipmentPlanElementComparator implements Comparator{ + + public int compare(AbstractShipmentPlanElement o1, AbstractShipmentPlanElement o2) { + if(o1.getStartTime() > o2.getStartTime()){ + return 1; + } + if(o1.getStartTime() < o2.getStartTime()){ + return -1; + } + if(o1.getStartTime() == o2.getStartTime()) { + if(o1.getEndTime() > o2.getEndTime()) { + return 1; + } + if(o1.getEndTime() < o2.getEndTime()) { + return -1; + } + } + return 0; + } + +} diff --git a/src/main/java/lsp/shipment/LSPShipment.java b/src/main/java/lsp/shipment/LSPShipment.java new file mode 100644 index 00000000000..6667d3a9885 --- /dev/null +++ b/src/main/java/lsp/shipment/LSPShipment.java @@ -0,0 +1,43 @@ +package lsp.shipment; + +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import demand.utilityFunctions.UtilityFunction; +import lsp.functions.Info; + +public interface LSPShipment { + + public Id getId(); + + public Id getFromLinkId(); + + public Id getToLinkId(); + + public TimeWindow getStartTimeWindow(); + + public TimeWindow getEndTimeWindow(); + + public AbstractShipmentPlan getSchedule(); + + public AbstractShipmentPlan getLog(); + + public int getCapacityDemand(); + + public double getServiceTime(); + + public Collection getEventHandlers(); + + public Collection getRequirements(); + + public Collection getUtilityFunctions(); + + public Collection getInfos(); + + +} diff --git a/src/main/java/lsp/shipment/LSPShipmentImpl.java b/src/main/java/lsp/shipment/LSPShipmentImpl.java new file mode 100644 index 00000000000..916d6da02d9 --- /dev/null +++ b/src/main/java/lsp/shipment/LSPShipmentImpl.java @@ -0,0 +1,200 @@ +package lsp.shipment; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.core.events.handler.EventHandler; + +import demand.utilityFunctions.UtilityFunction; +import lsp.functions.Info; + +public class LSPShipmentImpl implements LSPShipment { + + private Id id; + private Id fromLinkId; + private Id toLinkId; + private TimeWindow startTimeWindow; + private TimeWindow endTimeWindow; + private int capacityDemand; + private double serviceTime; + private AbstractShipmentPlan schedule; + private AbstractShipmentPlan log; + private ArrayList eventHandlers; + private ArrayList requirements; + private ArrayList utilityFunctions; + private ArrayList infos; + + public static class Builder { + + private Id id; + private Id fromLinkId; + private Id toLinkId; + private TimeWindow startTimeWindow; + private TimeWindow endTimeWindow; + private int capacityDemand; + private double serviceTime; + private ArrayList requirements; + private ArrayList utilityFunctions; + private ArrayList infos; + + public static Builder newInstance(Id id){ + return new Builder(id); + } + + private Builder(Id id){ + this.requirements = new ArrayList(); + this.utilityFunctions = new ArrayList(); + this.infos = new ArrayList(); + this.id = id; + } + + public Builder setFromLinkId(Id fromLinkId){ + this.fromLinkId = fromLinkId; + return this; + } + + public Builder setToLinkId(Id toLinkId){ + this.toLinkId = toLinkId; + return this; + } + + public Builder setStartTimeWindow(TimeWindow startTimeWindow){ + this.startTimeWindow = startTimeWindow; + return this; + } + + public Builder setEndTimeWindow(TimeWindow endTimeWindow){ + this.endTimeWindow = endTimeWindow; + return this; + } + + public Builder setCapacityDemand(int capacityDemand){ + this.capacityDemand = capacityDemand; + return this; + } + + public Builder setServiceTime(double serviceTime){ + this.serviceTime = serviceTime; + return this; + } + + public Builder addRequirement(Requirement requirement) { + requirements.add(requirement); + return this; + } + + public Builder addUtilityFunction(UtilityFunction utilityFunction) { + utilityFunctions.add(utilityFunction); + return this; + } + + public Builder addInfo(Info info) { + infos.add(info); + return this; + } + + public LSPShipmentImpl build(){ + return new LSPShipmentImpl(this); + } + + + } + + private LSPShipmentImpl(LSPShipmentImpl.Builder builder){ + this.id = builder.id; + this.fromLinkId = builder.fromLinkId; + this.toLinkId = builder.toLinkId; + this.startTimeWindow = builder.startTimeWindow; + this.endTimeWindow = builder.endTimeWindow; + this.capacityDemand = builder.capacityDemand; + this.serviceTime = builder.serviceTime; + this.schedule = new Schedule(this); + this.log = new Log(this); + this.eventHandlers = new ArrayList(); + this.requirements = new ArrayList(); + for(Requirement requirement : builder.requirements) { + this.requirements.add(requirement); + } + this.utilityFunctions = new ArrayList(); + for(UtilityFunction utilityFunction : builder.utilityFunctions) { + this.utilityFunctions.add(utilityFunction); + } + this.infos = new ArrayList(); + for(Info info : builder.infos) { + this.infos.add(info); + } + } + + + @Override + public Id getId() { + return id; + } + + @Override + public Id getFromLinkId() { + return fromLinkId; + } + + @Override + public Id getToLinkId() { + return toLinkId; + } + + @Override + public TimeWindow getStartTimeWindow() { + return startTimeWindow; + } + + @Override + public TimeWindow getEndTimeWindow() { + return endTimeWindow; + } + + @Override + public AbstractShipmentPlan getSchedule() { + return schedule; + } + + @Override + public AbstractShipmentPlan getLog() { + return log; + } + + @Override + public int getCapacityDemand() { + return capacityDemand; + } + + @Override + public double getServiceTime() { + return serviceTime; + } + + @Override + public Collection getEventHandlers() { + return eventHandlers; + } + + + @Override + public Collection getRequirements() { + return requirements; + } + + + @Override + public Collection getUtilityFunctions() { + return utilityFunctions; + } + + + @Override + public Collection getInfos() { + return infos; + } + +} diff --git a/src/main/java/lsp/shipment/LSPShipments.java b/src/main/java/lsp/shipment/LSPShipments.java new file mode 100644 index 00000000000..e955a47e74f --- /dev/null +++ b/src/main/java/lsp/shipment/LSPShipments.java @@ -0,0 +1,39 @@ +package lsp.shipment; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import org.matsim.api.core.v01.Id; + + +public class LSPShipments { + + private Map, LSPShipment> lspShipments; + + public LSPShipments(Collection lspShipments) { + makeMap(lspShipments); + } + + private void makeMap(Collection lspShipments) { + for (LSPShipment l : lspShipments) { + this.lspShipments.put(l.getId(), l); + } + } + + public LSPShipments() { + this.lspShipments = new HashMap<>(); + } + + public Map, LSPShipment> getShipments() { + return lspShipments; + } + + public void addShipment(LSPShipment lspShipment) { + if(!lspShipments.containsKey(lspShipment.getId())){ + lspShipments.put(lspShipment.getId(), lspShipment); + } + else { + + } + } +} diff --git a/src/main/java/lsp/shipment/Log.java b/src/main/java/lsp/shipment/Log.java new file mode 100644 index 00000000000..5b7fd2725ea --- /dev/null +++ b/src/main/java/lsp/shipment/Log.java @@ -0,0 +1,70 @@ +package lsp.shipment; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import org.matsim.api.core.v01.Id; + +public class Log implements AbstractShipmentPlan { + + class LogElementComparator implements Comparator{ + + @Override + public int compare(AbstractShipmentPlanElement o1, AbstractShipmentPlanElement o2) { + if(o1.getStartTime() > o2.getStartTime()){ + return 1; + } + if(o1.getStartTime() < o2.getStartTime()){ + return -1; + } + if(o1.getStartTime() == o2.getStartTime()) { + if(o1.getEndTime() > o2.getEndTime()) { + return 1; + } + if(o1.getEndTime() < o2.getEndTime()) { + return -1; + } + } + return 0; + } + } + + + + private LSPShipment shipment; + private HashMap , AbstractShipmentPlanElement> logElements; + + + public Log(LSPShipment shipment){ + this.shipment = shipment; + this.logElements = new HashMap , AbstractShipmentPlanElement>(); + } + + @Override + public LSPShipment getShipment() { + return shipment; + } + + public void addPlanElement(Id id, AbstractShipmentPlanElement element) { + logElements.put(id, element); + } + + @Override + public HashMap , AbstractShipmentPlanElement> getPlanElements() { + return logElements; + } + + @Override + public AbstractShipmentPlanElement getMostRecentEntry() { + ArrayList logList = new ArrayList(logElements.values()); + Collections.sort(logList, new LogElementComparator()); + Collections.reverse(logList); + return logList.get(0); + } + + @Override + public void clear() { + logElements.clear(); + } +} diff --git a/src/main/java/lsp/shipment/LoggedShipmentHandle.java b/src/main/java/lsp/shipment/LoggedShipmentHandle.java new file mode 100644 index 00000000000..8f146024e8f --- /dev/null +++ b/src/main/java/lsp/shipment/LoggedShipmentHandle.java @@ -0,0 +1,101 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + + + +public class LoggedShipmentHandle implements AbstractShipmentPlanElement { + + private final String type = "HANDLE"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id linkId; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id linkId; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setLinkId(Id linkId){ + this.linkId = linkId; + return this; + } + + public LoggedShipmentHandle build(){ + return new LoggedShipmentHandle(this); + } + } + + private LoggedShipmentHandle(LoggedShipmentHandle.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.linkId = builder.linkId; + } + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + public Id getLinkId() { + return linkId; + } + +} diff --git a/src/main/java/lsp/shipment/LoggedShipmentLoad.java b/src/main/java/lsp/shipment/LoggedShipmentLoad.java new file mode 100644 index 00000000000..fb810effe78 --- /dev/null +++ b/src/main/java/lsp/shipment/LoggedShipmentLoad.java @@ -0,0 +1,108 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; +import lsp.shipment.ScheduledShipmentLoad.Builder; + +public class LoggedShipmentLoad implements AbstractShipmentPlanElement { + + private final String type = "LOAD"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setLinkId(Id linkId){ + this.linkId = linkId; + return this; + } + + public Builder setCarrierId(Id carrierId){ + this.carrierId = carrierId; + return this; + } + + public LoggedShipmentLoad build(){ + return new LoggedShipmentLoad(this); + } + } + + private LoggedShipmentLoad(LoggedShipmentLoad.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.carrierId = builder.carrierId; + this.linkId = builder.linkId; + } + + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + + @Override + public Id getResourceId() { + return resourceId; + } + +} diff --git a/src/main/java/lsp/shipment/LoggedShipmentTransport.java b/src/main/java/lsp/shipment/LoggedShipmentTransport.java new file mode 100644 index 00000000000..ae98450db61 --- /dev/null +++ b/src/main/java/lsp/shipment/LoggedShipmentTransport.java @@ -0,0 +1,127 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; +import lsp.shipment.LoggedShipmentLoad.Builder; + +public class LoggedShipmentTransport implements AbstractShipmentPlanElement { + + private final String type = "TRANSPORT"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id fromLinkId; + private Id toLinkId; + private Id carrierId; + + public static class Builder{ + private double startTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id fromLinkId; + private Id toLinkId; + private Id carrierId; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setFromLinkId(Id fromLinkId){ + this.fromLinkId = fromLinkId; + return this; + } + + public Builder setToLinkId(Id toLinkId){ + this.toLinkId = toLinkId; + return this; + } + + public Builder setCarrierId(Id carrierId){ + this.carrierId = carrierId; + return this; + } + + public LoggedShipmentTransport build(){ + return new LoggedShipmentTransport(this); + } + } + + private LoggedShipmentTransport(LoggedShipmentTransport.Builder builder){ + this.startTime = builder.startTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.fromLinkId = builder.fromLinkId; + this.carrierId = builder.carrierId; + this.toLinkId = builder.toLinkId; + } + + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + public void setEndTime(double endTime){ + this.endTime = endTime; + } + + + public Id getFromLinkId() { + return fromLinkId; + } + + + public Id getToLinkId() { + return toLinkId; + } + + + public void setToLinkId(Id toLinkId) { + this.toLinkId = toLinkId; + } + + +} diff --git a/src/main/java/lsp/shipment/LoggedShipmentUnload.java b/src/main/java/lsp/shipment/LoggedShipmentUnload.java new file mode 100644 index 00000000000..b0b882aeb4b --- /dev/null +++ b/src/main/java/lsp/shipment/LoggedShipmentUnload.java @@ -0,0 +1,105 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + +public class LoggedShipmentUnload implements AbstractShipmentPlanElement { + + private final String type = "UNLOAD"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setLinkId(Id linkId){ + this.linkId = linkId; + return this; + } + + public Builder setCarrierId(Id carrierId){ + this.carrierId = carrierId; + return this; + } + + public LoggedShipmentUnload build(){ + return new LoggedShipmentUnload(this); + } + } + + private LoggedShipmentUnload(LoggedShipmentUnload.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.carrierId = builder.carrierId; + this.linkId = builder.linkId; + } + + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + +} diff --git a/src/main/java/lsp/shipment/Requirement.java b/src/main/java/lsp/shipment/Requirement.java new file mode 100644 index 00000000000..1e3e320d2b9 --- /dev/null +++ b/src/main/java/lsp/shipment/Requirement.java @@ -0,0 +1,9 @@ +package lsp.shipment; + +import lsp.LogisticsSolution; + +public interface Requirement { + + public boolean checkRequirement(LogisticsSolution solution); + +} diff --git a/src/main/java/lsp/shipment/Schedule.java b/src/main/java/lsp/shipment/Schedule.java new file mode 100644 index 00000000000..37df5a59791 --- /dev/null +++ b/src/main/java/lsp/shipment/Schedule.java @@ -0,0 +1,77 @@ +package lsp.shipment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; + +import org.matsim.api.core.v01.Id; + + + +public class Schedule implements AbstractShipmentPlan{ + + class ScheduleElementComparator implements Comparator{ + + @Override + public int compare(AbstractShipmentPlanElement o1, AbstractShipmentPlanElement o2) { + if(o1.getStartTime() > o2.getStartTime()){ + return 1; + } + if(o1.getStartTime() < o2.getStartTime()){ + return -1; + } + if(o1.getStartTime() == o2.getStartTime()) { + if(o1.getEndTime() > o2.getEndTime()) { + return 1; + } + if(o1.getEndTime() < o2.getEndTime()) { + return -1; + } + } + return 0; + } + } + + private LSPShipment shipment; + private HashMap , AbstractShipmentPlanElement> scheduleElements; + + + public Schedule(LSPShipment shipment){ + this.shipment = shipment; + this.scheduleElements = new HashMap , AbstractShipmentPlanElement>(); + } + + + public LSPShipment getShipment() { + return shipment; + } + + public HashMap , AbstractShipmentPlanElement> getPlanElements() { + return scheduleElements; + } + + public void addPlanElement(Id id, AbstractShipmentPlanElement element) { + scheduleElements.put(id, element); + } + + + @Override + public AbstractShipmentPlanElement getMostRecentEntry() { + ArrayList scheduleList = new ArrayList(scheduleElements.values()); + Collections.sort(scheduleList, new ScheduleElementComparator()); + Collections.reverse(scheduleList); + return scheduleList.get(0); + } + + @Override + public void clear() { + scheduleElements.clear(); + } + +} + + + + \ No newline at end of file diff --git a/src/main/java/lsp/shipment/ScheduledShipmentHandle.java b/src/main/java/lsp/shipment/ScheduledShipmentHandle.java new file mode 100644 index 00000000000..25d60fe2929 --- /dev/null +++ b/src/main/java/lsp/shipment/ScheduledShipmentHandle.java @@ -0,0 +1,98 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + +public class ScheduledShipmentHandle implements AbstractShipmentPlanElement{ + + private final String type = "HANDLE"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id linkId; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id linkId; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setLinkId(Id linkId){ + this.linkId = linkId; + return this; + } + + public ScheduledShipmentHandle build(){ + return new ScheduledShipmentHandle(this); + } + } + + private ScheduledShipmentHandle(ScheduledShipmentHandle.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + } + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + public Id getLinkId() { + return linkId; + } + +} diff --git a/src/main/java/lsp/shipment/ScheduledShipmentLoad.java b/src/main/java/lsp/shipment/ScheduledShipmentLoad.java new file mode 100644 index 00000000000..7ffe0ff497c --- /dev/null +++ b/src/main/java/lsp/shipment/ScheduledShipmentLoad.java @@ -0,0 +1,129 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + + + +public class ScheduledShipmentLoad implements AbstractShipmentPlanElement{ + + private final String type = "LOAD"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + private CarrierService carrierService; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + private CarrierService carrierService; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setLinkId(Id linkId){ + this.linkId = linkId; + return this; + } + + public Builder setCarrierId(Id carrierId){ + this.carrierId = carrierId; + return this; + } + + public Builder setCarrierService(CarrierService carrierService){ + this.carrierService = carrierService; + return this; + } + + public ScheduledShipmentLoad build(){ + return new ScheduledShipmentLoad(this); + } + } + + private ScheduledShipmentLoad(ScheduledShipmentLoad.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.linkId = builder.linkId; + this.carrierId = builder.carrierId; + this.carrierService = builder.carrierService; + } + + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + public Id getLinkId() { + return linkId; + } + + public Id getCarrierId() { + return carrierId; + } + + public CarrierService getCarrierService() { + return carrierService; + } + + +} \ No newline at end of file diff --git a/src/main/java/lsp/shipment/ScheduledShipmentTransport.java b/src/main/java/lsp/shipment/ScheduledShipmentTransport.java new file mode 100644 index 00000000000..a55e3683f17 --- /dev/null +++ b/src/main/java/lsp/shipment/ScheduledShipmentTransport.java @@ -0,0 +1,141 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + +public class ScheduledShipmentTransport implements AbstractShipmentPlanElement{ + + private final String type = "TRANSPORT"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id fromLinkId; + private Id toLinkId; + private CarrierService carrierService; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id fromLinkId; + private Id toLinkId; + private CarrierService carrierService; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setCarrierId(Id carrierId){ + this.carrierId = carrierId; + return this; + } + + public Builder setFromLinkId(Id fromLinkId){ + this.fromLinkId = fromLinkId; + return this; + } + + public Builder setToLinkId(Id toLinkId){ + this.toLinkId = toLinkId; + return this; + } + + public Builder setCarrierService(CarrierService carrierService){ + this.carrierService = carrierService; + return this; + } + + public ScheduledShipmentTransport build(){ + return new ScheduledShipmentTransport(this); + } + } + + private ScheduledShipmentTransport(ScheduledShipmentTransport.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.carrierId = builder.carrierId; + this.fromLinkId = builder.fromLinkId; + this.toLinkId = builder.toLinkId; + this.carrierService = builder.carrierService; + } + + + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + + public Id getToLinkId() { + return toLinkId; + } + + public Id getCarrierId() { + return carrierId; + } + + + public Id getFromLinkId() { + return fromLinkId; + } + + public CarrierService getCarrierService() { + return carrierService; + } + +} diff --git a/src/main/java/lsp/shipment/ScheduledShipmentUnload.java b/src/main/java/lsp/shipment/ScheduledShipmentUnload.java new file mode 100644 index 00000000000..180d512a909 --- /dev/null +++ b/src/main/java/lsp/shipment/ScheduledShipmentUnload.java @@ -0,0 +1,128 @@ +package lsp.shipment; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; + +public class ScheduledShipmentUnload implements AbstractShipmentPlanElement{ + + private final String type = "UNLOAD"; + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + private CarrierService carrierService; + + public static class Builder{ + private double startTime; + private double endTime; + private LogisticsSolutionElement element; + private Id resourceId; + private Id carrierId; + private Id linkId; + private CarrierService carrierService; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + public Builder setStartTime(double startTime){ + this.startTime = startTime; + return this; + } + + public Builder setEndTime(double endTime){ + this.endTime = endTime; + return this; + } + + public Builder setLogisticsSolutionElement(LogisticsSolutionElement element){ + this.element = element; + return this; + } + + public Builder setResourceId(Id resourceId){ + this.resourceId = resourceId; + return this; + } + + public Builder setCarrierId(Id carrierId){ + this.carrierId = carrierId; + return this; + } + + public Builder setLinkId(Id linkId){ + this.linkId = linkId; + return this; + } + + public Builder setCarrierService(CarrierService carrierService){ + this.carrierService = carrierService; + return this; + } + + public ScheduledShipmentUnload build(){ + return new ScheduledShipmentUnload(this); + } + } + + private ScheduledShipmentUnload(ScheduledShipmentUnload.Builder builder){ + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.element = builder.element; + this.resourceId = builder.resourceId; + this.carrierId = builder.carrierId; + this.linkId = builder.linkId; + this.carrierService = builder.carrierService; + } + + + @Override + public String getElementType() { + return type; + } + + @Override + public double getStartTime() { + return startTime; + } + + @Override + public double getEndTime() { + return endTime; + } + + + @Override + public LogisticsSolutionElement getSolutionElement() { + return element; + } + + @Override + public Id getResourceId() { + return resourceId; + } + + public Id getCarrierId() { + return carrierId; + } + + public Id getLinkId() { + return linkId; + } + + public CarrierService getCarrierService() { + return carrierService; + } + +} + diff --git a/src/main/java/lsp/shipment/ShipmentComparator.java b/src/main/java/lsp/shipment/ShipmentComparator.java new file mode 100644 index 00000000000..1ca11e09a01 --- /dev/null +++ b/src/main/java/lsp/shipment/ShipmentComparator.java @@ -0,0 +1,21 @@ +package lsp.shipment; + +import java.util.Comparator; + +import lsp.ShipmentTuple; + +public class ShipmentComparator implements Comparator{ + + @Override + public int compare(ShipmentTuple o1, ShipmentTuple o2) { + if(o1.getTime() > o2.getTime()){ + return 1; + } + if(o1.getTime() < o2.getTime()){ + return -1; + } + else{ + return 0; + } + } +} diff --git a/src/main/java/lsp/usecase/CollectionCarrierAdapter.java b/src/main/java/lsp/usecase/CollectionCarrierAdapter.java new file mode 100644 index 00000000000..80c29d9dd3f --- /dev/null +++ b/src/main/java/lsp/usecase/CollectionCarrierAdapter.java @@ -0,0 +1,172 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.tracking.SimulationTracker; + +public class CollectionCarrierAdapter implements CarrierResource { + + private Idid; + private Carrier carrier; + private Id locationLinkId; + private ArrayList clientElements; + private CollectionCarrierScheduler collectionScheduler; + private Network network; + private Collection eventHandlers; + private Collection infos; + private Collection trackers; + private EventsManager eventsManager; + +public static class Builder { + + private Idid; + private Carrier carrier; + private Id locationLinkId; + private ArrayList clientElements; + private CollectionCarrierScheduler collectionScheduler; + private Network network; + + public static Builder newInstance(Id id, Network network){ + return new Builder(id,network); + } + + private Builder(Id id, Network network){ + this.id = id; + this.clientElements = new ArrayList (); + this.network = network; + } + + public Builder setLocationLinkId(Id locationLinkId){ + this.locationLinkId = locationLinkId; + return this; + } + + public Builder setCarrier(Carrier carrier){ + this.carrier = carrier; + return this; + } + + + public Builder setCollectionScheduler(CollectionCarrierScheduler collectionHandler){ + this.collectionScheduler = collectionHandler; + return this; + } + + public CollectionCarrierAdapter build(){ + return new CollectionCarrierAdapter(this); + } + + } + + private CollectionCarrierAdapter(CollectionCarrierAdapter.Builder builder){ + this.id = builder.id; + this.locationLinkId = builder.locationLinkId; + this.collectionScheduler = builder.collectionScheduler; + this.clientElements = builder.clientElements; + this.carrier = builder.carrier; + this.network = builder.network; + this.eventHandlers = new ArrayList(); + this.infos = new ArrayList(); + this.trackers = new ArrayList(); + } + + + @Override + public Class getClassOfResource() { + return carrier.getClass(); + } + + @Override + public Id getStartLinkId() { + Id depotLinkId = null; + for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()){ + if(depotLinkId == null || depotLinkId == vehicle.getLocation()){ + depotLinkId = vehicle.getLocation(); + } + + } + + return depotLinkId; + + } + + @Override + public Id getEndLinkId() { + Id depotLinkId = null; + for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()){ + if(depotLinkId == null || depotLinkId == vehicle.getLocation()){ + depotLinkId = vehicle.getLocation(); + } + + } + + return depotLinkId; + + } + + + @Override + public Collection getClientElements() { + return clientElements; + } + + @Override + public Id getId() { + return id; + } + + @Override + public void schedule(int bufferTime) { + collectionScheduler.scheduleShipments(this, bufferTime); + } + + public Carrier getCarrier(){ + return carrier; + } + + public Network getNetwork(){ + return network; + } + + public Collection getEventHandlers(){ + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + + @Override + public void addSimulationTracker(SimulationTracker tracker) { + this.trackers.add(tracker); + this.eventHandlers.addAll(tracker.getEventHandlers()); + this.infos.addAll(tracker.getInfos()); + } + + + @Override + public Collection getSimulationTrackers() { + return trackers; + } + + @Override + public void setEventsManager(EventsManager eventsManager) { + this.eventsManager = eventsManager; + } + +} diff --git a/src/main/java/lsp/usecase/CollectionCarrierScheduler.java b/src/main/java/lsp/usecase/CollectionCarrierScheduler.java new file mode 100644 index 00000000000..b26aafb069e --- /dev/null +++ b/src/main/java/lsp/usecase/CollectionCarrierScheduler.java @@ -0,0 +1,269 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierPlan; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.ScheduledTour; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.Leg; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.jsprit.MatsimJspritFactory; +import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; +import org.matsim.contrib.freight.jsprit.NetworkRouter; + +import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; +import com.graphhopper.jsprit.core.algorithm.box.Jsprit; +import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; +import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; +import com.graphhopper.jsprit.core.util.Solutions; + +import lsp.LogisticsSolutionElement; +import lsp.ShipmentTuple; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.resources.ResourceScheduler; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.ScheduledShipmentLoad; +import lsp.shipment.ScheduledShipmentTransport; +import lsp.shipment.ScheduledShipmentUnload; + + + +public class CollectionCarrierScheduler extends ResourceScheduler { + + class LSPCarrierPair{ + private ShipmentTuple tuple; + private CarrierService service; + + public LSPCarrierPair(ShipmentTuple tuple, CarrierService service){ + this.tuple = tuple; + this.service = service; + } + } + + private Carrier carrier; + private CollectionCarrierAdapter adapter; + private ArrayListpairs; + + + public CollectionCarrierScheduler(){ + this.pairs = new ArrayList(); + } + + + /*@Override + public void scheduleShipments(Resource resource) { + this.shipments = new ArrayList(); + if(resource.getClass() == CollectionCarrierAdapter.class){ + this.adapter = (CollectionCarrierAdapter) resource; + this.carrier = adapter.getCarrier(); + presortIncomingShipments(); + + for(ShipmentTuple tupleToBeAssigned: shipments){ + CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); + carrier.getServices().add(carrierService); + } + + routeCarrier(); + for(ShipmentTuple tupleToBeUpdated : shipments){ + updateShipment(tupleToBeUpdated); + switchHandeledShipment(tupleToBeUpdated); + } + + shipments.clear(); + } + + }*/ + + + public void initializeValues(Resource resource){ + this.pairs = new ArrayList(); + if(resource.getClass() == CollectionCarrierAdapter.class){ + this.adapter = (CollectionCarrierAdapter) resource; + this.carrier = adapter.getCarrier(); + this.carrier.getServices().clear(); + this.carrier.getShipments().clear(); + this.carrier.getPlans().clear(); + this.carrier.setSelectedPlan(null); + } + } + + + public void scheduleResource() { + for(ShipmentTuple tupleToBeAssigned: shipments){ + CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); + carrier.getServices().add(carrierService); + } + + routeCarrier(); + } + + private CarrierService convertToCarrierService(ShipmentTuple tuple){ + Id serviceId = Id.create(tuple.getShipment().getId().toString(), CarrierService.class); + CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, tuple.getShipment().getFromLinkId()); + builder.setServiceStartTimeWindow(tuple.getShipment().getStartTimeWindow()); + builder.setCapacityDemand(tuple.getShipment().getCapacityDemand()); + builder.setServiceDuration(tuple.getShipment().getServiceTime()); + CarrierService service = builder.build(); + pairs.add(new LSPCarrierPair(tuple, service)); + return service; + } + + private void routeCarrier(){ + VehicleRoutingProblem.Builder vrpBuilder = MatsimJspritFactory.createRoutingProblemBuilder(carrier, adapter.getNetwork()); + NetworkBasedTransportCosts.Builder tpcostsBuilder = NetworkBasedTransportCosts.Builder.newInstance(adapter.getNetwork(), carrier.getCarrierCapabilities().getVehicleTypes()); + NetworkBasedTransportCosts netbasedTransportcosts = tpcostsBuilder.build(); + vrpBuilder.setRoutingCost(netbasedTransportcosts); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp); + + Collection solutions = algorithm.searchSolutions(); + + VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); + + CarrierPlan plan = MatsimJspritFactory.createPlan(carrier, solution); + NetworkRouter.routePlan(plan, netbasedTransportcosts); + carrier.setSelectedPlan(plan); + } + + + public void updateShipments() { + for(ShipmentTuple tuple : shipments) { + updateShipment(tuple); + } + } + + + private void updateShipment(ShipmentTuple tuple){ + + //outerLoop: + for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()){ + Tour tour = scheduledTour.getTour(); + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; + LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); + for(LSPCarrierPair pair : pairs){ + if(pair.tuple == carrierPair.tuple && pair.service.getId() == carrierPair.service.getId()){ + addShipmentLoadElement(tuple, tour, serviceActivity); + addShipmentTransportElement(tuple, tour, serviceActivity); + addShipmentUnloadElement(tuple, tour, serviceActivity); + addCollectionTourEndEventHandler(pair.service, tuple, adapter); + addCollectionServiceEventHandler(pair.service, tuple, adapter); + // break outerLoop; + } + } + } + } + } + } + + private void addShipmentLoadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentLoad.Builder builder = ScheduledShipmentLoad.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); + Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex-1); + double startTimeOfLoading = legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime(); + builder.setStartTime(startTimeOfLoading); + builder.setEndTime(startTimeOfLoading + tuple.getShipment().getServiceTime()); + builder.setCarrierId(carrier.getId()); + builder.setLinkId(serviceActivity.getLocation()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentLoad load = builder.build(); + String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, load); + } + + private void addCollectionServiceEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + CollectionServiceEventHandler endHandler = new CollectionServiceEventHandler(carrierService, tuple.getShipment(), element, resource); + tuple.getShipment().getEventHandlers().add(endHandler); + break; + } + } + + } + + private void addCollectionTourEndEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + CollectionTourEndEventHandler handler = new CollectionTourEndEventHandler(carrierService, tuple.getShipment(), element, resource); + tuple.getShipment().getEventHandlers().add(handler); + break; + } + } + + } + + private void addShipmentTransportElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentTransport.Builder builder = ScheduledShipmentTransport.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); + Leg legAfterService = (Leg) tour.getTourElements().get(serviceIndex+1); + double startTimeOfTransport = legAfterService.getExpectedDepartureTime(); + builder.setStartTime(startTimeOfTransport); + Leg lastLeg = (Leg) tour.getTourElements().get(tour.getTourElements().size()-1); + double endTimeOfTransport = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); + builder.setEndTime(endTimeOfTransport); + builder.setCarrierId(carrier.getId()); + builder.setFromLinkId(serviceActivity.getLocation()); + builder.setToLinkId(tour.getEndLinkId()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentTransport transport = builder.build(); + String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, transport); + } + + private void addShipmentUnloadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentUnload.Builder builder = ScheduledShipmentUnload.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + Leg lastLeg = (Leg) tour.getTourElements().get(tour.getTourElements().size()-1); + double startTime = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); + builder.setStartTime(startTime); + builder.setEndTime(startTime + getUnloadEndTime(tour)); + builder.setCarrierId(carrier.getId()); + builder.setLinkId(tour.getEndLinkId()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentUnload unload = builder.build(); + String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, unload); + } + + + private double getUnloadEndTime(Tour tour){ + double unloadEndTime = 0; + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; + unloadEndTime = unloadEndTime + serviceActivity.getDuration(); + } + } + + + return unloadEndTime; + } +} diff --git a/src/main/java/lsp/usecase/CollectionServiceEventHandler.java b/src/main/java/lsp/usecase/CollectionServiceEventHandler.java new file mode 100644 index 00000000000..52e50e9bcd9 --- /dev/null +++ b/src/main/java/lsp/usecase/CollectionServiceEventHandler.java @@ -0,0 +1,93 @@ +package lsp.usecase; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentLoad; +import lsp.shipment.LoggedShipmentTransport; + +public class CollectionServiceEventHandler implements ServiceEndEventHandler { + + private CarrierService carrierService; + private LSPShipment lspShipment; + private LogisticsSolutionElement solutionElement; + private CarrierResource resource; + + public CollectionServiceEventHandler(CarrierService carrierService, LSPShipment lspShipment, LogisticsSolutionElement element, CarrierResource resource){ + this.carrierService = carrierService; + this.lspShipment = lspShipment; + this.solutionElement = element; + this.resource = resource; + } + + + @Override + public void reset(int iteration) { + // TODO Auto-generated method stub + + } + + @Override + public void handleEvent(ServiceEndEvent event) { + if(event.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()){ + logTransport(event); + logLoad(event); + } + } + + private void logLoad(ServiceEndEvent event){ + LoggedShipmentLoad.Builder builder = LoggedShipmentLoad.Builder.newInstance(); + builder.setStartTime(event.getTime() - event.getService().getServiceDuration()); + builder.setEndTime(event.getTime()); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + builder.setLinkId(event.getService().getLocationLinkId()); + builder.setCarrierId(event.getCarrierId()); + LoggedShipmentLoad load = builder.build(); + String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); + Id loadId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(loadId, load); + } + + private void logTransport(ServiceEndEvent event){ + LoggedShipmentTransport.Builder builder = LoggedShipmentTransport.Builder.newInstance(); + builder.setStartTime(event.getTime()); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + builder.setFromLinkId(event.getService().getLocationLinkId()); + builder.setCarrierId(event.getCarrierId()); + LoggedShipmentTransport transport = builder.build(); + String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); + Id transportId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(transportId, transport); + } + + + public CarrierService getCarrierService() { + return carrierService; + } + + + public LSPShipment getLspShipment() { + return lspShipment; + } + + + public LogisticsSolutionElement getElement() { + return solutionElement; + } + + + public Id getResourceId() { + return resource.getId(); + } + + +} diff --git a/src/main/java/lsp/usecase/CollectionTourEndEventHandler.java b/src/main/java/lsp/usecase/CollectionTourEndEventHandler.java new file mode 100644 index 00000000000..6647b575ce3 --- /dev/null +++ b/src/main/java/lsp/usecase/CollectionTourEndEventHandler.java @@ -0,0 +1,116 @@ +package lsp.usecase; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; + +import lsp.events.TourEndEvent; +import lsp.events.TourEndEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentTransport; +import lsp.shipment.LoggedShipmentUnload; + +public class CollectionTourEndEventHandler implements TourEndEventHandler { + + private CarrierService carrierService; + private LSPShipment lspShipment; + private LogisticsSolutionElement solutionElement; + private CarrierResource resource; + + public CollectionTourEndEventHandler(CarrierService carrierService, LSPShipment lspShipment, LogisticsSolutionElement element, CarrierResource resource){ + this.carrierService = carrierService; + this.lspShipment = lspShipment; + this.solutionElement = element; + this.resource = resource; + } + + + @Override + public void reset(int iteration) { + // TODO Auto-generated method stub + + } + + @Override + public void handleEvent(TourEndEvent event) { + Tour tour = event.getTour(); + for(TourElement element : tour.getTourElements()){ + if(element instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) element; + if(serviceActivity.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()){ + logTransport(event, tour); + logUnload(event, tour); + } + } + } + } + + private void logUnload(TourEndEvent event, Tour tour){ + LoggedShipmentUnload.Builder builder = LoggedShipmentUnload.Builder.newInstance(); + builder.setStartTime(event.getTime()); + builder.setEndTime(event.getTime() + getTotalUnloadingTime(tour)); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + builder.setCarrierId(event.getCarrierId()); + LoggedShipmentUnload unload = builder.build(); + String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); + Id unloadId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(unloadId, unload); + } + + private void logTransport(TourEndEvent event, Tour tour){ + String idString = resource.getId() + "" + solutionElement.getId() + "" + "TRANSPORT"; + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + AbstractShipmentPlanElement abstractPlanElement = lspShipment.getLog().getPlanElements().get(id); + if(abstractPlanElement instanceof LoggedShipmentTransport) { + LoggedShipmentTransport transport = (LoggedShipmentTransport) abstractPlanElement; + transport.setEndTime(event.getTime()); + transport.setToLinkId(tour.getEndLinkId()); + } + } + + private double getTotalUnloadingTime(Tour tour){ + double totalTime = 0; + for(TourElement element : tour.getTourElements()){ + if(element instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) element; + totalTime = totalTime + serviceActivity.getDuration(); + } + } + return totalTime; + } + + + public CarrierService getCarrierService() { + return carrierService; + } + + + public LSPShipment getLspShipment() { + return lspShipment; + } + + + public LogisticsSolutionElement getElement() { + return solutionElement; + } + + + public Id getResourceId() { + return resource.getId(); + } + + +} + + + + + + diff --git a/src/main/java/lsp/usecase/DeterministicShipmentAssigner.java b/src/main/java/lsp/usecase/DeterministicShipmentAssigner.java new file mode 100644 index 00000000000..f3ed66c6640 --- /dev/null +++ b/src/main/java/lsp/usecase/DeterministicShipmentAssigner.java @@ -0,0 +1,27 @@ +package lsp.usecase; + +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.ShipmentAssigner; +import lsp.shipment.LSPShipment; + +public class DeterministicShipmentAssigner implements ShipmentAssigner { + + private LSP lsp; + + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + @Override + public void assignShipment(LSPShipment shipment) { + LogisticsSolution singleSolution = lsp.getSelectedPlan().getSolutions().iterator().next(); + singleSolution.assignShipment(shipment); + } + + @Override + public LSP getLSP() { + return lsp; + } + +} diff --git a/src/main/java/lsp/usecase/DistributionCarrierAdapter.java b/src/main/java/lsp/usecase/DistributionCarrierAdapter.java new file mode 100644 index 00000000000..c3f71a4079a --- /dev/null +++ b/src/main/java/lsp/usecase/DistributionCarrierAdapter.java @@ -0,0 +1,169 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.tracking.SimulationTracker; + +public class DistributionCarrierAdapter implements CarrierResource { + + private Idid; + private Carrier carrier; + private Id locationLinkId; + private ArrayList clientElements; + private DistributionCarrierScheduler distributionHandler; + private Network network; + private Collection eventHandlers; + private Collection infos; + private Collection trackers; + private EventsManager eventsManager; + + public static class Builder { + + private Idid; + private Carrier carrier; + private Id locationLinkId; + private ArrayList clientElements; + private DistributionCarrierScheduler distributionHandler; + private Network network; + + public static Builder newInstance(Id id, Network network){ + return new Builder(id,network); + } + + private Builder(Id id, Network network){ + this.id = id; + this.clientElements = new ArrayList (); + this.network = network; + } + + public Builder setLocationLinkId(Id locationLinkId){ + this.locationLinkId = locationLinkId; + return this; + } + + public Builder setCarrier(Carrier carrier){ + this.carrier = carrier; + return this; + } + + + public Builder setDistributionScheduler(DistributionCarrierScheduler distributionHandler){ + this.distributionHandler = distributionHandler; + return this; + } + + public DistributionCarrierAdapter build(){ + return new DistributionCarrierAdapter(this); + } + + } + + private DistributionCarrierAdapter(DistributionCarrierAdapter.Builder builder){ + this.id = builder.id; + this.locationLinkId = builder.locationLinkId; + this.distributionHandler = builder.distributionHandler; + this.clientElements = builder.clientElements; + this.carrier = builder.carrier; + this.network = builder.network; + this.eventHandlers = new ArrayList(); + this.infos = new ArrayList(); + this.trackers = new ArrayList(); + } + + @Override + public Class getClassOfResource() { + return carrier.getClass(); + } + + @Override + public Id getStartLinkId() { + Id depotLinkId = null; + for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()){ + if(depotLinkId == null || depotLinkId == vehicle.getLocation()){ + depotLinkId = vehicle.getLocation(); + } + + } + + return depotLinkId; + + } + + @Override + public Id getEndLinkId() { + Id depotLinkId = null; + for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()){ + if(depotLinkId == null || depotLinkId == vehicle.getLocation()){ + depotLinkId = vehicle.getLocation(); + } + + } + + return depotLinkId; + + } + + @Override + public Id getId() { + return id; + } + + @Override + public Collection getClientElements() { + return clientElements; + } + + @Override + public void schedule(int bufferTime) { + distributionHandler.scheduleShipments(this, bufferTime); + + } + + public Network getNetwork(){ + return network; + } + + public Carrier getCarrier(){ + return carrier; + } + + public Collection getEventHandlers(){ + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void addSimulationTracker(SimulationTracker tracker) { + this.trackers.add(tracker); + this.eventHandlers.addAll(tracker.getEventHandlers()); + this.infos.addAll(tracker.getInfos()); + } + + @Override + public Collection getSimulationTrackers() { + return trackers; + } + + @Override + public void setEventsManager(EventsManager eventsManager) { + this.eventsManager = eventsManager; + } + +} diff --git a/src/main/java/lsp/usecase/DistributionCarrierScheduler.java b/src/main/java/lsp/usecase/DistributionCarrierScheduler.java new file mode 100644 index 00000000000..495ef906ea4 --- /dev/null +++ b/src/main/java/lsp/usecase/DistributionCarrierScheduler.java @@ -0,0 +1,320 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.ListIterator; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierImpl; +import org.matsim.contrib.freight.carrier.CarrierPlan; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.ScheduledTour; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.contrib.freight.carrier.Tour.Leg; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.jsprit.MatsimJspritFactory; +import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; +import org.matsim.contrib.freight.jsprit.NetworkRouter; + +import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; +import com.graphhopper.jsprit.core.algorithm.box.Jsprit; +import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; +import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; +import com.graphhopper.jsprit.core.util.Solutions; + +import lsp.LogisticsSolutionElement; +import lsp.ShipmentTuple; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.resources.ResourceScheduler; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.ScheduledShipmentLoad; +import lsp.shipment.ScheduledShipmentTransport; +import lsp.shipment.ScheduledShipmentUnload; + +public class DistributionCarrierScheduler extends ResourceScheduler { + + class LSPCarrierPair{ + private ShipmentTuple tuple; + private CarrierService service; + + public LSPCarrierPair(ShipmentTuple tuple, CarrierService service){ + this.tuple = tuple; + this.service = service; + } + + } + + + private Carrier carrier; + private DistributionCarrierAdapter adapter; + private ArrayListpairs; + + + public DistributionCarrierScheduler(){ + this.pairs = new ArrayList(); + } + + + protected void initializeValues(Resource resource) { + this.pairs = new ArrayList(); + if(resource.getClass() == DistributionCarrierAdapter.class){ + this.adapter = (DistributionCarrierAdapter) resource; + this.carrier = adapter.getCarrier(); + this.carrier.getServices().clear(); + this.carrier.getShipments().clear(); + this.carrier.getPlans().clear(); + this.carrier.setSelectedPlan(null); + } + } + + protected void scheduleResource() { + int load = 0; + double cumulatedLoadingTime = 0; + double availiabilityTimeOfLastShipment = 0; + ArrayList copyOfAssignedShipments = new ArrayList(shipments); + ArrayList shipmentsInCurrentTour = new ArrayList(); + ArrayList scheduledTours = new ArrayList(); + + for(ShipmentTuple tuple : copyOfAssignedShipments){ + CarrierVehicleType vehicleType = carrier.getCarrierCapabilities().getVehicleTypes().iterator().next(); + if((load + tuple.getShipment().getCapacityDemand()) <= vehicleType.getCarrierVehicleCapacity()){ + shipmentsInCurrentTour.add(tuple); + load = load + tuple.getShipment().getCapacityDemand(); + cumulatedLoadingTime = cumulatedLoadingTime + tuple.getShipment().getServiceTime(); + availiabilityTimeOfLastShipment = tuple.getTime(); + } + else{ + load=0; + Carrier auxiliaryCarrier = createAuxiliaryCarrier(shipmentsInCurrentTour, availiabilityTimeOfLastShipment + cumulatedLoadingTime); + routeCarrier(auxiliaryCarrier); + scheduledTours.addAll(auxiliaryCarrier.getSelectedPlan().getScheduledTours()); + cumulatedLoadingTime = 0; + shipmentsInCurrentTour.clear(); + shipmentsInCurrentTour.add(tuple); + load = load + tuple.getShipment().getCapacityDemand(); + cumulatedLoadingTime = cumulatedLoadingTime + tuple.getShipment().getServiceTime(); + availiabilityTimeOfLastShipment = tuple.getTime(); + } + } + + if(!shipmentsInCurrentTour.isEmpty()) { + Carrier auxiliaryCarrier = createAuxiliaryCarrier(shipmentsInCurrentTour, availiabilityTimeOfLastShipment + cumulatedLoadingTime); + routeCarrier(auxiliaryCarrier); + scheduledTours.addAll(auxiliaryCarrier.getSelectedPlan().getScheduledTours()); + cumulatedLoadingTime = 0; + shipmentsInCurrentTour.clear(); + } + + CarrierPlan plan = new CarrierPlan(carrier,scheduledTours); + carrier.setSelectedPlan(plan); + } + + private CarrierService convertToCarrierService(ShipmentTuple tuple){ + Id serviceId = Id.create(tuple.getShipment().getId().toString(), CarrierService.class); + CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, tuple.getShipment().getToLinkId()); + builder.setCapacityDemand(tuple.getShipment().getCapacityDemand()); + builder.setServiceDuration(tuple.getShipment().getServiceTime()); + CarrierService service = builder.build(); + pairs.add(new LSPCarrierPair(tuple, service)); + return service; + } + + private void routeCarrier(Carrier carrier){ + VehicleRoutingProblem.Builder vrpBuilder = MatsimJspritFactory.createRoutingProblemBuilder(carrier, adapter.getNetwork()); + NetworkBasedTransportCosts.Builder tpcostsBuilder = NetworkBasedTransportCosts.Builder.newInstance(adapter.getNetwork(), carrier.getCarrierCapabilities().getVehicleTypes()); + NetworkBasedTransportCosts netbasedTransportcosts = tpcostsBuilder.build(); + vrpBuilder.setRoutingCost(netbasedTransportcosts); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp); + + Collection solutions = algorithm.searchSolutions(); + + VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); + + CarrierPlan plan = MatsimJspritFactory.createPlan(carrier, solution); + NetworkRouter.routePlan(plan, netbasedTransportcosts); + carrier.setSelectedPlan(plan); + } + + + protected void updateShipments() { + for(ShipmentTuple tuple: shipments) { + updateSchedule(tuple); + } + + } + + + private void updateSchedule(ShipmentTuple tuple){ + + //outerLoop: + for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()){ + Tour tour = scheduledTour.getTour(); + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; + LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); + for(LSPCarrierPair pair : pairs){ + if(pair.tuple == carrierPair.tuple && pair.service.getId() == carrierPair.service.getId()){ + addShipmentLoadElement(tuple, tour, serviceActivity); + addShipmentTransportElement(tuple, tour, serviceActivity); + addShipmentUnloadElement(tuple, tour, serviceActivity); + addDistributionStartEventHandler(pair.service, tuple, adapter); + addDistributionServiceEventHandler(pair.service, tuple, adapter); + //break outerLoop; + } + } + } + } + } + } + + private void addShipmentLoadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentLoad.Builder builder = ScheduledShipmentLoad.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); + double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); + double cumulatedLoadingTime = 0; + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity activity = (Tour.ServiceActivity) element; + cumulatedLoadingTime = cumulatedLoadingTime + activity.getDuration(); + } + } + builder.setStartTime(startTimeOfTransport - cumulatedLoadingTime); + builder.setEndTime(startTimeOfTransport); + builder.setCarrierId(carrier.getId()); + builder.setLinkId(tour.getStartLinkId()); + builder.setCarrierService(serviceActivity.getService()); + + ScheduledShipmentLoad load = builder.build(); + String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, load); + + } + + private void addShipmentTransportElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentTransport.Builder builder = ScheduledShipmentTransport.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); + double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); + builder.setStartTime(startTimeOfTransport); + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); + Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex-1); + builder.setEndTime(legBeforeService.getExpectedTransportTime() + legBeforeService.getExpectedDepartureTime()); + builder.setCarrierId(carrier.getId()); + builder.setFromLinkId(tour.getStartLinkId()); + builder.setToLinkId(serviceActivity.getLocation()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentTransport transport = builder.build(); + String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, transport); + } + + + private void addShipmentUnloadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentUnload.Builder builder = ScheduledShipmentUnload.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); + ServiceActivity service = (ServiceActivity) tour.getTourElements().get(serviceIndex); + builder.setStartTime(service.getExpectedArrival()); + builder.setEndTime(service.getDuration() + service.getExpectedArrival()); + builder.setCarrierId(carrier.getId()); + builder.setLinkId(serviceActivity.getLocation()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentUnload unload = builder.build(); + String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, unload); + } + + + private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrentTour, double startTime){ + Carrier auxiliaryCarrier = CarrierImpl.newInstance(carrier.getId()); + CarrierVehicle carrierVehicle = carrier.getCarrierCapabilities().getCarrierVehicles().iterator().next(); + CarrierVehicle.Builder vBuilder = CarrierVehicle.Builder.newInstance(carrierVehicle.getVehicleId(), carrierVehicle.getLocation()); + vBuilder.setEarliestStart(startTime); + vBuilder.setLatestEnd(24*60*60); + vBuilder.setType(carrier.getCarrierCapabilities().getVehicleTypes().iterator().next()); + auxiliaryCarrier.getCarrierCapabilities().getVehicleTypes().add(carrier.getCarrierCapabilities().getVehicleTypes().iterator().next()); + auxiliaryCarrier.getCarrierCapabilities().getCarrierVehicles().add(vBuilder.build()); + auxiliaryCarrier.getCarrierCapabilities().setFleetSize(FleetSize.FINITE); + + for(ShipmentTuple tuple : shipmentsInCurrentTour){ + auxiliaryCarrier.getServices().add(convertToCarrierService(tuple)); + } + return auxiliaryCarrier; + } + + private double getLoadStartTime(ShipmentTuple tuple, Tour tour){ + double loadStartTime = 0; + ListIterator iterator = tour.getTourElements().listIterator(tour.getTourElements().size()-1); + + outerLoop: + while(iterator.hasPrevious()){ + TourElement element = iterator.previous(); + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; + LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); + for(LSPCarrierPair pair : pairs){ + if(pair.tuple == carrierPair.tuple && pair.service.getId() == carrierPair.service.getId()){ + break outerLoop; + } + else{ + loadStartTime = loadStartTime + serviceActivity.getDuration(); + } + } + } + } + + return loadStartTime; + } + + private void addDistributionServiceEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + DistributionServiceEventHandler handler = new DistributionServiceEventHandler(carrierService, tuple.getShipment(), element, resource); + tuple.getShipment().getEventHandlers().add(handler); + break; + } + } + } + + private void addDistributionStartEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + DistributionStartEventHandler handler = new DistributionStartEventHandler(carrierService, tuple.getShipment(), element, resource); + tuple.getShipment().getEventHandlers().add(handler); + break; + } + } + + } + +} \ No newline at end of file diff --git a/src/main/java/lsp/usecase/DistributionServiceEventHandler.java b/src/main/java/lsp/usecase/DistributionServiceEventHandler.java new file mode 100644 index 00000000000..c3d3f62fe0c --- /dev/null +++ b/src/main/java/lsp/usecase/DistributionServiceEventHandler.java @@ -0,0 +1,85 @@ +package lsp.usecase; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.CarrierService; + +import lsp.events.ServiceEndEvent; +import lsp.events.ServiceEndEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentTransport; +import lsp.shipment.LoggedShipmentUnload; + +public class DistributionServiceEventHandler implements ServiceEndEventHandler { + + private CarrierService carrierService; + private LSPShipment lspShipment; + private LogisticsSolutionElement solutionElement; + private CarrierResource resource; + + public DistributionServiceEventHandler(CarrierService carrierService, LSPShipment lspShipment, LogisticsSolutionElement element, CarrierResource resource) { + this.carrierService = carrierService; + this.lspShipment = lspShipment; + this.solutionElement = element; + this.resource = resource; + } + + @Override + public void reset(int iteration) { + // TODO Auto-generated method stub + + } + + @Override + public void handleEvent(ServiceEndEvent event) { + if (event.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()) { + logTransport(event); + logUnload(event); + } + } + + private void logTransport(ServiceEndEvent event) { + String idString = resource.getId() + "" + solutionElement.getId() + "" + "TRANSPORT"; + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + AbstractShipmentPlanElement abstractPlanElement = lspShipment.getLog().getPlanElements().get(id); + if(abstractPlanElement instanceof LoggedShipmentTransport) { + LoggedShipmentTransport transport = (LoggedShipmentTransport) abstractPlanElement; + transport.setEndTime(event.getTime()); + } + } + + private void logUnload(ServiceEndEvent event) { + LoggedShipmentUnload.Builder builder = LoggedShipmentUnload.Builder.newInstance(); + builder.setCarrierId(event.getCarrierId()); + builder.setLinkId(event.getService().getLocationLinkId()); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + builder.setStartTime(event.getTime()); + builder.setEndTime(event.getTime() + event.getService().getServiceDuration()); + LoggedShipmentUnload unload = builder.build(); + String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); + Id unloadId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(unloadId, unload); + } + + public CarrierService getCarrierService() { + return carrierService; + } + + public LSPShipment getLspShipment() { + return lspShipment; + } + + public LogisticsSolutionElement getSolutionElement() { + return solutionElement; + } + + public CarrierResource getResource() { + return resource; + } + + + +} diff --git a/src/main/java/lsp/usecase/DistributionStartEventHandler.java b/src/main/java/lsp/usecase/DistributionStartEventHandler.java new file mode 100644 index 00000000000..d3e9762b091 --- /dev/null +++ b/src/main/java/lsp/usecase/DistributionStartEventHandler.java @@ -0,0 +1,113 @@ +package lsp.usecase; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; + +import lsp.events.TourStartEvent; +import lsp.events.TourStartEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentLoad; +import lsp.shipment.LoggedShipmentTransport; + +public class DistributionStartEventHandler implements TourStartEventHandler { + + private CarrierService carrierService; + private LSPShipment lspShipment; + private LogisticsSolutionElement element; + private CarrierResource resource; + + public DistributionStartEventHandler(CarrierService carrierService, LSPShipment lspShipment, LogisticsSolutionElement element, CarrierResource resource){ + this.carrierService = carrierService; + this.lspShipment = lspShipment; + this.element = element; + this.resource = resource; + } + + + @Override + public void reset(int iteration) { + // TODO Auto-generated method stub + + } + + @Override + public void handleEvent(TourStartEvent event) { + for(TourElement tourElement : event.getTour().getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + if(serviceActivity.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()){ + logLoad(event); + logTransport(event); + } + } + } + + } + + private void logLoad(TourStartEvent event){ + LoggedShipmentLoad.Builder builder = LoggedShipmentLoad.Builder.newInstance(); + builder.setCarrierId(event.getCarrierId()); + builder.setLinkId(event.getTour().getStartLinkId()); + builder.setLogisticsSolutionElement(element); + builder.setResourceId(resource.getId()); + builder.setEndTime(event.getTime()); + builder.setStartTime(event.getTime() - getCumulatedLoadingTime(event.getTour())); + LoggedShipmentLoad load = builder.build(); + String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); + Id loadId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(loadId, load); + } + + private void logTransport(TourStartEvent event){ + LoggedShipmentTransport.Builder builder = LoggedShipmentTransport.Builder.newInstance(); + builder.setCarrierId(event.getCarrierId()); + builder.setFromLinkId(event.getTour().getStartLinkId()); + builder.setToLinkId(event.getTour().getEndLinkId()); + builder.setLogisticsSolutionElement(element); + builder.setResourceId(resource.getId()); + builder.setStartTime(event.getTime()); + LoggedShipmentTransport transport = builder.build(); + String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); + Id transportId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(transportId, transport); + } + + private double getCumulatedLoadingTime(Tour tour){ + double cumulatedLoadingTime = 0; + for(TourElement tourElement : tour.getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + cumulatedLoadingTime = cumulatedLoadingTime + serviceActivity.getDuration(); + } + } + return cumulatedLoadingTime; + } + + + public CarrierService getCarrierService() { + return carrierService; + } + + + public LSPShipment getLspShipment() { + return lspShipment; + } + + + public LogisticsSolutionElement getElement() { + return element; + } + + + public CarrierResource getResource() { + return resource; + } + + +} diff --git a/src/main/java/lsp/usecase/FreightLinkEnterEventHandler.java b/src/main/java/lsp/usecase/FreightLinkEnterEventHandler.java new file mode 100644 index 00000000000..831bce68647 --- /dev/null +++ b/src/main/java/lsp/usecase/FreightLinkEnterEventHandler.java @@ -0,0 +1,11 @@ +package lsp.usecase; + +import org.matsim.core.events.handler.EventHandler; + +import lsp.events.FreightLinkEnterEvent; + +public interface FreightLinkEnterEventHandler extends EventHandler{ + + public void handleEvent(FreightLinkEnterEvent event); + +} diff --git a/src/main/java/lsp/usecase/LSPShipmentMaker.java b/src/main/java/lsp/usecase/LSPShipmentMaker.java new file mode 100644 index 00000000000..164ac62abac --- /dev/null +++ b/src/main/java/lsp/usecase/LSPShipmentMaker.java @@ -0,0 +1,61 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.core.network.NetworkUtils; +import org.matsim.core.network.io.MatsimNetworkReader; + +import lsp.LSPImpl; +import lsp.shipment.LSPShipment; +import lsp.shipment.LSPShipmentImpl; + +public class LSPShipmentMaker { + + public static void main (String[]args){ + + Network network = NetworkUtils.createNetwork(); + MatsimNetworkReader reader = new MatsimNetworkReader(network); + reader.readFile("D:\\Working_Copies_Dissertation\\Code_Dissertation\\logistics\\input\\lsp\\network\\2regions.xml"); + Random random = new Random(1); + ArrayList shipments = new ArrayList(); + + for(int i = 0; i < 8; i++){ + LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(Id.create("Shipment " + i, LSPShipment.class)); + builder.setServiceTime(180); + builder.setCapacityDemand(1); + TimeWindow startTimeWindow = TimeWindow.newInstance(0, Double.MAX_VALUE); + builder.setStartTimeWindow(startTimeWindow); + TimeWindow endTimeWindow = TimeWindow.newInstance(0, Double.MAX_VALUE); + builder.setEndTimeWindow(endTimeWindow); + IdfromLinkId= null; + IdtoLinkId = null; + while (fromLinkId == null || toLinkId == null){ + List linkList = new ArrayList(network.getLinks().values()); + Collections.shuffle(linkList); + Link link = linkList.get(0); + + if(link.getCoord().getX()<4){ + fromLinkId = link.getId(); + builder.setFromLinkId(fromLinkId); + } + if(link.getCoord().getX()>14){ + toLinkId = link.getId(); + builder.setToLinkId(toLinkId); + } + + } + shipments.add(builder.build()); + } + + for(LSPShipment shipment : shipments){ + System.out.println(shipment.getFromLinkId() + " "+ shipment.getToLinkId()); + } + } +} diff --git a/src/main/java/lsp/usecase/MainRunCarrierAdapter.java b/src/main/java/lsp/usecase/MainRunCarrierAdapter.java new file mode 100644 index 00000000000..28814cff24b --- /dev/null +++ b/src/main/java/lsp/usecase/MainRunCarrierAdapter.java @@ -0,0 +1,158 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.tracking.SimulationTracker; + +public class MainRunCarrierAdapter implements CarrierResource { + + private Idid; + private Carrier carrier; + private Id fromLinkId; + private Id toLinkId; + private ArrayList clientElements; + private MainRunCarrierScheduler mainRunScheduler; + private Network network; + private Collection eventHandlers; + private Collection trackers; + private Collection infos; + private EventsManager eventsManager; + + + public static class Builder { + + private Idid; + private Carrier carrier; + private Id fromLinkId; + private Id toLinkId; + private ArrayList clientElements; + private MainRunCarrierScheduler mainRunScheduler; + private Network network; + + public static Builder newInstance(Id id, Network network){ + return new Builder(id,network); + } + + private Builder(Id id, Network network){ + this.id = id; + this.clientElements = new ArrayList (); + this.network = network; + } + + public Builder setFromLinkId(Id fromLinkId){ + this.fromLinkId = fromLinkId; + return this; + } + + public Builder setToLinkId(Id toLinkId){ + this.toLinkId = toLinkId; + return this; + } + + public Builder setCarrier(Carrier carrier){ + this.carrier = carrier; + return this; + } + + public Builder setMainRunCarrierScheduler(MainRunCarrierScheduler mainRunScheduler){ + this.mainRunScheduler = mainRunScheduler; + return this; + } + + public MainRunCarrierAdapter build(){ + return new MainRunCarrierAdapter(this); + } + + } + + private MainRunCarrierAdapter(MainRunCarrierAdapter.Builder builder){ + this.id = builder.id; + this.carrier = builder.carrier; + this.fromLinkId = builder.fromLinkId; + this.toLinkId = builder.toLinkId; + this.clientElements = builder.clientElements; + this.mainRunScheduler = builder.mainRunScheduler; + this.network = builder.network; + this.eventHandlers = new ArrayList(); + this.infos = new ArrayList(); + this.trackers = new ArrayList(); + } + + + @Override + public Id getId() { + return id; + } + + @Override + public Id getStartLinkId() { + return fromLinkId; + } + + @Override + public Class getClassOfResource() { + return carrier.getClass(); + } + + @Override + public Id getEndLinkId() { + return toLinkId; + } + + @Override + public Collection getClientElements() { + return clientElements; + } + + @Override + public void schedule(int bufferTime) { + mainRunScheduler.scheduleShipments(this, bufferTime); + } + + public Carrier getCarrier(){ + return carrier; + } + + public Network getNetwork(){ + return network; + } + + public Collection getEventHandlers(){ + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void addSimulationTracker(SimulationTracker tracker) { + this.trackers.add(tracker); + this.eventHandlers.addAll(tracker.getEventHandlers()); + this.infos.addAll(tracker.getInfos()); + } + + @Override + public Collection getSimulationTrackers() { + return trackers; + } + + @Override + public void setEventsManager(EventsManager eventsManager) { + this.eventsManager = eventsManager; + } + +} diff --git a/src/main/java/lsp/usecase/MainRunCarrierScheduler.java b/src/main/java/lsp/usecase/MainRunCarrierScheduler.java new file mode 100644 index 00000000000..11f9aff8a08 --- /dev/null +++ b/src/main/java/lsp/usecase/MainRunCarrierScheduler.java @@ -0,0 +1,279 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.Carrier; +import org.matsim.contrib.freight.carrier.CarrierPlan; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierVehicle; +import org.matsim.contrib.freight.carrier.CarrierVehicleType; +import org.matsim.contrib.freight.carrier.ScheduledTour; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.Leg; +import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; +import org.matsim.contrib.freight.jsprit.NetworkRouter; + +import lsp.LogisticsSolutionElement; +import lsp.ShipmentTuple; +import lsp.resources.CarrierResource; +import lsp.resources.Resource; +import lsp.resources.ResourceScheduler; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.ScheduledShipmentLoad; +import lsp.shipment.ScheduledShipmentTransport; +import lsp.shipment.ScheduledShipmentUnload; +import lsp.shipment.ShipmentComparator; +import lsp.shipment.ScheduledShipmentLoad.Builder; + + +public class MainRunCarrierScheduler extends ResourceScheduler { + + class LSPCarrierPair{ + private ShipmentTuple tuple; + private CarrierService service; + + public LSPCarrierPair(ShipmentTuple tuple, CarrierService service){ + this.tuple = tuple; + this.service = service; + } + + } + + private Carrier carrier; + private MainRunCarrierAdapter adapter; + private ArrayListpairs; + + + public MainRunCarrierScheduler(){ + this.pairs = new ArrayList(); + } + + protected void initializeValues(Resource resource) { + this.pairs = new ArrayList(); + if(resource.getClass() == MainRunCarrierAdapter.class){ + this.adapter = (MainRunCarrierAdapter) resource; + this.carrier = adapter.getCarrier(); + this.carrier.getServices().clear(); + this.carrier.getShipments().clear(); + this.carrier.getPlans().clear(); + this.carrier.setSelectedPlan(null); + } + } + + protected void scheduleResource() { + int load = 0; + ArrayList copyOfAssignedShipments = new ArrayList(shipments); + Collections.sort(copyOfAssignedShipments, new ShipmentComparator()); + ArrayList shipmentsInCurrentTour = new ArrayList(); + ArrayList scheduledTours = new ArrayList(); + + for(ShipmentTuple tuple : copyOfAssignedShipments){ + CarrierVehicleType vehicleType = carrier.getCarrierCapabilities().getVehicleTypes().iterator().next(); + if((load + tuple.getShipment().getCapacityDemand()) <= vehicleType.getCarrierVehicleCapacity()){ + shipmentsInCurrentTour.add(tuple); + load = load + tuple.getShipment().getCapacityDemand(); + } + else{ + load=0; + CarrierPlan plan = createPlan(carrier, shipmentsInCurrentTour); + scheduledTours.addAll(plan.getScheduledTours()); + shipmentsInCurrentTour.clear(); + shipmentsInCurrentTour.add(tuple); + load = load + tuple.getShipment().getCapacityDemand(); + } + + } + if(!shipmentsInCurrentTour.isEmpty()) { + CarrierPlan plan = createPlan(carrier, shipmentsInCurrentTour); + scheduledTours.addAll(plan.getScheduledTours()); + shipmentsInCurrentTour.clear(); + } + CarrierPlan plan = new CarrierPlan(carrier,scheduledTours); + carrier.setSelectedPlan(plan); + } + + + + private CarrierPlan createPlan(Carrier carrier, ArrayList tuples){ + + NetworkBasedTransportCosts.Builder tpcostsBuilder = NetworkBasedTransportCosts.Builder.newInstance(adapter.getNetwork(), adapter.getCarrier().getCarrierCapabilities().getVehicleTypes()); + NetworkBasedTransportCosts netbasedTransportcosts = tpcostsBuilder.build(); + Collection tours = new ArrayList(); + + Tour.Builder tourBuilder = Tour.Builder.newInstance(); + tourBuilder.scheduleStart(Id.create(adapter.getStartLinkId(), Link.class)); + + double totalLoadingTime = 0; + double latestTupleTime = 0; + + for (ShipmentTuple tuple : tuples){ + totalLoadingTime = totalLoadingTime + tuple.getShipment().getServiceTime(); + if(tuple.getTime() > latestTupleTime){ + latestTupleTime = tuple.getTime(); + } + tourBuilder.addLeg(new Leg()); + CarrierService carrierService = convertToCarrierService(tuple); + tourBuilder.scheduleService(carrierService); + } + + + tourBuilder.addLeg(new Leg()); + tourBuilder.scheduleEnd(Id.create(adapter.getEndLinkId(), Link.class)); + org.matsim.contrib.freight.carrier.Tour vehicleTour = tourBuilder.build(); + CarrierVehicle vehicle = carrier.getCarrierCapabilities().getCarrierVehicles().iterator().next(); + double tourStartTime = latestTupleTime + totalLoadingTime; + ScheduledTour sTour = ScheduledTour.newInstance(vehicleTour, vehicle, tourStartTime); + tours.add(sTour); + CarrierPlan plan = new CarrierPlan(carrier,tours); + NetworkRouter.routePlan(plan, netbasedTransportcosts); + return plan; + } + + + private CarrierService convertToCarrierService(ShipmentTuple tuple){ + Id serviceId = Id.create(tuple.getShipment().getId().toString(), CarrierService.class); + CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, adapter.getEndLinkId()); + builder.setCapacityDemand(tuple.getShipment().getCapacityDemand()); + builder.setServiceDuration(tuple.getShipment().getServiceTime()); + CarrierService service = builder.build(); + pairs.add(new LSPCarrierPair(tuple, service)); + return service; + } + + + protected void updateShipments() { + for(ShipmentTuple tuple : shipments) { + updateSchedule(tuple); + } + } + + + private void updateSchedule(ShipmentTuple tuple){ + //outerLoop: + for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()){ + Tour tour = scheduledTour.getTour(); + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; + LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); + for(LSPCarrierPair pair : pairs){ + if(pair.tuple == carrierPair.tuple && pair.service.getId() == carrierPair.service.getId()){ + addShipmentLoadElement(tuple, tour, serviceActivity); + addShipmentTransportElement(tuple, tour, serviceActivity); + addShipmentUnloadElement(tuple, tour, serviceActivity); + addMainRunStartEventHandler(pair.service, tuple, adapter); + addMainRunEndEventHandler(pair.service, tuple, adapter); + //break outerLoop; + } + } + } + } + } + } + + private void addShipmentLoadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentLoad.Builder builder = ScheduledShipmentLoad.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); + double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); + double cumulatedLoadingTime = 0; + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity activity = (Tour.ServiceActivity) element; + cumulatedLoadingTime = cumulatedLoadingTime + activity.getDuration(); + } + } + builder.setStartTime(startTimeOfTransport - cumulatedLoadingTime); + builder.setEndTime(startTimeOfTransport); + builder.setCarrierId(carrier.getId()); + builder.setLinkId(tour.getStartLinkId()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentLoad load = builder.build(); + String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, load); + } + + private void addShipmentTransportElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentTransport.Builder builder = ScheduledShipmentTransport.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); + double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); + builder.setStartTime(startTimeOfTransport); + builder.setEndTime(legAfterStart.getExpectedTransportTime() + startTimeOfTransport); + builder.setCarrierId(carrier.getId()); + builder.setFromLinkId(tour.getStartLinkId()); + builder.setToLinkId(tour.getEndLinkId()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentTransport transport = builder.build(); + String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, transport); + } + + private void addShipmentUnloadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ + ScheduledShipmentUnload.Builder builder = ScheduledShipmentUnload.Builder.newInstance(); + builder.setResourceId(adapter.getId()); + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + double cumulatedLoadingTime = 0; + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity activity = (Tour.ServiceActivity) element; + cumulatedLoadingTime = cumulatedLoadingTime + activity.getDuration(); + } + } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); + builder.setStartTime(legAfterStart.getExpectedDepartureTime() + legAfterStart.getExpectedTransportTime()); + builder.setEndTime(legAfterStart.getExpectedDepartureTime() + legAfterStart.getExpectedTransportTime() + cumulatedLoadingTime); + builder.setCarrierId(carrier.getId()); + builder.setLinkId(tour.getEndLinkId()); + builder.setCarrierService(serviceActivity.getService()); + ScheduledShipmentUnload unload = builder.build(); + String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, unload); + } + + private void addMainRunStartEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + MainRunStartEventHandler handler = new MainRunStartEventHandler(tuple.getShipment(), carrierService, element, resource); + tuple.getShipment().getEventHandlers().add(handler); + break; + } + } + } + + private void addMainRunEndEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ + for(LogisticsSolutionElement element : adapter.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + MainRunEndEventHandler handler = new MainRunEndEventHandler(tuple.getShipment(), carrierService, element,resource); + tuple.getShipment().getEventHandlers().add(handler); + break; + } + } + + } +} diff --git a/src/main/java/lsp/usecase/MainRunEndEventHandler.java b/src/main/java/lsp/usecase/MainRunEndEventHandler.java new file mode 100644 index 00000000000..024dcb314e4 --- /dev/null +++ b/src/main/java/lsp/usecase/MainRunEndEventHandler.java @@ -0,0 +1,112 @@ +package lsp.usecase; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; + +import lsp.events.TourEndEvent; +import lsp.events.TourEndEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentTransport; +import lsp.shipment.LoggedShipmentUnload; + +public class MainRunEndEventHandler implements TourEndEventHandler{ + + private LSPShipment lspShipment; + private CarrierService carrierService; + private LogisticsSolutionElement solutionElement; + private CarrierResource resource; + + + public MainRunEndEventHandler (LSPShipment lspShipment, CarrierService carrierService, LogisticsSolutionElement solutionElement, CarrierResource resource){ + this.lspShipment=lspShipment; + this.carrierService=carrierService; + this.solutionElement=solutionElement; + this.resource=resource; + } + + + @Override + public void reset(int iteration) { + // TODO Auto-generated method stub + + } + + + + @Override + public void handleEvent(TourEndEvent event) { + for(TourElement tourElement : event.getTour().getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + if(serviceActivity.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()){ + logUnload(event); + logTransport(event); + } + } + } + } + + private void logUnload(TourEndEvent event){ + LoggedShipmentUnload.Builder builder = LoggedShipmentUnload.Builder.newInstance(); + builder.setStartTime(event.getTime() - getTotalUnloadingTime(event.getTour())); + builder.setEndTime(event.getTime()); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + builder.setCarrierId(event.getCarrierId()); + LoggedShipmentUnload unload = builder.build(); + String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); + Id unloadId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(unloadId, unload); + } + + private void logTransport(TourEndEvent event){ + String idString = resource.getId() + "" + solutionElement.getId() + "" + "TRANSPORT"; + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + AbstractShipmentPlanElement abstractPlanElement = lspShipment.getLog().getPlanElements().get(id); + if(abstractPlanElement instanceof LoggedShipmentTransport) { + LoggedShipmentTransport transport = (LoggedShipmentTransport) abstractPlanElement; + transport.setEndTime(event.getTime()- getTotalUnloadingTime(event.getTour())); + transport.setToLinkId(event.getTour().getEndLinkId()); + } + } + + private double getTotalUnloadingTime(Tour tour){ + double totalTime = 0; + for(TourElement element : tour.getTourElements()){ + if(element instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) element; + totalTime = totalTime + serviceActivity.getDuration(); + } + } + return totalTime; + } + + + public LSPShipment getLspShipment() { + return lspShipment; + } + + + public CarrierService getCarrierService() { + return carrierService; + } + + + public LogisticsSolutionElement getSolutionElement() { + return solutionElement; + } + + + public CarrierResource getResource() { + return resource; + } + + + +} diff --git a/src/main/java/lsp/usecase/MainRunStartEventHandler.java b/src/main/java/lsp/usecase/MainRunStartEventHandler.java new file mode 100644 index 00000000000..82120d3f2a6 --- /dev/null +++ b/src/main/java/lsp/usecase/MainRunStartEventHandler.java @@ -0,0 +1,116 @@ +package lsp.usecase; + +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; + +import lsp.events.TourStartEvent; +import lsp.events.TourStartEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.CarrierResource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentLoad; +import lsp.shipment.LoggedShipmentTransport; + +public class MainRunStartEventHandler implements TourStartEventHandler { + + private LSPShipment lspShipment; + private CarrierService carrierService; + private LogisticsSolutionElement solutionElement; + private CarrierResource resource; + + + public MainRunStartEventHandler (LSPShipment lspShipment, CarrierService carrierService, LogisticsSolutionElement solutionElement, CarrierResource resource){ + this.lspShipment=lspShipment; + this.carrierService=carrierService; + this.solutionElement=solutionElement; + this.resource=resource; + } + + + @Override + public void reset(int iteration) { + // TODO Auto-generated method stub + + } + + @Override + public void handleEvent(TourStartEvent event) { + for(TourElement tourElement : event.getTour().getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + if(serviceActivity.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()){ + logLoad(event); + logTransport(event); + } + } + } + + } + + private void logLoad(TourStartEvent event){ + LoggedShipmentLoad.Builder builder = LoggedShipmentLoad.Builder.newInstance(); + builder.setCarrierId(event.getCarrierId()); + builder.setLinkId(event.getTour().getStartLinkId()); + double startTime = event.getTime() - getCumulatedLoadingTime(event.getTour()); + builder.setStartTime(startTime); + builder.setEndTime(event.getTime()); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + LoggedShipmentLoad load = builder.build(); + String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); + Id loadId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(loadId, load); + } + + private double getCumulatedLoadingTime(Tour tour){ + double cumulatedLoadingTime = 0; + for(TourElement tourElement : tour.getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + cumulatedLoadingTime = cumulatedLoadingTime + serviceActivity.getDuration(); + } + } + return cumulatedLoadingTime; + } + + private void logTransport(TourStartEvent event){ + LoggedShipmentTransport.Builder builder = LoggedShipmentTransport.Builder.newInstance(); + builder.setCarrierId(event.getCarrierId()); + builder.setFromLinkId(event.getTour().getStartLinkId()); + builder.setToLinkId(event.getTour().getEndLinkId()); + builder.setStartTime(event.getTime()); + builder.setLogisticsSolutionElement(solutionElement); + builder.setResourceId(resource.getId()); + LoggedShipmentTransport transport = builder.build(); + String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); + Id transportId = Id.create(idString, AbstractShipmentPlanElement.class); + lspShipment.getLog().getPlanElements().put(transportId, transport); + } + + + public LSPShipment getLspShipment() { + return lspShipment; + } + + + public CarrierService getCarrierService() { + return carrierService; + } + + + public LogisticsSolutionElement getSolutionElement() { + return solutionElement; + } + + + public CarrierResource getResource() { + return resource; + } + + + +} diff --git a/src/main/java/lsp/usecase/NetworkMaker.java b/src/main/java/lsp/usecase/NetworkMaker.java new file mode 100644 index 00000000000..1dad0b279a8 --- /dev/null +++ b/src/main/java/lsp/usecase/NetworkMaker.java @@ -0,0 +1,147 @@ +package lsp.usecase; + + + +import org.matsim.api.core.v01.Coord; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.network.NetworkWriter; +import org.matsim.api.core.v01.network.Node; +import org.matsim.core.network.NetworkUtils; + + +import com.google.common.collect.Sets; + +public class NetworkMaker { + + public static void main (String[]args){ + Network network = NetworkUtils.createNetwork(); + + for(int i=0; i < 5; i++){ + for(int j = 0; j < 5; j++){ + Coord coord = new Coord(i,j); + Id id = Id.createNodeId("("+i+" " +j+")"); + Node node = NetworkUtils.createNode(id, coord); + network.addNode(node); + } + } + + for(int i=14; i < 19; i++){ + for(int j = 0; j < 5; j++){ + Coord coord = new Coord(i,j); + Id id = Id.createNodeId("("+i+" " +j+")"); + Node node = NetworkUtils.createNode(id, coord); + network.addNode(node); + } + } + + + for(int i = 0; i < 4; i++){ + for( int j = 0; j < 5 ; j++){ + Id id1 = Id.createNodeId("("+i+" " +j+")"); + Node node1 = network.getNodes().get(id1); + Id id2 = Id.createNodeId("("+(i+1)+" " +j+")"); + Node node2 = network.getNodes().get(id2); + Link link1 = NetworkUtils.createLink(Id.createLinkId("("+i+" " +j+")" + " " + "("+(i+1)+" " +j+")"), node1, node2, network, 10000, 7.5, 10, 1); + link1.setLength(1000); + link1.setFreespeed(7.5); + link1.setCapacity(10.0); + link1.setNumberOfLanes(1.0); + link1.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link1); + Link link2 = NetworkUtils.createLink(Id.createLinkId("("+(i+1)+" " +j+")" + " " + "("+i+" " +j+")"), node2, node1, network, 10000, 7.5, 10, 1); + link2.setLength(1000); + link2.setFreespeed(7.5); + link2.setCapacity(10.0); + link2.setNumberOfLanes(1.0); + link2.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link2); + } + + } + + for(int i = 0; i < 5; i++){ + for( int j = 0; j < 4 ; j++){ + Id id1 = Id.createNodeId("("+i+" " +j+")"); + Node node1 = network.getNodes().get(id1); + Id id2 = Id.createNodeId("("+i+" " +(j+1)+")"); + Node node2 = network.getNodes().get(id2); + Link link1 = NetworkUtils.createLink(Id.createLinkId("("+i+" " +j+")" + " " + "("+i+" " +(j+1)+")"), node1, node2, network, 10000, 7.5, 10, 1); + link1.setLength(1000); + link1.setFreespeed(7.5); + link1.setCapacity(10.0); + link1.setNumberOfLanes(1.0); + link1.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link1); + Link link2 = NetworkUtils.createLink(Id.createLinkId("("+i+" " +(j+1)+")" + " " + "("+i+" " +j+")"), node2, node1, network, 10000, 7.5, 10, 1); + link2.setLength(1000); + link2.setFreespeed(7.5); + link2.setCapacity(10.0); + link2.setNumberOfLanes(1.0); + link2.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link2); + } + + } + + for(int i = 14; i < 18; i++){ + for( int j = 0; j < 5 ; j++){ + Id id1 = Id.createNodeId("("+i+" " +j+")"); + Node node1 = network.getNodes().get(id1); + Id id2 = Id.createNodeId("("+(i+1)+" " +j+")"); + Node node2 = network.getNodes().get(id2); + Link link1 = NetworkUtils.createLink(Id.createLinkId("("+i+" " +j+")" + " " + "("+(i+1)+" " +j+")"), node1, node2, network, 10000, 7.5, 10, 1); + link1.setLength(1000); + link1.setFreespeed(7.5); + link1.setCapacity(10.0); + link1.setNumberOfLanes(1.0); + link1.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link1); + Link link2 = NetworkUtils.createLink(Id.createLinkId("("+(i+1)+" " +j+")" + " " + "("+i+" " +j+")"), node2, node1, network, 10000, 7.5, 10, 1); + link2.setLength(1000); + link2.setFreespeed(7.5); + link2.setCapacity(10.0); + link2.setNumberOfLanes(1.0); + link2.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link2); + } + + } + + for(int i = 14; i < 19; i++){ + for( int j = 0; j <4 ; j++){ + Id id1 = Id.createNodeId("("+i+" " +j+")"); + Node node1 = network.getNodes().get(id1); + Id id2 = Id.createNodeId("("+i+" " +(j+1)+")"); + Node node2 = network.getNodes().get(id2); + Link link1 = NetworkUtils.createLink(Id.createLinkId("("+i+" " +j+")" + " " + "("+i+" " +(j+1)+")"), node1, node2, network, 10000, 7.5, 10, 1); + link1.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link1); + Link link2 = NetworkUtils.createLink(Id.createLinkId("("+i+" " +(j+1)+")" + " " + "("+i+" " +j+")"), node2, node1, network, 10000, 7.5, 10, 1); + link2.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link2); + } + + } + + Id id1 = Id.createNodeId("(4 2)"); + Node node1 = network.getNodes().get(id1); + Id id2 = Id.createNodeId("(14 2)"); + Node node2 = network.getNodes().get(id2); + Link link1 = NetworkUtils.createLink(Id.createLinkId("(4 2)" + " " + "(14 2)"), node1, node1, network, 10000, 7.5, 10, 1); + link1.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link1); + Link link2 = NetworkUtils.createLink(Id.createLinkId("(14 2)" + " " + "(4 2)"), node2, node1, network, 10000, 7.5, 10, 1); + link2.setAllowedModes(Sets.newHashSet("car")); + network.addLink(link2); + + NetworkWriter writer = new NetworkWriter(network); + writer.write("D:\\Transport_Chains\\workspace_TransportChains\\logistics\\input\\lsp\\network\\2regions.xml"); + + } + + + + +} diff --git a/src/main/java/lsp/usecase/ReloadingPoint.java b/src/main/java/lsp/usecase/ReloadingPoint.java new file mode 100644 index 00000000000..1f40a540106 --- /dev/null +++ b/src/main/java/lsp/usecase/ReloadingPoint.java @@ -0,0 +1,135 @@ +package lsp.usecase; + +import java.util.ArrayList; +import java.util.Collection; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.CarrierService.Builder; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.handler.EventHandler; + +import lsp.functions.Info; +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; +import lsp.tracking.SimulationTracker; + +public class ReloadingPoint implements Resource { + + private Id id; + private Id locationLinkId; + private ReloadingPointScheduler reloadingScheduler; + private ArrayList clientElements; + private ArrayList eventHandlers; + private Collection infos; + private Collection trackers; + private ReloadingPointEventHandler eventHandler; + private EventsManager eventsManager; + + public static class Builder { + + private Id id; + private Id locationLinkId; + private ReloadingPointScheduler reloadingScheduler; + private ArrayList clientElements; + + public static Builder newInstance(Id id, Id locationLinkId){ + return new Builder(id,locationLinkId); + } + + private Builder(Id id, Id locationLinkId){ + this.id = id; + this.clientElements = new ArrayList (); + this.locationLinkId = locationLinkId; + } + + public Builder setReloadingScheduler(ReloadingPointScheduler reloadingHandler){ + this.reloadingScheduler = reloadingHandler; + return this; + } + + public ReloadingPoint build(){ + return new ReloadingPoint(this); + } + + } + + private ReloadingPoint(ReloadingPoint.Builder builder){ + this.id = builder.id; + this.locationLinkId = builder.locationLinkId; + this.reloadingScheduler = builder.reloadingScheduler; + reloadingScheduler.setReloadingPoint(this); + ReloadingPointEventHandler eventHandler = new ReloadingPointEventHandler(this); + reloadingScheduler.setEventHandler(eventHandler); + this.clientElements = builder.clientElements; + this.eventHandlers = new ArrayList(); + this.infos = new ArrayList(); + this.trackers = new ArrayList(); + eventHandlers.add(eventHandler); + } + + @Override + public Id getStartLinkId() { + return locationLinkId; + } + + @Override + public Class getClassOfResource() { + return this.getClass(); + } + + @Override + public Id getEndLinkId() { + return locationLinkId; + } + + @Override + public Collection getClientElements() { + return clientElements; + } + + @Override + public Id getId() { + return id; + } + + @Override + public void schedule(int bufferTime) { + reloadingScheduler.scheduleShipments(this, bufferTime); + } + + public double getCapacityNeedFixed(){ + return reloadingScheduler.getCapacityNeedFixed(); + } + + public double getCapacityNeedLinear(){ + return reloadingScheduler.getCapacityNeedLinear(); + } + + public Collection getEventHandlers(){ + return eventHandlers; + } + + @Override + public Collection getInfos() { + return infos; + } + + @Override + public void addSimulationTracker(SimulationTracker tracker) { + this.trackers.add(tracker); + this.eventHandlers.addAll(tracker.getEventHandlers()); + this.infos.addAll(tracker.getInfos()); + } + + @Override + public Collection getSimulationTrackers() { + return trackers; + } + + @Override + public void setEventsManager(EventsManager eventsManager) { + this.eventsManager = eventsManager; + } +} diff --git a/src/main/java/lsp/usecase/ReloadingPointEventHandler.java b/src/main/java/lsp/usecase/ReloadingPointEventHandler.java new file mode 100644 index 00000000000..60525d8bb9f --- /dev/null +++ b/src/main/java/lsp/usecase/ReloadingPointEventHandler.java @@ -0,0 +1,181 @@ +package lsp.usecase; + +import java.util.HashMap; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.freight.carrier.CarrierService; +import org.matsim.contrib.freight.carrier.Tour; +import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; +import org.matsim.contrib.freight.carrier.Tour.TourElement; + +import lsp.events.TourEndEvent; +import lsp.events.TourEndEventHandler; +import lsp.LogisticsSolutionElement; +import lsp.resources.Resource; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.LSPShipment; +import lsp.shipment.LoggedShipmentHandle; +import lsp.shipment.ScheduledShipmentTransport; + +public class ReloadingPointEventHandler implements TourEndEventHandler { + + public class ReloadingPointEventHandlerPair{ + public LSPShipment shipment; + public LogisticsSolutionElement element; + + public ReloadingPointEventHandlerPair(LSPShipment shipment, LogisticsSolutionElement element){ + this.shipment = shipment; + this.element = element; + } + } + + + private HashMap servicesWaitedFor; + private ReloadingPoint reloadingPoint; + private Id resourceId; + private Id linkId; + + public ReloadingPointEventHandler(ReloadingPoint reloadingPoint){ + this.reloadingPoint = reloadingPoint; + this.linkId = reloadingPoint.getEndLinkId(); + this.resourceId = reloadingPoint.getId(); + this.servicesWaitedFor = new HashMap(); + } + + @Override + public void reset(int iteration) { + servicesWaitedFor.clear(); + } + + public void addShipment(LSPShipment shipment, LogisticsSolutionElement solutionElement){ + ReloadingPointEventHandlerPair pair = new ReloadingPointEventHandlerPair(shipment, solutionElement); + + for(AbstractShipmentPlanElement planElement: shipment.getSchedule().getPlanElements().values()){ + if(planElement instanceof ScheduledShipmentTransport){ + ScheduledShipmentTransport transport = (ScheduledShipmentTransport) planElement; + if(transport.getSolutionElement().getNextElement() == solutionElement){ + servicesWaitedFor.put(transport.getCarrierService(), pair); + } + } + } + } + + @Override + public void handleEvent(TourEndEvent event) { + if((event.getTour().getEndLinkId() == this.linkId) && (shipmentsOfTourEndInPoint(event.getTour()))){ + + for(TourElement tourElement : event.getTour().getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + if(serviceActivity.getLocation() == reloadingPoint.getStartLinkId() + && allServicesAreInOnePoint(event.getTour()) + && (event.getTour().getStartLinkId() != reloadingPoint.getStartLinkId())) { + logReloadAfterMainRun(serviceActivity.getService(), event); + } + else { + logReloadAfterCollection(serviceActivity.getService(), event); + } + } + + } + } + + + + } + + private boolean shipmentsOfTourEndInPoint(Tour tour){ + boolean shipmentsEndInPoint = true; + for(TourElement tourElement : tour.getTourElements()){ + if(tourElement instanceof ServiceActivity){ + ServiceActivity serviceActivity = (ServiceActivity) tourElement; + if(!servicesWaitedFor.containsKey(serviceActivity.getService())){ + return false; + } + } + } + return shipmentsEndInPoint; + } + + private void logReloadAfterCollection(CarrierService carrierService, TourEndEvent event){ + LSPShipment lspShipment = servicesWaitedFor.get(carrierService).shipment; + LoggedShipmentHandle.Builder builder = LoggedShipmentHandle.Builder.newInstance(); + builder.setLinkId(linkId); + builder.setResourceId(resourceId); + double startTime = event.getTime() + getUnloadEndTime(event.getTour()); + builder.setStartTime(startTime); + double handlingTime = reloadingPoint.getCapacityNeedFixed() + reloadingPoint.getCapacityNeedLinear() * lspShipment.getCapacityDemand(); + builder.setEndTime(startTime + handlingTime); + builder.setLogisticsSolutionElement(servicesWaitedFor.get(carrierService).element); + LoggedShipmentHandle handle = builder.build(); + String idString = handle.getResourceId() + "" + handle.getSolutionElement().getId() + "" + handle.getElementType(); + Id loadId = Id.create(idString, AbstractShipmentPlanElement.class); + if(!lspShipment.getLog().getPlanElements().containsKey(loadId)) { + lspShipment.getLog().getPlanElements().put(loadId, handle); + } + } + + private double getUnloadEndTime(Tour tour){ + double unloadEndTime = 0; + for(TourElement element: tour.getTourElements()){ + if(element instanceof Tour.ServiceActivity){ + Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; + unloadEndTime = unloadEndTime + serviceActivity.getDuration(); + } + } + + + return unloadEndTime; + } + + private void logReloadAfterMainRun(CarrierService carrierService, TourEndEvent event){ + LSPShipment lspShipment = servicesWaitedFor.get(carrierService).shipment; + LoggedShipmentHandle.Builder builder = LoggedShipmentHandle.Builder.newInstance(); + builder.setLinkId(linkId); + builder.setResourceId(resourceId); + double startTime = event.getTime(); + builder.setStartTime(startTime); + double handlingTime = reloadingPoint.getCapacityNeedFixed() + reloadingPoint.getCapacityNeedLinear() * lspShipment.getCapacityDemand(); + builder.setEndTime(startTime + handlingTime); + builder.setLogisticsSolutionElement(servicesWaitedFor.get(carrierService).element); + LoggedShipmentHandle handle = builder.build(); + String idString = handle.getResourceId() + "" + handle.getSolutionElement().getId() + "" + handle.getElementType(); + Id loadId = Id.create(idString, AbstractShipmentPlanElement.class); + if(!lspShipment.getLog().getPlanElements().containsKey(loadId)) { + lspShipment.getLog().getPlanElements().put(loadId, handle); + } + } + + private boolean allServicesAreInOnePoint(Tour tour) { + for(TourElement element : tour.getTourElements()) { + if(element instanceof ServiceActivity) { + ServiceActivity activity = (ServiceActivity) element; + if(activity.getLocation() != tour.getEndLinkId()) { + return false; + } + } + } + return true; + } + + + public HashMap getServicesWaitedFor() { + return servicesWaitedFor; + } + + public ReloadingPoint getReloadingPoint() { + return reloadingPoint; + } + + public Id getResourceId() { + return resourceId; + } + + public Id getLinkId() { + return linkId; + } + + + +} diff --git a/src/main/java/lsp/usecase/ReloadingPointScheduler.java b/src/main/java/lsp/usecase/ReloadingPointScheduler.java new file mode 100644 index 00000000000..cf65765b8b3 --- /dev/null +++ b/src/main/java/lsp/usecase/ReloadingPointScheduler.java @@ -0,0 +1,127 @@ +package lsp.usecase; + +import java.util.ArrayList; + +import org.matsim.api.core.v01.Id; + +import lsp.LogisticsSolutionElement; +import lsp.ShipmentTuple; +import lsp.resources.Resource; +import lsp.resources.ResourceScheduler; +import lsp.shipment.AbstractShipmentPlanElement; +import lsp.shipment.ScheduledShipmentHandle; + +public class ReloadingPointScheduler extends ResourceScheduler { + + private ReloadingPoint reloadingPoint; + private double capacityNeedLinear; + private double capacityNeedFixed; + private ReloadingPointEventHandler eventHandler; + + public static class Builder{ + private double capacityNeedLinear; + private double capacityNeedFixed; + + private Builder(){ + } + + public static Builder newInstance(){ + return new Builder(); + } + + + public Builder setCapacityNeedLinear(double capacityNeedLinear){ + this.capacityNeedLinear = capacityNeedLinear; + return this; + } + + public Builder setCapacityNeedFixed(double capacityNeedFixed){ + this.capacityNeedFixed = capacityNeedFixed; + return this; + } + + public ReloadingPointScheduler build(){ + return new ReloadingPointScheduler(this); + } + } + + private ReloadingPointScheduler(ReloadingPointScheduler.Builder builder){ + this.shipments = new ArrayList(); + this.capacityNeedLinear = builder.capacityNeedLinear; + this.capacityNeedFixed = builder.capacityNeedFixed; + + } + + protected void initializeValues(Resource resource) { + if(resource.getClass() == ReloadingPoint.class){ + this.reloadingPoint = (ReloadingPoint) resource; + } + } + + protected void scheduleResource() { + for(ShipmentTuple tupleToBeAssigned: shipments){ + handleWaitingShipment(tupleToBeAssigned); + } + } + + protected void updateShipments() { + + } + + + + private void handleWaitingShipment(ShipmentTuple tupleToBeAssigned){ + updateSchedule(tupleToBeAssigned); + addShipmentToEventHandler(tupleToBeAssigned); + } + + private void updateSchedule(ShipmentTuple tuple){ + ScheduledShipmentHandle.Builder builder = ScheduledShipmentHandle.Builder.newInstance(); + builder.setStartTime(tuple.getTime()); + builder.setEndTime(tuple.getTime() + capacityNeedFixed + capacityNeedLinear * tuple.getShipment().getCapacityDemand()); + builder.setResourceId(reloadingPoint.getId()); + for(LogisticsSolutionElement element : reloadingPoint.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + builder.setLogisticsSolutionElement(element); + } + } + builder.setLinkId(reloadingPoint.getStartLinkId()); + ScheduledShipmentHandle handle = builder.build(); + String idString = handle.getResourceId() + "" + handle.getSolutionElement().getId() + "" + handle.getElementType(); + Id id = Id.create(idString, AbstractShipmentPlanElement.class); + tuple.getShipment().getSchedule().addPlanElement(id, handle); + } + + private void addShipmentToEventHandler(ShipmentTuple tuple){ + for(LogisticsSolutionElement element : reloadingPoint.getClientElements()){ + if(element.getIncomingShipments().getShipments().contains(tuple)){ + eventHandler.addShipment(tuple.getShipment(), element); + break; + } + } + } + + public double getCapacityNeedLinear() { + return capacityNeedLinear; + } + + + public double getCapacityNeedFixed() { + return capacityNeedFixed; + } + + + public ReloadingPoint getReloadingPoint() { + return reloadingPoint; + } + + + public void setReloadingPoint(ReloadingPoint reloadingPoint) { + this.reloadingPoint = reloadingPoint; + } + + public void setEventHandler(ReloadingPointEventHandler eventHandler) { + this.eventHandler = eventHandler; + } + +} diff --git a/src/main/java/lsp/usecase/SimpleForwardSolutionScheduler.java b/src/main/java/lsp/usecase/SimpleForwardSolutionScheduler.java new file mode 100644 index 00000000000..acb321934ba --- /dev/null +++ b/src/main/java/lsp/usecase/SimpleForwardSolutionScheduler.java @@ -0,0 +1,63 @@ +package lsp.usecase; + +import java.util.ArrayList; + +import lsp.LSP; +import lsp.LogisticsSolution; +import lsp.LogisticsSolutionElement; +import lsp.SolutionScheduler; +import lsp.resources.Resource; +import lsp.shipment.LSPShipment; + +public class SimpleForwardSolutionScheduler implements SolutionScheduler { + + private LSP lsp; + private ArrayList resources; + private int bufferTime; + + public SimpleForwardSolutionScheduler(ArrayList resources) { + this.resources = resources; + } + + @Override + public void scheduleSolutions() { + insertShipmentsAtBeginning(); + for(Resource resource : resources) { + for(Resource lspResource : lsp.getResources()) { + if(lspResource == resource) { + lspResource.schedule(bufferTime); + } + } + } + } + + @Override + public void setLSP(LSP lsp) { + this.lsp = lsp; + } + + + private void insertShipmentsAtBeginning() { + for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { + LogisticsSolutionElement firstElement = getFirstElement(solution); + for(LSPShipment shipment : solution.getShipments() ) { + firstElement.getIncomingShipments().addShipment(shipment.getStartTimeWindow().getStart(), shipment); + } + } + } + + private LogisticsSolutionElement getFirstElement(LogisticsSolution solution){ + for(LogisticsSolutionElement element : solution.getSolutionElements()){ + if(element.getPreviousElement() == null){ + return element; + } + + } + return null; + } + + @Override + public void setBufferTime(int bufferTime) { + this.bufferTime = bufferTime; + } +} From c0df72bf342e2b8ac1984274dccc03a42fb404e4 Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 16:21:48 +0200 Subject: [PATCH 0047/1340] also move test code --- .../adapterTests/CollectionAdapterTest.java | 0 .../adapterTests/DistributionAdapterTest.java | 0 .../adapterTests/FirstReloadAdapterTest.java | 0 .../adapterTests/MainRunAdapterTest.java | 0 .../adapterTests/SecondReloadAdapterTest.java | 0 .../CollectionLSPCreationTest.java | 0 .../CompleteLSPCreationTest.java | 0 .../CollectionLSPMobsimTest.java | 0 .../lspMobsimTests/CompleteLSPMobsimTest.java | 0 .../FirstReloadLSPMobsimTest.java | 0 .../lspMobsimTests/MainRunLSPMobsimTest.java | 0 .../MainRunOnlyLSPMobsimTest.java | 0 ...ipleIterationsCollectionLSPMobsimTest.java | 0 ...pleIterationsFirstReloadLSPMobsimTest.java | 0 ...ultipleIterationsMainRunLSPMobsimTest.java | 0 ...leIterationsSecondReloadLSPMobsimTest.java | 0 ...ltipleItreationsCompleteLSPMobsimTest.java | 0 ...tipleShipmentsCollectionLSPMobsimTest.java | 0 ...ultipleShipmentsCompleteLSPMobsimTest.java | 0 ...ipleShipmentsFirstReloadLSPMobsimTest.java | 0 ...MultipleShipmentsMainRunLSPMobsimTest.java | 0 ...pleShipmentsSecondReloadLSPMobsimTest.java | 0 ...ultipleShipmentsCompleteLSPMobsimTest.java | 0 .../SecondReloadLSPMobsimTest.java | 0 .../lspPlanTests/CollectionLSPPlanTest.java | 0 .../lspPlanTests/CompleteLSPPlanTest.java | 0 .../CollectionLSPReplanningTest.java | 0 .../GenericStrategyManagerFactoryImpl.java | 0 .../lspReplanningTests/TomorrowAssigner.java | 0 ...morrowShipmentAssignerStrategyFactory.java | 0 .../CollectionLSPScoringTest.java | 0 ...pleIterationsCollectionLSPScoringTest.java | 0 .../lspScoringTests/TipEventHandler.java | 0 .../test/java}/lspScoringTests/TipInfo.java | 0 .../test/java}/lspScoringTests/TipScorer.java | 0 .../lspScoringTests/TipSimulationTracker.java | 0 .../CollectionLSPShipmentAssigmentTest.java | 0 .../CompleteLSPShipmentAssignerTest.java | 0 .../CollectionShipmentBuilderTest.java | 0 .../CompleteShipmentBuilderTest.java | 0 .../DistributionShipmentBuilderTest.java | 0 .../AssignerRequirementsTest.java | 0 .../requirementsCheckerTests/BlueInfo.java | 0 .../BlueRequirement.java | 0 .../NonsenseOffer.java | 0 .../requirementsCheckerTests/RedInfo.java | 0 .../RedRequirement.java | 0 .../RequirementsAssigner.java | 0 .../RequirementsTransferrer.java | 0 .../TransferrerRequirementsTest.java | 0 .../CollectionElementTest.java | 0 .../DistributionElementTest.java | 0 .../FirstReloadElementTest.java | 0 .../MainRunElementTest.java | 0 .../SecondReloadElementTest.java | 0 .../solutionTests/CollectionSolutionTest.java | 0 .../solutionTests/CompleteSolutionTest.java | 0 .../test/java}/testSuite/FTLabTestSuite.java | 0 test/cascadingInfoTest/AverageTimeInfo.java | 55 -- .../AverageTimeInfoFunction.java | 25 - .../AverageTimeInfoFunctionValue.java | 23 - .../cascadingInfoTest/AverageTimeTracker.java | 56 -- test/cascadingInfoTest/CascadingInfoTest.java | 224 ------ test/cascadingInfoTest/TimeSpanHandler.java | 56 -- .../demandObjectTests/AllOffersRequester.java | 37 - .../DemandObjectBuilderTest.java | 140 ---- .../FortyTwoDemandScorer.java | 19 - .../HalfLotSizeDemandPlanGenerator.java | 40 -- .../InitialLSPGenerator.java | 252 ------- test/demandObjectTests/LinearOffer.java | 85 --- .../SimpleOfferTransferrer.java | 30 - .../CollectionLSPSchedulingTest.java | 254 ------- .../CompleteLSPSchedulingTest.java | 647 ------------------ .../FirstReloadLSPSchedulingTest.java | 346 ---------- .../MainRunLSPSchedulingTest.java | 469 ------------- ...eShipmentsCollectionLSPSchedulingTest.java | 253 ------- ...pleShipmentsCompleteLSPSchedulingTest.java | 646 ----------------- ...ShipmentsFirstReloadLSPSchedulingTest.java | 344 ---------- ...ipleShipmentsMainRunLSPSchedulingTest.java | 467 ------------- ...hipmentsSecondReloadLSPSchedulingTest.java | 530 -------------- .../SecondReloadLSPSchedulingTest.java | 530 -------------- .../CollectionServiceHandler.java | 87 --- .../CollectionTrackerTest.java | 328 --------- test/testLSPWithCostTracker/CostInfo.java | 49 -- .../CostInfoFunction.java | 31 - .../DistanceAndTimeHandler.java | 84 --- .../FixedCostFunctionValue.java | 24 - .../LinearCostFunctionValue.java | 23 - .../LinearCostTracker.java | 102 --- .../TourStartHandler.java | 24 - .../AllOffersRequester.java | 37 - .../FortyTwoDemandScorer.java | 19 - .../HalfLotSizeDemandPlanGenerator.java | 40 -- .../InitialLSPGenerator.java | 252 ------- test/testMutualReplanning/LinearOffer.java | 85 --- .../MutualReplanningTest.java | 239 ------- .../SimpleOfferTransferrer.java | 30 - .../AllOffersRequester.java | 37 - .../CollectionServiceHandler.java | 87 --- .../CostInfo.java | 49 -- .../CostInfoFunction.java | 29 - .../DistanceAndTimeHandler.java | 82 --- .../FixedCostFunctionValue.java | 24 - .../LinearCostFunctionValue.java | 24 - .../LinearCostTracker.java | 104 --- .../LinearOffer.java | 98 --- .../LinearOfferFactoryImpl.java | 74 -- .../LinearOfferVisitor.java | 35 - .../MutualReplanningAndOfferUpdateTest.java | 291 -------- .../TourStartHandler.java | 24 - 110 files changed, 7940 deletions(-) rename {test => src/test/java}/adapterTests/CollectionAdapterTest.java (100%) rename {test => src/test/java}/adapterTests/DistributionAdapterTest.java (100%) rename {test => src/test/java}/adapterTests/FirstReloadAdapterTest.java (100%) rename {test => src/test/java}/adapterTests/MainRunAdapterTest.java (100%) rename {test => src/test/java}/adapterTests/SecondReloadAdapterTest.java (100%) rename {test => src/test/java}/lspCreationTests/CollectionLSPCreationTest.java (100%) rename {test => src/test/java}/lspCreationTests/CompleteLSPCreationTest.java (100%) rename {test => src/test/java}/lspMobsimTests/CollectionLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/CompleteLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/FirstReloadLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MainRunLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MainRunOnlyLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java (100%) rename {test => src/test/java}/lspMobsimTests/SecondReloadLSPMobsimTest.java (100%) rename {test => src/test/java}/lspPlanTests/CollectionLSPPlanTest.java (100%) rename {test => src/test/java}/lspPlanTests/CompleteLSPPlanTest.java (100%) rename {test => src/test/java}/lspReplanningTests/CollectionLSPReplanningTest.java (100%) rename {test => src/test/java}/lspReplanningTests/GenericStrategyManagerFactoryImpl.java (100%) rename {test => src/test/java}/lspReplanningTests/TomorrowAssigner.java (100%) rename {test => src/test/java}/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java (100%) rename {test => src/test/java}/lspScoringTests/CollectionLSPScoringTest.java (100%) rename {test => src/test/java}/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java (100%) rename {test => src/test/java}/lspScoringTests/TipEventHandler.java (100%) rename {test => src/test/java}/lspScoringTests/TipInfo.java (100%) rename {test => src/test/java}/lspScoringTests/TipScorer.java (100%) rename {test => src/test/java}/lspScoringTests/TipSimulationTracker.java (100%) rename {test => src/test/java}/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java (100%) rename {test => src/test/java}/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java (100%) rename {test => src/test/java}/lspShipmentTest/CollectionShipmentBuilderTest.java (100%) rename {test => src/test/java}/lspShipmentTest/CompleteShipmentBuilderTest.java (100%) rename {test => src/test/java}/lspShipmentTest/DistributionShipmentBuilderTest.java (100%) rename {test => src/test/java}/requirementsCheckerTests/AssignerRequirementsTest.java (100%) rename {test => src/test/java}/requirementsCheckerTests/BlueInfo.java (100%) rename {test => src/test/java}/requirementsCheckerTests/BlueRequirement.java (100%) rename {test => src/test/java}/requirementsCheckerTests/NonsenseOffer.java (100%) rename {test => src/test/java}/requirementsCheckerTests/RedInfo.java (100%) rename {test => src/test/java}/requirementsCheckerTests/RedRequirement.java (100%) rename {test => src/test/java}/requirementsCheckerTests/RequirementsAssigner.java (100%) rename {test => src/test/java}/requirementsCheckerTests/RequirementsTransferrer.java (100%) rename {test => src/test/java}/requirementsCheckerTests/TransferrerRequirementsTest.java (100%) rename {test => src/test/java}/solutionElementTests/CollectionElementTest.java (100%) rename {test => src/test/java}/solutionElementTests/DistributionElementTest.java (100%) rename {test => src/test/java}/solutionElementTests/FirstReloadElementTest.java (100%) rename {test => src/test/java}/solutionElementTests/MainRunElementTest.java (100%) rename {test => src/test/java}/solutionElementTests/SecondReloadElementTest.java (100%) rename {test => src/test/java}/solutionTests/CollectionSolutionTest.java (100%) rename {test => src/test/java}/solutionTests/CompleteSolutionTest.java (100%) rename {test => src/test/java}/testSuite/FTLabTestSuite.java (100%) delete mode 100644 test/cascadingInfoTest/AverageTimeInfo.java delete mode 100644 test/cascadingInfoTest/AverageTimeInfoFunction.java delete mode 100644 test/cascadingInfoTest/AverageTimeInfoFunctionValue.java delete mode 100644 test/cascadingInfoTest/AverageTimeTracker.java delete mode 100644 test/cascadingInfoTest/CascadingInfoTest.java delete mode 100644 test/cascadingInfoTest/TimeSpanHandler.java delete mode 100644 test/demandObjectTests/AllOffersRequester.java delete mode 100644 test/demandObjectTests/DemandObjectBuilderTest.java delete mode 100644 test/demandObjectTests/FortyTwoDemandScorer.java delete mode 100644 test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java delete mode 100644 test/demandObjectTests/InitialLSPGenerator.java delete mode 100644 test/demandObjectTests/LinearOffer.java delete mode 100644 test/demandObjectTests/SimpleOfferTransferrer.java delete mode 100644 test/lspSchedulingTests/CollectionLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/CompleteLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/MainRunLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java delete mode 100644 test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java delete mode 100644 test/testLSPWithCostTracker/CollectionServiceHandler.java delete mode 100644 test/testLSPWithCostTracker/CollectionTrackerTest.java delete mode 100644 test/testLSPWithCostTracker/CostInfo.java delete mode 100644 test/testLSPWithCostTracker/CostInfoFunction.java delete mode 100644 test/testLSPWithCostTracker/DistanceAndTimeHandler.java delete mode 100644 test/testLSPWithCostTracker/FixedCostFunctionValue.java delete mode 100644 test/testLSPWithCostTracker/LinearCostFunctionValue.java delete mode 100644 test/testLSPWithCostTracker/LinearCostTracker.java delete mode 100644 test/testLSPWithCostTracker/TourStartHandler.java delete mode 100644 test/testMutualReplanning/AllOffersRequester.java delete mode 100644 test/testMutualReplanning/FortyTwoDemandScorer.java delete mode 100644 test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java delete mode 100644 test/testMutualReplanning/InitialLSPGenerator.java delete mode 100644 test/testMutualReplanning/LinearOffer.java delete mode 100644 test/testMutualReplanning/MutualReplanningTest.java delete mode 100644 test/testMutualReplanning/SimpleOfferTransferrer.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/CostInfo.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/LinearOffer.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java delete mode 100644 test/testMutualreplanningWithOfferUpdate/TourStartHandler.java diff --git a/test/adapterTests/CollectionAdapterTest.java b/src/test/java/adapterTests/CollectionAdapterTest.java similarity index 100% rename from test/adapterTests/CollectionAdapterTest.java rename to src/test/java/adapterTests/CollectionAdapterTest.java diff --git a/test/adapterTests/DistributionAdapterTest.java b/src/test/java/adapterTests/DistributionAdapterTest.java similarity index 100% rename from test/adapterTests/DistributionAdapterTest.java rename to src/test/java/adapterTests/DistributionAdapterTest.java diff --git a/test/adapterTests/FirstReloadAdapterTest.java b/src/test/java/adapterTests/FirstReloadAdapterTest.java similarity index 100% rename from test/adapterTests/FirstReloadAdapterTest.java rename to src/test/java/adapterTests/FirstReloadAdapterTest.java diff --git a/test/adapterTests/MainRunAdapterTest.java b/src/test/java/adapterTests/MainRunAdapterTest.java similarity index 100% rename from test/adapterTests/MainRunAdapterTest.java rename to src/test/java/adapterTests/MainRunAdapterTest.java diff --git a/test/adapterTests/SecondReloadAdapterTest.java b/src/test/java/adapterTests/SecondReloadAdapterTest.java similarity index 100% rename from test/adapterTests/SecondReloadAdapterTest.java rename to src/test/java/adapterTests/SecondReloadAdapterTest.java diff --git a/test/lspCreationTests/CollectionLSPCreationTest.java b/src/test/java/lspCreationTests/CollectionLSPCreationTest.java similarity index 100% rename from test/lspCreationTests/CollectionLSPCreationTest.java rename to src/test/java/lspCreationTests/CollectionLSPCreationTest.java diff --git a/test/lspCreationTests/CompleteLSPCreationTest.java b/src/test/java/lspCreationTests/CompleteLSPCreationTest.java similarity index 100% rename from test/lspCreationTests/CompleteLSPCreationTest.java rename to src/test/java/lspCreationTests/CompleteLSPCreationTest.java diff --git a/test/lspMobsimTests/CollectionLSPMobsimTest.java b/src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/CollectionLSPMobsimTest.java rename to src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java diff --git a/test/lspMobsimTests/CompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/CompleteLSPMobsimTest.java rename to src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java diff --git a/test/lspMobsimTests/FirstReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/FirstReloadLSPMobsimTest.java rename to src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java diff --git a/test/lspMobsimTests/MainRunLSPMobsimTest.java b/src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MainRunLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java diff --git a/test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MainRunOnlyLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java diff --git a/test/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java rename to src/test/java/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java diff --git a/test/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java rename to src/test/java/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java diff --git a/test/lspMobsimTests/SecondReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java similarity index 100% rename from test/lspMobsimTests/SecondReloadLSPMobsimTest.java rename to src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java diff --git a/test/lspPlanTests/CollectionLSPPlanTest.java b/src/test/java/lspPlanTests/CollectionLSPPlanTest.java similarity index 100% rename from test/lspPlanTests/CollectionLSPPlanTest.java rename to src/test/java/lspPlanTests/CollectionLSPPlanTest.java diff --git a/test/lspPlanTests/CompleteLSPPlanTest.java b/src/test/java/lspPlanTests/CompleteLSPPlanTest.java similarity index 100% rename from test/lspPlanTests/CompleteLSPPlanTest.java rename to src/test/java/lspPlanTests/CompleteLSPPlanTest.java diff --git a/test/lspReplanningTests/CollectionLSPReplanningTest.java b/src/test/java/lspReplanningTests/CollectionLSPReplanningTest.java similarity index 100% rename from test/lspReplanningTests/CollectionLSPReplanningTest.java rename to src/test/java/lspReplanningTests/CollectionLSPReplanningTest.java diff --git a/test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java b/src/test/java/lspReplanningTests/GenericStrategyManagerFactoryImpl.java similarity index 100% rename from test/lspReplanningTests/GenericStrategyManagerFactoryImpl.java rename to src/test/java/lspReplanningTests/GenericStrategyManagerFactoryImpl.java diff --git a/test/lspReplanningTests/TomorrowAssigner.java b/src/test/java/lspReplanningTests/TomorrowAssigner.java similarity index 100% rename from test/lspReplanningTests/TomorrowAssigner.java rename to src/test/java/lspReplanningTests/TomorrowAssigner.java diff --git a/test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java b/src/test/java/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java similarity index 100% rename from test/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java rename to src/test/java/lspReplanningTests/TomorrowShipmentAssignerStrategyFactory.java diff --git a/test/lspScoringTests/CollectionLSPScoringTest.java b/src/test/java/lspScoringTests/CollectionLSPScoringTest.java similarity index 100% rename from test/lspScoringTests/CollectionLSPScoringTest.java rename to src/test/java/lspScoringTests/CollectionLSPScoringTest.java diff --git a/test/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java b/src/test/java/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java similarity index 100% rename from test/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java rename to src/test/java/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java diff --git a/test/lspScoringTests/TipEventHandler.java b/src/test/java/lspScoringTests/TipEventHandler.java similarity index 100% rename from test/lspScoringTests/TipEventHandler.java rename to src/test/java/lspScoringTests/TipEventHandler.java diff --git a/test/lspScoringTests/TipInfo.java b/src/test/java/lspScoringTests/TipInfo.java similarity index 100% rename from test/lspScoringTests/TipInfo.java rename to src/test/java/lspScoringTests/TipInfo.java diff --git a/test/lspScoringTests/TipScorer.java b/src/test/java/lspScoringTests/TipScorer.java similarity index 100% rename from test/lspScoringTests/TipScorer.java rename to src/test/java/lspScoringTests/TipScorer.java diff --git a/test/lspScoringTests/TipSimulationTracker.java b/src/test/java/lspScoringTests/TipSimulationTracker.java similarity index 100% rename from test/lspScoringTests/TipSimulationTracker.java rename to src/test/java/lspScoringTests/TipSimulationTracker.java diff --git a/test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java b/src/test/java/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java similarity index 100% rename from test/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java rename to src/test/java/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java diff --git a/test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/src/test/java/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java similarity index 100% rename from test/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java rename to src/test/java/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java diff --git a/test/lspShipmentTest/CollectionShipmentBuilderTest.java b/src/test/java/lspShipmentTest/CollectionShipmentBuilderTest.java similarity index 100% rename from test/lspShipmentTest/CollectionShipmentBuilderTest.java rename to src/test/java/lspShipmentTest/CollectionShipmentBuilderTest.java diff --git a/test/lspShipmentTest/CompleteShipmentBuilderTest.java b/src/test/java/lspShipmentTest/CompleteShipmentBuilderTest.java similarity index 100% rename from test/lspShipmentTest/CompleteShipmentBuilderTest.java rename to src/test/java/lspShipmentTest/CompleteShipmentBuilderTest.java diff --git a/test/lspShipmentTest/DistributionShipmentBuilderTest.java b/src/test/java/lspShipmentTest/DistributionShipmentBuilderTest.java similarity index 100% rename from test/lspShipmentTest/DistributionShipmentBuilderTest.java rename to src/test/java/lspShipmentTest/DistributionShipmentBuilderTest.java diff --git a/test/requirementsCheckerTests/AssignerRequirementsTest.java b/src/test/java/requirementsCheckerTests/AssignerRequirementsTest.java similarity index 100% rename from test/requirementsCheckerTests/AssignerRequirementsTest.java rename to src/test/java/requirementsCheckerTests/AssignerRequirementsTest.java diff --git a/test/requirementsCheckerTests/BlueInfo.java b/src/test/java/requirementsCheckerTests/BlueInfo.java similarity index 100% rename from test/requirementsCheckerTests/BlueInfo.java rename to src/test/java/requirementsCheckerTests/BlueInfo.java diff --git a/test/requirementsCheckerTests/BlueRequirement.java b/src/test/java/requirementsCheckerTests/BlueRequirement.java similarity index 100% rename from test/requirementsCheckerTests/BlueRequirement.java rename to src/test/java/requirementsCheckerTests/BlueRequirement.java diff --git a/test/requirementsCheckerTests/NonsenseOffer.java b/src/test/java/requirementsCheckerTests/NonsenseOffer.java similarity index 100% rename from test/requirementsCheckerTests/NonsenseOffer.java rename to src/test/java/requirementsCheckerTests/NonsenseOffer.java diff --git a/test/requirementsCheckerTests/RedInfo.java b/src/test/java/requirementsCheckerTests/RedInfo.java similarity index 100% rename from test/requirementsCheckerTests/RedInfo.java rename to src/test/java/requirementsCheckerTests/RedInfo.java diff --git a/test/requirementsCheckerTests/RedRequirement.java b/src/test/java/requirementsCheckerTests/RedRequirement.java similarity index 100% rename from test/requirementsCheckerTests/RedRequirement.java rename to src/test/java/requirementsCheckerTests/RedRequirement.java diff --git a/test/requirementsCheckerTests/RequirementsAssigner.java b/src/test/java/requirementsCheckerTests/RequirementsAssigner.java similarity index 100% rename from test/requirementsCheckerTests/RequirementsAssigner.java rename to src/test/java/requirementsCheckerTests/RequirementsAssigner.java diff --git a/test/requirementsCheckerTests/RequirementsTransferrer.java b/src/test/java/requirementsCheckerTests/RequirementsTransferrer.java similarity index 100% rename from test/requirementsCheckerTests/RequirementsTransferrer.java rename to src/test/java/requirementsCheckerTests/RequirementsTransferrer.java diff --git a/test/requirementsCheckerTests/TransferrerRequirementsTest.java b/src/test/java/requirementsCheckerTests/TransferrerRequirementsTest.java similarity index 100% rename from test/requirementsCheckerTests/TransferrerRequirementsTest.java rename to src/test/java/requirementsCheckerTests/TransferrerRequirementsTest.java diff --git a/test/solutionElementTests/CollectionElementTest.java b/src/test/java/solutionElementTests/CollectionElementTest.java similarity index 100% rename from test/solutionElementTests/CollectionElementTest.java rename to src/test/java/solutionElementTests/CollectionElementTest.java diff --git a/test/solutionElementTests/DistributionElementTest.java b/src/test/java/solutionElementTests/DistributionElementTest.java similarity index 100% rename from test/solutionElementTests/DistributionElementTest.java rename to src/test/java/solutionElementTests/DistributionElementTest.java diff --git a/test/solutionElementTests/FirstReloadElementTest.java b/src/test/java/solutionElementTests/FirstReloadElementTest.java similarity index 100% rename from test/solutionElementTests/FirstReloadElementTest.java rename to src/test/java/solutionElementTests/FirstReloadElementTest.java diff --git a/test/solutionElementTests/MainRunElementTest.java b/src/test/java/solutionElementTests/MainRunElementTest.java similarity index 100% rename from test/solutionElementTests/MainRunElementTest.java rename to src/test/java/solutionElementTests/MainRunElementTest.java diff --git a/test/solutionElementTests/SecondReloadElementTest.java b/src/test/java/solutionElementTests/SecondReloadElementTest.java similarity index 100% rename from test/solutionElementTests/SecondReloadElementTest.java rename to src/test/java/solutionElementTests/SecondReloadElementTest.java diff --git a/test/solutionTests/CollectionSolutionTest.java b/src/test/java/solutionTests/CollectionSolutionTest.java similarity index 100% rename from test/solutionTests/CollectionSolutionTest.java rename to src/test/java/solutionTests/CollectionSolutionTest.java diff --git a/test/solutionTests/CompleteSolutionTest.java b/src/test/java/solutionTests/CompleteSolutionTest.java similarity index 100% rename from test/solutionTests/CompleteSolutionTest.java rename to src/test/java/solutionTests/CompleteSolutionTest.java diff --git a/test/testSuite/FTLabTestSuite.java b/src/test/java/testSuite/FTLabTestSuite.java similarity index 100% rename from test/testSuite/FTLabTestSuite.java rename to src/test/java/testSuite/FTLabTestSuite.java diff --git a/test/cascadingInfoTest/AverageTimeInfo.java b/test/cascadingInfoTest/AverageTimeInfo.java deleted file mode 100644 index 9431917e5ca..00000000000 --- a/test/cascadingInfoTest/AverageTimeInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -package cascadingInfoTest; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionImpl; -import lsp.functions.InfoFunctionValue; -import lsp.functions.InfoFunctionValueImpl; - -public class AverageTimeInfo extends Info{ - - private InfoFunction function; - private String name = "averageTime"; - - public AverageTimeInfo() { - function = new AverageTimeInfoFunction(); - } - - @Override - public String getName() { - return name; - } - - @Override - public InfoFunction getFunction() { - return function; - } - - @Override - public double getFromTime() { - return 0; - } - - @Override - public double getToTime() { - return Double.MAX_VALUE; - } - - @Override - public void update() { - Info preInfo = predecessorInfos.iterator().next(); - AverageTimeInfo avgInfo = (AverageTimeInfo)preInfo; - InfoFunctionValue infoVal = avgInfo.getFunction().getValues().iterator().next(); - if( infoVal.getValue() instanceof Double) { - if(function.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue) { - AverageTimeInfoFunctionValue avgVal = (AverageTimeInfoFunctionValue) function.getValues().iterator().next(); - avgVal.setValue((Double)infoVal.getValue()); - } - } - } - - @Override - public void setName(String name) { - this.name = name; - } -} diff --git a/test/cascadingInfoTest/AverageTimeInfoFunction.java b/test/cascadingInfoTest/AverageTimeInfoFunction.java deleted file mode 100644 index fb3a95fe65b..00000000000 --- a/test/cascadingInfoTest/AverageTimeInfoFunction.java +++ /dev/null @@ -1,25 +0,0 @@ -package cascadingInfoTest; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; - - - -public class AverageTimeInfoFunction implements InfoFunction{ - - private Collection> values; - - public AverageTimeInfoFunction() { - values = new ArrayList>(); - values.add(new AverageTimeInfoFunctionValue()); - } - - @Override - public Collection> getValues() { - return values; - } - -} diff --git a/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java b/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java deleted file mode 100644 index 9136b623161..00000000000 --- a/test/cascadingInfoTest/AverageTimeInfoFunctionValue.java +++ /dev/null @@ -1,23 +0,0 @@ -package cascadingInfoTest; - -import lsp.functions.InfoFunctionValue; - -public class AverageTimeInfoFunctionValue implements InfoFunctionValue{ - - private Double value; - - @Override - public String getName() { - return "averageTimeInSeconds"; - } - - @Override - public void setValue(Double value) { - this.value = value; - } - - @Override - public Double getValue() { - return value; - } -} diff --git a/test/cascadingInfoTest/AverageTimeTracker.java b/test/cascadingInfoTest/AverageTimeTracker.java deleted file mode 100644 index a3708bc0e4d..00000000000 --- a/test/cascadingInfoTest/AverageTimeTracker.java +++ /dev/null @@ -1,56 +0,0 @@ -package cascadingInfoTest; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.events.handler.EventHandler; - -import lsp.functions.Info; -import lsp.tracking.SimulationTracker; - - - -public class AverageTimeTracker implements SimulationTracker { - - private Collection handlers; - private Collection infos; - private AverageTimeInfo timeInfo; - private TimeSpanHandler handler; - - public AverageTimeTracker() { - handlers = new ArrayList(); - handler = new TimeSpanHandler(); - handlers.add(handler); - infos = new ArrayList(); - timeInfo = new AverageTimeInfo(); - infos.add(timeInfo); - } - - - @Override - public Collection getEventHandlers() { - return handlers; - } - - @Override - public Collection getInfos() { - return infos; - } - - @Override - public void notifyAfterMobsim(AfterMobsimEvent event) { - int numberOfStops = handler.getNumberOfStops(); - double totalTransportTime = handler.getTotalTime(); - double averageTransportTime = totalTransportTime/numberOfStops; - AverageTimeInfoFunctionValue value = (AverageTimeInfoFunctionValue) timeInfo.getFunction().getValues().iterator().next(); - value.setValue(averageTransportTime); - } - - - @Override - public void reset() { - // TODO Auto-generated method stub - - } -} diff --git a/test/cascadingInfoTest/CascadingInfoTest.java b/test/cascadingInfoTest/CascadingInfoTest.java deleted file mode 100644 index 2bf4bc20715..00000000000 --- a/test/cascadingInfoTest/CascadingInfoTest.java +++ /dev/null @@ -1,224 +0,0 @@ -package cascadingInfoTest; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; - - - -public class CascadingInfoTest { - private Network network; - private LSP collectionLSP; - private Carrier carrier; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private LogisticsSolution collectionSolution; - private AverageTimeInfo elementInfo; - private AverageTimeInfo solutionInfo; - private AverageTimeTracker timeTracker; - - @Before - public void initialize() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Link collectionLink = network.getLinks().get(collectionLinkId); - - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = adapterBuilder.build(); - timeTracker = new AverageTimeTracker(); - collectionAdapter.addSimulationTracker(timeTracker); - - - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - collectionElement = collectionElementBuilder.build(); - - elementInfo = new AverageTimeInfo(); - elementInfo.addPredecessorInfo(collectionAdapter.getInfos().iterator().next()); - collectionElement.getInfos().add(elementInfo); - - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - collectionSolution = collectionSolutionBuilder.build(); - - solutionInfo = new AverageTimeInfo(); - solutionInfo.addPredecessorInfo(collectionElement.getInfos().iterator().next()); - collectionElement.getInfos().add(solutionInfo); - - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - collectionLSP = collectionLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id toLinkId = collectionLinkId; - - - for(int i = 1; i < 11; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = 1 + random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - collectionLSP.assignShipmentToLSP(shipment); - } - - collectionLSP.scheduleSoultions(); - - ArrayList lspList = new ArrayList(); - lspList.add(collectionLSP); - LSPs lsps = new LSPs(lspList); - - Controler controler = new Controler(config); - - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); - controler.run(); - } - - @Test - public void testCascadingInfos() { - assertTrue(timeTracker.getInfos().iterator().next() == elementInfo.getPredecessorInfos().iterator().next()); - assertTrue(timeTracker.getInfos().iterator().next() instanceof AverageTimeInfo); - AverageTimeInfo resourceInfo = (AverageTimeInfo) timeTracker.getInfos().iterator().next(); - assertTrue(resourceInfo.getFunction() instanceof AverageTimeInfoFunction); - AverageTimeInfoFunction resourceInfoFunction = (AverageTimeInfoFunction) resourceInfo.getFunction(); - assertTrue(resourceInfoFunction.getValues().size() == 1); - assertTrue(resourceInfoFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); - AverageTimeInfoFunctionValue averageResourceValue = (AverageTimeInfoFunctionValue) resourceInfoFunction.getValues().iterator().next(); - assertTrue(elementInfo.getFunction() instanceof AverageTimeInfoFunction); - AverageTimeInfoFunction averageElementFunction = (AverageTimeInfoFunction) elementInfo.getFunction(); - assertTrue(averageElementFunction.getValues().size() == 1); - assertTrue(averageElementFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); - AverageTimeInfoFunctionValue averageElementValue = (AverageTimeInfoFunctionValue) averageElementFunction.getValues().iterator().next(); - assertTrue(averageElementValue.getValue() > 0); - assertTrue(averageElementFunction.getValues().iterator().next().getValue() instanceof Double); - assertTrue(solutionInfo.getFunction() instanceof AverageTimeInfoFunction); - assertTrue(solutionInfo.getPredecessorInfos().iterator().next() == elementInfo); - AverageTimeInfoFunction averageSolutionFunction = (AverageTimeInfoFunction) solutionInfo.getFunction(); - assertTrue(averageSolutionFunction.getValues().size() == 1); - assertTrue(averageSolutionFunction.getValues().iterator().next() instanceof AverageTimeInfoFunctionValue); - AverageTimeInfoFunctionValue averageSolutionValue = (AverageTimeInfoFunctionValue) averageSolutionFunction.getValues().iterator().next(); - assertTrue(averageSolutionValue.getValue() > 0); - assertTrue(averageElementValue.getValue() == averageResourceValue.getValue()); - assertTrue(averageElementValue.getValue() == averageSolutionValue.getValue()); - } - -} diff --git a/test/cascadingInfoTest/TimeSpanHandler.java b/test/cascadingInfoTest/TimeSpanHandler.java deleted file mode 100644 index 645009b65e3..00000000000 --- a/test/cascadingInfoTest/TimeSpanHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -package cascadingInfoTest; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; -import lsp.events.TourStartEvent; -import lsp.events.TourStartEventHandler; - - - -public class TimeSpanHandler implements TourStartEventHandler, ServiceStartEventHandler{ - - private int numberOfStops; - private double totalTime; - - private Collection startEvents; - - public TimeSpanHandler() { - startEvents = new ArrayList(); - } - - @Override - public void reset(int iteration) { - totalTime = 0; - numberOfStops = 0; - } - - @Override - public void handleEvent(ServiceStartEvent event) { - numberOfStops++; - for(TourStartEvent startEvent : startEvents) { - if(startEvent.getDriverId() == event.getDriverId()) { - double startTime = startEvent.getTime(); - double serviceTime = event.getTime(); - totalTime = totalTime + (serviceTime - startTime); - break; - } - } - } - - @Override - public void handleEvent(TourStartEvent event) { - startEvents.add(event); - } - - public int getNumberOfStops() { - return numberOfStops; - } - - public double getTotalTime() { - return totalTime; - } - -} diff --git a/test/demandObjectTests/AllOffersRequester.java b/test/demandObjectTests/AllOffersRequester.java deleted file mode 100644 index 290217dd392..00000000000 --- a/test/demandObjectTests/AllOffersRequester.java +++ /dev/null @@ -1,37 +0,0 @@ -package demandObjectTests; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.OfferRequester; -import demand.offer.Offer; - -public class AllOffersRequester implements OfferRequester{ - - private DemandObject demandObject; - - public AllOffersRequester() { - - } - - @Override - public Collection requestOffers(Collection lsps) { - ArrayList offers = new ArrayList(); - for(LSPDecorator lsp : lsps) { - for(LogisticsSolutionDecorator solution : lsp.getSelectedPlan().getSolutionDecorators()) { - offers.add(lsp.getOffer(demandObject, "linear", solution.getId())); - } - } - return offers; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/test/demandObjectTests/DemandObjectBuilderTest.java b/test/demandObjectTests/DemandObjectBuilderTest.java deleted file mode 100644 index 7ade5976153..00000000000 --- a/test/demandObjectTests/DemandObjectBuilderTest.java +++ /dev/null @@ -1,140 +0,0 @@ -package demandObjectTests; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.replanning.modules.GenericPlanStrategyModule; -import org.matsim.core.replanning.selectors.BestPlanSelector; -import org.matsim.core.scenario.ScenarioUtils; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandAgent.DemandAgent; -import demand.demandAgent.DemandAgentImpl; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjectImpl; -import demand.demandObject.DemandPlan; -import demand.demandObject.DemandPlanImpl; -import demand.demandObject.OfferRequester; -import demand.demandObject.ShipperShipment; -import demand.demandObject.ShipperShipmentImpl; -import demand.mutualReplanning.DemandPlanStrategyImpl; -import demand.mutualReplanning.DemandReplannerImpl; -import demand.mutualReplanning.OfferReplanningStrategyModule; -import demand.mutualReplanning.OfferReplanningStrategyModuleImpl; -import demand.offer.Offer; - -public class DemandObjectBuilderTest { - - private Network network; - private ArrayList demandObjects; - private OfferRequester offerRequester; - private LSPDecorator lsp; - private DemandReplannerImpl replanner; - private DemandPlanStrategyImpl planStrategy; - private OfferReplanningStrategyModule offerModule ; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - this.demandObjects = new ArrayList(); - Random random = new Random(1); - lsp = new InitialLSPGenerator().createInitialLSP(); - - - for(int i = 1; i < 11 ; i++) { - DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); - builder.setId(Id.create("DemandObject_" + i, DemandObject.class)); - DemandAgentImpl.Builder shipperBuilder = DemandAgentImpl.Builder.newInstance(); - shipperBuilder.setId(Id.create("DemandObject_" + i+ "_Shipper", DemandAgent.class)); - builder.setShipper(shipperBuilder.build()); - DemandAgentImpl.Builder recipientBuilder = DemandAgentImpl.Builder.newInstance(); - recipientBuilder.setId(Id.create("DemandObject_" + i+ "_Recipient", DemandAgent.class)); - builder.setRecipient(recipientBuilder.build()); - double shipmentSize= 5 + random.nextDouble()*5; - builder.setStrengthOfFlow(shipmentSize); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - } - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); - ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); - shipmentBuilder.setId(Id.create("DemandObject_" + i+ "_Shipment", ShipperShipment.class)); - shipmentBuilder.setShipmentSize(shipmentSize); - shipmentBuilder.setServiceTime(shipmentSize * 60); - planBuilder.setShipperShipment(shipmentBuilder.build()); - planBuilder.setLsp(lsp); - planBuilder.setLogisticsSolutionId(lsp.getSelectedPlan().getSolutions().iterator().next().getId()); - builder.setInitialPlan(planBuilder.build()); - builder.setScorer(new FortyTwoDemandScorer()); - replanner = new DemandReplannerImpl(); - planStrategy = new DemandPlanStrategyImpl(new BestPlanSelector()); - offerModule = new OfferReplanningStrategyModuleImpl(); - planStrategy.addStrategyModule(offerModule); - replanner.addStrategy(planStrategy); - builder.setReplanner(replanner); - builder.setOfferRequester(new AllOffersRequester()); - builder.setDemandPlanGenerator(new HalfLotSizeDemandPlanGenerator()); - demandObjects.add(builder.build()); - } - - } - - @Test - public void testDemandObjectBuilding() { - for(DemandObject demandObject : demandObjects) { - Offer offer = lsp.getOffer(demandObject, "linear", lsp.getSelectedPlan().getSolutions().iterator().next().getId()); - CollectionofferList= new ArrayList<>(); - offerList.add(offer); - DemandPlan newPlan = demandObject.getDemandPlanGenerator().createDemandPlan(offerList); - DemandPlan oldPlan = demandObject.getSelectedPlan(); - assertTrue(newPlan.getLsp() == oldPlan.getLsp()); - assertTrue(newPlan.getSolutionId() == oldPlan.getSolutionId()); - assertTrue(newPlan.getShipment().getShipmentSize() == oldPlan.getShipment().getShipmentSize()/2); - assertNotNull(demandObject.getOfferRequester()); - assertNotNull(demandObject.getReplanner()); - - } - } - -} diff --git a/test/demandObjectTests/FortyTwoDemandScorer.java b/test/demandObjectTests/FortyTwoDemandScorer.java deleted file mode 100644 index 9a18c6c432c..00000000000 --- a/test/demandObjectTests/FortyTwoDemandScorer.java +++ /dev/null @@ -1,19 +0,0 @@ -package demandObjectTests; - -import demand.demandObject.DemandObject; -import demand.scoring.DemandScorer; - -public class FortyTwoDemandScorer implements DemandScorer { - - @Override - public double scoreCurrentPlan(DemandObject demandObject) { - return 42; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - // TODO Auto-generated method stub - - } - -} diff --git a/test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java b/test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java deleted file mode 100644 index bd4fd139232..00000000000 --- a/test/demandObjectTests/HalfLotSizeDemandPlanGenerator.java +++ /dev/null @@ -1,40 +0,0 @@ -package demandObjectTests; - -import java.util.Collection; - -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; -import demand.demandObject.DemandPlanGenerator; -import demand.demandObject.DemandPlanImpl; -import demand.demandObject.ShipperShipmentImpl; -import demand.offer.Offer; - -public class HalfLotSizeDemandPlanGenerator implements DemandPlanGenerator{ - - private DemandObject demandObject; - - @Override - public DemandPlan createDemandPlan(Collection offers) { - Offer singleOffer = offers.iterator().next(); - DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); - planBuilder.setLsp(singleOffer.getLsp()); - planBuilder.setLogisticsSolutionId(singleOffer.getSolution().getId()); - planBuilder.setDemandObject(demandObject); - - ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); - shipmentBuilder.setDemandObject(demandObject); - shipmentBuilder.setId(demandObject.getSelectedPlan().getShipment().getId()); - shipmentBuilder.setEndTimeWindow(demandObject.getSelectedPlan().getShipment().getEndTimeWindow()); - shipmentBuilder.setStartTimeWindow(demandObject.getSelectedPlan().getShipment().getStartTimeWindow()); - shipmentBuilder.setServiceTime(demandObject.getSelectedPlan().getShipment().getServiceTime()); - shipmentBuilder.setShipmentSize(demandObject.getSelectedPlan().getShipment().getShipmentSize()/2); - planBuilder.setShipperShipment(shipmentBuilder.build()); - return planBuilder.build(); - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/test/demandObjectTests/InitialLSPGenerator.java b/test/demandObjectTests/InitialLSPGenerator.java deleted file mode 100644 index ba525e74a58..00000000000 --- a/test/demandObjectTests/InitialLSPGenerator.java +++ /dev/null @@ -1,252 +0,0 @@ -package demandObjectTests; - -import java.util.ArrayList; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPPlanDecorator; -import demand.decoratedLSP.LSPPlanWithOfferTransferrer; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.offer.OfferFactoryImpl; -import demand.offer.OfferTransferrer; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import requirementsCheckerTests.BlueInfo; -import requirementsCheckerTests.NonsenseOffer; -import requirementsCheckerTests.RedInfo; -import requirementsCheckerTests.RequirementsTransferrer; - -public class InitialLSPGenerator { - - - public LSPDecorator createInitialLSP() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - Network network = scenario.getNetwork(); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(20); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); - mainRunAdapterBuilder.setCarrier(collectionCarrier); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); - - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); - - DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); - Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); - Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); - dsitributionVehicleTypeBuilder.setCapacity(10); - dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - dsitributionVehicleTypeBuilder.setFixCost(49); - dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); - - Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); - distributionCarrierVehicle.setVehicleType(distributionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); - capabilitiesBuilder.addVehicle(distributionCarrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); - Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); - carrier.setCarrierCapabilities(distributionCapabilities); - - - Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); - DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); - distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - distributionAdapterBuilder.setCarrier(carrier); - distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - Resource distributionAdapter = distributionAdapterBuilder.build(); - - Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); - distributionBuilder.setResource(distributionAdapter); - LogisticsSolutionElement distributionElement = distributionBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - secondReloadElement.setNextElement(distributionElement); - distributionElement.setPreviousElement(secondReloadElement); - - Id solutionId = Id.create("Solution", LogisticsSolution.class); - LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); - solutionBuilder.addSolutionElement(collectionElement); - solutionBuilder.addSolutionElement(firstReloadElement); - solutionBuilder.addSolutionElement(mainRunElement); - solutionBuilder.addSolutionElement(secondReloadElement); - solutionBuilder.addSolutionElement(distributionElement); - LogisticsSolutionDecorator solution = solutionBuilder.build(); - - OfferFactoryImpl offerFactory = new OfferFactoryImpl(solution); - offerFactory.addOffer(new LinearOffer(solution)); - solution.setOfferFactory(offerFactory); - - LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); - plan.addSolution(solution); - - OfferTransferrer transferrer = new SimpleOfferTransferrer(); - plan.setOfferTransferrer(transferrer); - - LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); - offerLSPBuilder.setInitialPlan(plan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - offerLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - resourcesList.add(distributionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - offerLSPBuilder.setSolutionScheduler(simpleScheduler); - return offerLSPBuilder.build(); - } - -} diff --git a/test/demandObjectTests/LinearOffer.java b/test/demandObjectTests/LinearOffer.java deleted file mode 100644 index 248f1f78576..00000000000 --- a/test/demandObjectTests/LinearOffer.java +++ /dev/null @@ -1,85 +0,0 @@ -package demandObjectTests; - -import java.util.Random; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.offer.Offer; -import demand.offer.OfferVisitor; -import example.simulationTrackers.CostInfo; -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.LSP; -import lsp.LogisticsSolution; - - -public class LinearOffer implements Offer{ - - private LSPDecorator lsp; - private LogisticsSolutionDecorator solution; - private String type; - private double fix; - private double linear; - - public LinearOffer(LogisticsSolutionDecorator solution) { - this.lsp = solution.getLSP(); - this.solution = solution; - this.type = "linear"; - Random random = new Random(1); - fix = random.nextDouble() * 10; - linear = random.nextDouble() * 10; - } - - @Override - public LSPDecorator getLsp() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getSolution() { - return solution; - } - - @Override - public String getType() { - return type; - } - - public double getFix() { - return fix; - } - - public void setFix(double fix) { - this.fix = fix; - } - - public double getLinear() { - return linear; - } - - public void setLinear(double linear) { - this.linear = linear; - } - - @Override - public void accept(OfferVisitor visitor) { - visitor.visit(this); - } - - @Override - public void update() { - - - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public void setSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - -} diff --git a/test/demandObjectTests/SimpleOfferTransferrer.java b/test/demandObjectTests/SimpleOfferTransferrer.java deleted file mode 100644 index 4efbfd7bdae..00000000000 --- a/test/demandObjectTests/SimpleOfferTransferrer.java +++ /dev/null @@ -1,30 +0,0 @@ -package demandObjectTests; - -import org.matsim.api.core.v01.Id; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.offer.Offer; -import demand.offer.OfferTransferrer; -import lsp.LogisticsSolution; - -public class SimpleOfferTransferrer implements OfferTransferrer{ - - private LSPDecorator lsp; - - @Override - public Offer transferOffer(DemandObject object, String type, Id solutionId) { - return lsp.getSelectedPlan().getSolutionDecorators().iterator().next().getOffer(object, type); - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public LSPDecorator getLSP() { - return lsp; - } - -} diff --git a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java b/test/lspSchedulingTests/CollectionLSPSchedulingTest.java deleted file mode 100644 index 5dda09ffd44..00000000000 --- a/test/lspSchedulingTests/CollectionLSPSchedulingTest.java +++ /dev/null @@ -1,254 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierPlanXmlWriterV2; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.Carriers; -import org.matsim.contrib.freight.carrier.ScheduledTour; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.Tour; -import org.matsim.contrib.freight.carrier.Tour.Leg; -import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; -import org.matsim.contrib.freight.carrier.Tour.TourElement; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class CollectionLSPSchedulingTest { - - private Network network; - private LSP collectionLSP; - private Carrier carrier; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - - @Before - public void initialize() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = adapterBuilder.build(); - - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - collectionElement = collectionElementBuilder.build(); - - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - collectionLSP = collectionLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id toLinkId = collectionLinkId; - - - for(int i = 1; i < 2; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - collectionLSP.assignShipmentToLSP(shipment); - } - collectionLSP.scheduleSoultions(); - - } - - @Test - public void testCollectionLSPScheduling() { - - for(LSPShipment shipment : collectionLSP.getShipments()) { - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - } - - for(LSPShipment shipment : collectionLSP.getShipments()) { - assertTrue(shipment.getSchedule().getPlanElements().size() == 3); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - - assertTrue(shipment.getEventHandlers().size() == 2); - ArrayList eventHandlers = new ArrayList(shipment.getEventHandlers()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(serviceHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(serviceHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); - } - - for(LogisticsSolution solution : collectionLSP.getSelectedPlan().getSolutions()) { - assertTrue(solution.getShipments().size() == 1); - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - - } -} diff --git a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java b/test/lspSchedulingTests/CompleteLSPSchedulingTest.java deleted file mode 100644 index 89584525b6d..00000000000 --- a/test/lspSchedulingTests/CompleteLSPSchedulingTest.java +++ /dev/null @@ -1,647 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import java.util.Map.Entry; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.DistributionServiceEventHandler; -import lsp.usecase.DistributionStartEventHandler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.MainRunEndEventHandler; -import lsp.usecase.MainRunStartEventHandler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class CompleteLSPSchedulingTest { - - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private Resource mainRunAdapter; - private LogisticsSolutionElement mainRunElement; - private Resource secondReloadingPointAdapter; - private LogisticsSolutionElement secondReloadElement; - private Resource distributionAdapter; - private LogisticsSolutionElement distributionElement; - private Id toLinkId; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - toLinkId = Id.createLinkId("(14 2) (14 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(fromLinkId); - mainRunAdapterBuilder.setToLinkId(toLinkId); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - mainRunElement = mainRunBuilder.build(); - - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - secondReloadElement = secondReloadingElementBuilder.build(); - - DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); - Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); - Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); - dsitributionVehicleTypeBuilder.setCapacity(10); - dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - dsitributionVehicleTypeBuilder.setFixCost(49); - dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); - - Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); - CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); - distributionCarrierVehicle.setVehicleType(distributionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); - capabilitiesBuilder.addVehicle(distributionCarrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); - Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); - distributionCarrier.setCarrierCapabilities(distributionCapabilities); - - - Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); - DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); - distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - distributionAdapterBuilder.setCarrier(distributionCarrier); - distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - distributionAdapter = distributionAdapterBuilder.build(); - - Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); - distributionBuilder.setResource(distributionAdapter); - distributionElement = distributionBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - secondReloadElement.setNextElement(distributionElement); - distributionElement.setPreviousElement(secondReloadElement); - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolutionBuilder.addSolutionElement(secondReloadElement); - completeSolutionBuilder.addSolutionElement(distributionElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - resourcesList.add(distributionAdapter); - - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Random rand = new Random(1); - for(int i = 1; i < 2; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testCompletedLSPScheduling() { - - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime()); - } - System.out.println(); - } - - ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); - ArrayList resources = new ArrayList<>(lsp.getResources()); - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 11); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - - assertTrue(planElements.get(10).getElementType() == "UNLOAD"); - assertTrue(planElements.get(10).getEndTime() >= (0)); - assertTrue(planElements.get(10).getEndTime() <= (24*3600)); - assertTrue(planElements.get(10).getStartTime() <= planElements.get(10).getEndTime()); - assertTrue(planElements.get(10).getStartTime() >= (0)); - assertTrue(planElements.get(10).getStartTime() <= (24*3600)); - assertTrue(planElements.get(10).getResourceId() == distributionAdapter.getId()); - assertTrue(planElements.get(10).getSolutionElement() == distributionElement); - - assertTrue(planElements.get(10).getStartTime() == planElements.get(9).getEndTime()); - - assertTrue(planElements.get(9).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(9).getEndTime() >= (0)); - assertTrue(planElements.get(9).getEndTime() <= (24*3600)); - assertTrue(planElements.get(9).getStartTime() <= planElements.get(9).getEndTime()); - assertTrue(planElements.get(9).getStartTime() >= (0)); - assertTrue(planElements.get(9).getStartTime() <= (24*3600)); - assertTrue(planElements.get(9).getResourceId() == distributionAdapter.getId()); - assertTrue(planElements.get(9).getSolutionElement() == distributionElement); - - assertTrue(planElements.get(9).getStartTime() == planElements.get(8).getEndTime()); - - assertTrue(planElements.get(8).getElementType() == "LOAD"); - assertTrue(planElements.get(8).getEndTime() >= (0)); - assertTrue(planElements.get(8).getEndTime() <= (24*3600)); - assertTrue(planElements.get(8).getStartTime() <= planElements.get(8).getEndTime()); - assertTrue(planElements.get(8).getStartTime() >= (0)); - assertTrue(planElements.get(8).getStartTime() <= (24*3600)); - assertTrue(planElements.get(8).getResourceId() == distributionAdapter.getId()); - assertTrue(planElements.get(8).getSolutionElement() == distributionElement); - - assertTrue(planElements.get(8).getStartTime() >= (planElements.get(7).getEndTime()/ 1.0001) + 300); - - assertTrue(planElements.get(7).getElementType() == "HANDLE"); - assertTrue(planElements.get(7).getEndTime() >= (0)); - assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); - assertTrue(planElements.get(7).getStartTime() >= (0)); - assertTrue(planElements.get(7).getStartTime() <= (24*3600)); - assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); - assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - - assertTrue(planElements.get(7).getStartTime() == (planElements.get(6).getEndTime() +300)); - - assertTrue(planElements.get(6).getElementType() == "UNLOAD"); - assertTrue(planElements.get(6).getEndTime() >= (0)); - assertTrue(planElements.get(6).getEndTime() <= (24*3600)); - assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); - assertTrue(planElements.get(6).getStartTime() >= (0)); - assertTrue(planElements.get(6).getStartTime() <= (24*3600)); - assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); - - assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(5).getEndTime() >= (0)); - assertTrue(planElements.get(5).getEndTime() <= (24*3600)); - assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); - assertTrue(planElements.get(5).getStartTime() >= (0)); - assertTrue(planElements.get(5).getStartTime() <= (24*3600)); - assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); - - assertTrue(planElements.get(4).getElementType() == "LOAD"); - assertTrue(planElements.get(4).getEndTime() >= (0)); - assertTrue(planElements.get(4).getEndTime() <= (24*3600)); - assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); - assertTrue(planElements.get(4).getStartTime() >= (0)); - assertTrue(planElements.get(4).getStartTime() <= (24*3600)); - assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(4).getStartTime() >= (planElements.get(3).getEndTime() / (1.0001)) + 300); - - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); - eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == toLinkId); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 6); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == solutionElements.get(0)); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(serviceHandler.getElement() == solutionElements.get(0)); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); - MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); - assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunStartHandler.getLspShipment() == shipment); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); - MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); - assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunEndHandler.getLspShipment() == shipment); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(4) instanceof DistributionStartEventHandler); - DistributionStartEventHandler distributionStartHandler = (DistributionStartEventHandler) eventHandlers.get(4); - assertTrue(distributionStartHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); - assertTrue(distributionStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(distributionStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(distributionStartHandler.getElement() == planElements.get(8).getSolutionElement()); - assertTrue(distributionStartHandler.getElement() == planElements.get(9).getSolutionElement()); - assertTrue(distributionStartHandler.getElement() == planElements.get(10).getSolutionElement()); - assertTrue(distributionStartHandler.getElement() == solutionElements.get(4)); - assertTrue(distributionStartHandler.getLspShipment() == shipment); - assertTrue(distributionStartHandler.getResource().getId() == planElements.get(8).getResourceId()); - assertTrue(distributionStartHandler.getResource().getId() == planElements.get(9).getResourceId()); - assertTrue(distributionStartHandler.getResource().getId() == planElements.get(10).getResourceId()); - assertTrue(distributionStartHandler.getResource().getId() == resources.get(4).getId()); - - assertTrue(eventHandlers.get(5) instanceof DistributionServiceEventHandler); - DistributionServiceEventHandler distributionServiceHandler = (DistributionServiceEventHandler) eventHandlers.get(5); - assertTrue(distributionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); - assertTrue(distributionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(distributionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(8).getSolutionElement()); - assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(9).getSolutionElement()); - assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(10).getSolutionElement()); - assertTrue(distributionServiceHandler.getSolutionElement() == solutionElements.get(4)); - assertTrue(distributionServiceHandler.getLspShipment() == shipment); - assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(8).getResourceId()); - assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(9).getResourceId()); - assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(10).getResourceId()); - assertTrue(distributionServiceHandler.getResource().getId() == resources.get(4).getId()); - - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - assertTrue(solution.getShipments().size() == 1); - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - - } - -} diff --git a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java deleted file mode 100644 index 2818a7fc9aa..00000000000 --- a/test/lspSchedulingTests/FirstReloadLSPSchedulingTest.java +++ /dev/null @@ -1,346 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.usecase.ReloadingPointEventHandler.ReloadingPointEventHandlerPair; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class FirstReloadLSPSchedulingTest { - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private LogisticsSolutionElement collectionElement; - private Resource collectionAdapter; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - - for(int i = 1; i < 2; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - //Random random = new Random(1); - int capacityDemand = new Random().nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testFirstReloadLSPScheduling() { - - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - } - - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 4); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - //This asserts that the shipments waiting for handling have been handled and the queues have been cleared - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 2); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == lsp.getResources().iterator().next().getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(serviceHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(serviceHandler.getResourceId() == lsp.getResources().iterator().next().getId()); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - assertTrue(solution.getShipments().size() == 1); - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - - } -} diff --git a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MainRunLSPSchedulingTest.java deleted file mode 100644 index 33fc15398cf..00000000000 --- a/test/lspSchedulingTests/MainRunLSPSchedulingTest.java +++ /dev/null @@ -1,469 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Random; - - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.MainRunEndEventHandler; -import lsp.usecase.MainRunStartEventHandler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class MainRunLSPSchedulingTest { - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private Resource mainRunAdapter; - private LogisticsSolutionElement mainRunElement; - private Id collectionLinkId; - private Id firstReloadingLinkId; - private Id fromLinkId; - private Id toLinkId; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - fromLinkId = Id.createLinkId("(4 2) (4 3)"); - toLinkId = Id.createLinkId("(14 2) (14 3)"); - - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(fromLinkId); - mainRunAdapterBuilder.setToLinkId(toLinkId); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - mainRunElement = mainRunBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - - for(int i = 1; i < 2; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - //Random random = new Random(1); - int capacityDemand = new Random().nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testMainRunLSPScheduling() { - - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - } - - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 7); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - assertTrue(planElements.get(6).getElementType() == "UNLOAD"); - assertTrue(planElements.get(6).getEndTime() >= (0)); - assertTrue(planElements.get(6).getEndTime() <= (24*3600)); - assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); - assertTrue(planElements.get(6).getStartTime() >= (0)); - assertTrue(planElements.get(6).getStartTime() <= (24*3600)); - assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); - - assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(5).getEndTime() >= (0)); - assertTrue(planElements.get(5).getEndTime() <= (24*3600)); - assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); - assertTrue(planElements.get(5).getStartTime() >= (0)); - assertTrue(planElements.get(5).getStartTime() <= (24*3600)); - assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); - - assertTrue(planElements.get(4).getElementType() == "LOAD"); - assertTrue(planElements.get(4).getEndTime() >= (0)); - assertTrue(planElements.get(4).getEndTime() <= (24*3600)); - assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); - assertTrue(planElements.get(4).getStartTime() >= (0)); - assertTrue(planElements.get(4).getStartTime() <= (24*3600)); - assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(4).getStartTime() >= ( planElements.get(3).getEndTime() / (1.0001)) + 300); - - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 4); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); - ArrayList resources = new ArrayList<>(lsp.getResources()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == solutionElements.get(0)); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(serviceHandler.getElement() == solutionElements.get(0)); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); - MainRunStartEventHandler startHandler = (MainRunStartEventHandler) eventHandlers.get(2); - assertTrue(startHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(startHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(startHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(startHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(startHandler.getLspShipment() == shipment); - assertTrue(startHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(startHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(startHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(startHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); - MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); - assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunEndHandler.getLspShipment() == shipment); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - assertTrue(solution.getShipments().size() == 1); - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - - } -} diff --git a/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java deleted file mode 100644 index 4d2e7a6b1e4..00000000000 --- a/test/lspSchedulingTests/MultipleShipmentsCollectionLSPSchedulingTest.java +++ /dev/null @@ -1,253 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierPlanXmlWriterV2; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.Carriers; -import org.matsim.contrib.freight.carrier.ScheduledTour; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.Tour; -import org.matsim.contrib.freight.carrier.Tour.Leg; -import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; -import org.matsim.contrib.freight.carrier.Tour.TourElement; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class MultipleShipmentsCollectionLSPSchedulingTest { - - private Network network; - private LSP collectionLSP; - private Carrier carrier; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - - @Before - public void initialize() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = adapterBuilder.build(); - - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - collectionElement = collectionElementBuilder.build(); - - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - collectionLSP = collectionLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id toLinkId = collectionLinkId; - - - for(int i = 1; i < 100; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - collectionLSP.assignShipmentToLSP(shipment); - } - collectionLSP.scheduleSoultions(); - - } - - @Test - public void testCollectionLSPScheduling() { - - for(LSPShipment shipment : collectionLSP.getShipments()) { - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - } - - for(LSPShipment shipment : collectionLSP.getShipments()) { - assertTrue(shipment.getSchedule().getPlanElements().size() == 3); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - - assertTrue(shipment.getEventHandlers().size() == 2); - ArrayList eventHandlers = new ArrayList(shipment.getEventHandlers()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(serviceHandler.getElement() == collectionLSP.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(serviceHandler.getResourceId() == collectionLSP.getResources().iterator().next().getId()); - } - - for(LogisticsSolution solution : collectionLSP.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - } -} diff --git a/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java deleted file mode 100644 index 3d8af0415ab..00000000000 --- a/test/lspSchedulingTests/MultipleShipmentsCompleteLSPSchedulingTest.java +++ /dev/null @@ -1,646 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import java.util.Map.Entry; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.DistributionServiceEventHandler; -import lsp.usecase.DistributionStartEventHandler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.MainRunEndEventHandler; -import lsp.usecase.MainRunStartEventHandler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class MultipleShipmentsCompleteLSPSchedulingTest { - - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private Resource mainRunAdapter; - private LogisticsSolutionElement mainRunElement; - private Resource secondReloadingPointAdapter; - private LogisticsSolutionElement secondReloadElement; - private Resource distributionAdapter; - private LogisticsSolutionElement distributionElement; - private Id toLinkId; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - toLinkId = Id.createLinkId("(14 2) (14 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(fromLinkId); - mainRunAdapterBuilder.setToLinkId(toLinkId); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - mainRunElement = mainRunBuilder.build(); - - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - secondReloadElement = secondReloadingElementBuilder.build(); - - DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); - Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); - Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); - dsitributionVehicleTypeBuilder.setCapacity(10); - dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - dsitributionVehicleTypeBuilder.setFixCost(49); - dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); - - Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); - CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); - distributionCarrierVehicle.setVehicleType(distributionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); - capabilitiesBuilder.addVehicle(distributionCarrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); - Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); - distributionCarrier.setCarrierCapabilities(distributionCapabilities); - - - Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); - DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); - distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - distributionAdapterBuilder.setCarrier(distributionCarrier); - distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - distributionAdapter = distributionAdapterBuilder.build(); - - Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); - distributionBuilder.setResource(distributionAdapter); - distributionElement = distributionBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - secondReloadElement.setNextElement(distributionElement); - distributionElement.setPreviousElement(secondReloadElement); - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolutionBuilder.addSolutionElement(secondReloadElement); - completeSolutionBuilder.addSolutionElement(distributionElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - resourcesList.add(distributionAdapter); - - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Random rand = new Random(1); - for(int i = 1; i < 100; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testCompletedLSPScheduling() { - - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime()); - } - System.out.println(); - } - - ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); - ArrayList resources = new ArrayList<>(lsp.getResources()); - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 11); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - - assertTrue(planElements.get(10).getElementType() == "UNLOAD"); - assertTrue(planElements.get(10).getEndTime() >= (0)); - assertTrue(planElements.get(10).getEndTime() <= (24*3600)); - assertTrue(planElements.get(10).getStartTime() <= planElements.get(10).getEndTime()); - assertTrue(planElements.get(10).getStartTime() >= (0)); - assertTrue(planElements.get(10).getStartTime() <= (24*3600)); - assertTrue(planElements.get(10).getResourceId() == distributionAdapter.getId()); - assertTrue(planElements.get(10).getSolutionElement() == distributionElement); - - assertTrue(planElements.get(10).getStartTime() == planElements.get(9).getEndTime()); - - assertTrue(planElements.get(9).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(9).getEndTime() >= (0)); - assertTrue(planElements.get(9).getEndTime() <= (24*3600)); - assertTrue(planElements.get(9).getStartTime() <= planElements.get(9).getEndTime()); - assertTrue(planElements.get(9).getStartTime() >= (0)); - assertTrue(planElements.get(9).getStartTime() <= (24*3600)); - assertTrue(planElements.get(9).getResourceId() == distributionAdapter.getId()); - assertTrue(planElements.get(9).getSolutionElement() == distributionElement); - - assertTrue(planElements.get(9).getStartTime() == planElements.get(8).getEndTime()); - - assertTrue(planElements.get(8).getElementType() == "LOAD"); - assertTrue(planElements.get(8).getEndTime() >= (0)); - assertTrue(planElements.get(8).getEndTime() <= (24*3600)); - assertTrue(planElements.get(8).getStartTime() <= planElements.get(8).getEndTime()); - assertTrue(planElements.get(8).getStartTime() >= (0)); - assertTrue(planElements.get(8).getStartTime() <= (24*3600)); - assertTrue(planElements.get(8).getResourceId() == distributionAdapter.getId()); - assertTrue(planElements.get(8).getSolutionElement() == distributionElement); - - assertTrue(planElements.get(8).getStartTime() >= planElements.get(7).getEndTime()/ 1.0001 + 300); - - assertTrue(planElements.get(7).getElementType() == "HANDLE"); - assertTrue(planElements.get(7).getEndTime() >= (0)); - assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); - assertTrue(planElements.get(7).getStartTime() >= (0)); - assertTrue(planElements.get(7).getStartTime() <= (24*3600)); - assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); - assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - - assertTrue(planElements.get(7).getStartTime() == planElements.get(6).getEndTime() + 300); - - assertTrue(planElements.get(6).getElementType() == "UNLOAD"); - assertTrue(planElements.get(6).getEndTime() >= (0)); - assertTrue(planElements.get(6).getEndTime() <= (24*3600)); - assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); - assertTrue(planElements.get(6).getStartTime() >= (0)); - assertTrue(planElements.get(6).getStartTime() <= (24*3600)); - assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); - - assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(5).getEndTime() >= (0)); - assertTrue(planElements.get(5).getEndTime() <= (24*3600)); - assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); - assertTrue(planElements.get(5).getStartTime() >= (0)); - assertTrue(planElements.get(5).getStartTime() <= (24*3600)); - assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); - - assertTrue(planElements.get(4).getElementType() == "LOAD"); - assertTrue(planElements.get(4).getEndTime() >= (0)); - assertTrue(planElements.get(4).getEndTime() <= (24*3600)); - assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); - assertTrue(planElements.get(4).getStartTime() >= (0)); - assertTrue(planElements.get(4).getStartTime() <= (24*3600)); - assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001) + 300); - - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime() + 300); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); - eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == toLinkId); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 6); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == solutionElements.get(0)); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(serviceHandler.getElement() == solutionElements.get(0)); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); - MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); - assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunStartHandler.getLspShipment() == shipment); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); - MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); - assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunEndHandler.getLspShipment() == shipment); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(4) instanceof DistributionStartEventHandler); - DistributionStartEventHandler distributionStartHandler = (DistributionStartEventHandler) eventHandlers.get(4); - assertTrue(distributionStartHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); - assertTrue(distributionStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(distributionStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(distributionStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(distributionStartHandler.getElement() == planElements.get(8).getSolutionElement()); - assertTrue(distributionStartHandler.getElement() == planElements.get(9).getSolutionElement()); - assertTrue(distributionStartHandler.getElement() == planElements.get(10).getSolutionElement()); - assertTrue(distributionStartHandler.getElement() == solutionElements.get(4)); - assertTrue(distributionStartHandler.getLspShipment() == shipment); - assertTrue(distributionStartHandler.getResource().getId() == planElements.get(8).getResourceId()); - assertTrue(distributionStartHandler.getResource().getId() == planElements.get(9).getResourceId()); - assertTrue(distributionStartHandler.getResource().getId() == planElements.get(10).getResourceId()); - assertTrue(distributionStartHandler.getResource().getId() == resources.get(4).getId()); - - assertTrue(eventHandlers.get(5) instanceof DistributionServiceEventHandler); - DistributionServiceEventHandler distributionServiceHandler = (DistributionServiceEventHandler) eventHandlers.get(5); - assertTrue(distributionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getToLinkId()); - assertTrue(distributionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(distributionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(8).getSolutionElement()); - assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(9).getSolutionElement()); - assertTrue(distributionServiceHandler.getSolutionElement() == planElements.get(10).getSolutionElement()); - assertTrue(distributionServiceHandler.getSolutionElement() == solutionElements.get(4)); - assertTrue(distributionServiceHandler.getLspShipment() == shipment); - assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(8).getResourceId()); - assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(9).getResourceId()); - assertTrue(distributionServiceHandler.getResource().getId() == planElements.get(10).getResourceId()); - assertTrue(distributionServiceHandler.getResource().getId() == resources.get(4).getId()); - - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - - } - -} diff --git a/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java deleted file mode 100644 index ab388f65868..00000000000 --- a/test/lspSchedulingTests/MultipleShipmentsFirstReloadLSPSchedulingTest.java +++ /dev/null @@ -1,344 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.usecase.ReloadingPointEventHandler.ReloadingPointEventHandlerPair; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class MultipleShipmentsFirstReloadLSPSchedulingTest { - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private LogisticsSolutionElement collectionElement; - private Resource collectionAdapter; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - - for(int i = 1; i < 100; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - //Random random = new Random(1); - int capacityDemand = new Random().nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testFirstReloadLSPScheduling() { - - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - } - - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 4); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == planElements.get(2).getEndTime() + 300); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - //This asserts that the shipments waiting for handling have been handled and the queues have been cleared - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 2); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == lsp.getResources().iterator().next().getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(serviceHandler.getElement() == lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements().iterator().next()); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(serviceHandler.getResourceId() == lsp.getResources().iterator().next().getId()); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - } -} diff --git a/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java deleted file mode 100644 index a63433dff0c..00000000000 --- a/test/lspSchedulingTests/MultipleShipmentsMainRunLSPSchedulingTest.java +++ /dev/null @@ -1,467 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Random; - - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.MainRunEndEventHandler; -import lsp.usecase.MainRunStartEventHandler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class MultipleShipmentsMainRunLSPSchedulingTest { - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private Resource mainRunAdapter; - private LogisticsSolutionElement mainRunElement; - private Id collectionLinkId; - private Id firstReloadingLinkId; - private Id fromLinkId; - private Id toLinkId; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - fromLinkId = Id.createLinkId("(4 2) (4 3)"); - toLinkId = Id.createLinkId("(14 2) (14 3)"); - - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(fromLinkId); - mainRunAdapterBuilder.setToLinkId(toLinkId); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - mainRunElement = mainRunBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - - for(int i = 1; i < 100; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - //Random random = new Random(1); - int capacityDemand = new Random().nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testMainRunLSPScheduling() { - - /*for(LSPShipment shipment : lsp.getShipments()) { - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - - System.out.println(); - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - }*/ - - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 7); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - assertTrue(planElements.get(6).getElementType() == "UNLOAD"); - assertTrue(planElements.get(6).getEndTime() >= (0)); - assertTrue(planElements.get(6).getEndTime() <= (24*3600)); - assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); - assertTrue(planElements.get(6).getStartTime() >= (0)); - assertTrue(planElements.get(6).getStartTime() <= (24*3600)); - assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); - - assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(5).getEndTime() >= (0)); - assertTrue(planElements.get(5).getEndTime() <= (24*3600)); - assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); - assertTrue(planElements.get(5).getStartTime() >= (0)); - assertTrue(planElements.get(5).getStartTime() <= (24*3600)); - assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); - - assertTrue(planElements.get(4).getElementType() == "LOAD"); - assertTrue(planElements.get(4).getEndTime() >= (0)); - assertTrue(planElements.get(4).getEndTime() <= (24*3600)); - assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); - assertTrue(planElements.get(4).getStartTime() >= (0)); - assertTrue(planElements.get(4).getStartTime() <= (24*3600)); - assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(4).getStartTime() >= planElements.get(3).getEndTime() / (1.0001) + 300); - - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() +300)); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 4); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); - ArrayList resources = new ArrayList<>(lsp.getResources()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler endHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(endHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(endHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(endHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(endHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(endHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(endHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(endHandler.getElement() == solutionElements.get(0)); - assertTrue(endHandler.getLspShipment() == shipment); - assertTrue(endHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(endHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(endHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler serviceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(serviceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(serviceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(serviceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(serviceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(serviceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(serviceHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(serviceHandler.getElement() == solutionElements.get(0)); - assertTrue(serviceHandler.getLspShipment() == shipment); - assertTrue(serviceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(serviceHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(serviceHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); - MainRunStartEventHandler startHandler = (MainRunStartEventHandler) eventHandlers.get(2); - assertTrue(startHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(startHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(startHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(startHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(startHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(startHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(startHandler.getLspShipment() == shipment); - assertTrue(startHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(startHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(startHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(startHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); - MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); - assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunEndHandler.getLspShipment() == shipment); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - } -} diff --git a/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java deleted file mode 100644 index fdd50ec1a97..00000000000 --- a/test/lspSchedulingTests/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ /dev/null @@ -1,530 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import java.util.Map.Entry; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.MainRunEndEventHandler; -import lsp.usecase.MainRunStartEventHandler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class MultipleShipmentsSecondReloadLSPSchedulingTest { - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private Resource mainRunAdapter; - private LogisticsSolutionElement mainRunElement; - private Resource secondReloadingPointAdapter; - private LogisticsSolutionElement secondReloadElement; - private Id toLinkId; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - toLinkId = Id.createLinkId("(14 2) (14 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(fromLinkId); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId(toLinkId)); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - mainRunElement = mainRunBuilder.build(); - - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - secondReloadElement = secondReloadingElementBuilder.build(); - - - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolutionBuilder.addSolutionElement(secondReloadElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - - for(int i = 1; i < 100; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testSecondReloadLSPScheduling() { - - /*for(LSPShipment shipment : lsp.getShipments()) { - ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); - } - System.out.println(); - }*/ - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 8); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - - assertTrue(planElements.get(7).getElementType() == "HANDLE"); - assertTrue(planElements.get(7).getEndTime() >= (0)); - assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); - assertTrue(planElements.get(7).getStartTime() >= (0)); - assertTrue(planElements.get(7).getStartTime() <= (24*3600)); - assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); - assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - - assertTrue(planElements.get(7).getStartTime() == (planElements.get(6).getEndTime() + 300)); - - assertTrue(planElements.get(6).getElementType() == "UNLOAD"); - assertTrue(planElements.get(6).getEndTime() >= (0)); - assertTrue(planElements.get(6).getEndTime() <= (24*3600)); - assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); - assertTrue(planElements.get(6).getStartTime() >= (0)); - assertTrue(planElements.get(6).getStartTime() <= (24*3600)); - assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); - - assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(5).getEndTime() >= (0)); - assertTrue(planElements.get(5).getEndTime() <= (24*3600)); - assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); - assertTrue(planElements.get(5).getStartTime() >= (0)); - assertTrue(planElements.get(5).getStartTime() <= (24*3600)); - assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); - - assertTrue(planElements.get(4).getElementType() == "LOAD"); - assertTrue(planElements.get(4).getEndTime() >= (0)); - assertTrue(planElements.get(4).getEndTime() <= (24*3600)); - assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); - assertTrue(planElements.get(4).getStartTime() >= (0)); - assertTrue(planElements.get(4).getStartTime() <= (24*3600)); - assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(4).getStartTime() >= (planElements.get(3).getEndTime()/ (1.0001)) + 300); - - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); - eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == toLinkId); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 4); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); - ArrayList resources = new ArrayList<>(lsp.getResources()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler collectionEndHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(collectionEndHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(collectionEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(collectionEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(collectionEndHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(collectionEndHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(collectionEndHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(collectionEndHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(collectionEndHandler.getElement() == solutionElements.get(0)); - assertTrue(collectionEndHandler.getLspShipment() == shipment); - assertTrue(collectionEndHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(collectionEndHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(collectionEndHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(collectionEndHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler collectionServiceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(collectionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(collectionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(collectionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(collectionServiceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(collectionServiceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(collectionServiceHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(collectionServiceHandler.getElement() == solutionElements.get(0)); - assertTrue(collectionServiceHandler.getLspShipment() == shipment); - assertTrue(collectionServiceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(collectionServiceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(collectionServiceHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(collectionServiceHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); - MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); - assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunStartHandler.getLspShipment() == shipment); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); - MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); - assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunEndHandler.getLspShipment() == shipment); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - } -} diff --git a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java b/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java deleted file mode 100644 index 63e8e8c83fd..00000000000 --- a/test/lspSchedulingTests/SecondReloadLSPSchedulingTest.java +++ /dev/null @@ -1,530 +0,0 @@ -package lspSchedulingTests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import java.util.Map.Entry; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.MainRunEndEventHandler; -import lsp.usecase.MainRunStartEventHandler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointEventHandler; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; - -public class SecondReloadLSPSchedulingTest { - private Network network; - private LogisticsSolution completeSolution; - private ShipmentAssigner assigner; - private LSPPlanImpl completePlan; - private SolutionScheduler simpleScheduler; - private LSP lsp; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private Resource firstReloadingPointAdapter; - private LogisticsSolutionElement firstReloadElement; - private Resource mainRunAdapter; - private LogisticsSolutionElement mainRunElement; - private Resource secondReloadingPointAdapter; - private LogisticsSolutionElement secondReloadElement; - private Id toLinkId; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); - collectionVehicleTypeBuilder.setCapacity(10); - collectionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - collectionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - collectionVehicleTypeBuilder.setFixCost(49); - collectionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = collectionVehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionCarrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionBuilder.setResource(collectionAdapter); - collectionElement = collectionBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - toLinkId = Id.createLinkId("(14 2) (14 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(fromLinkId); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId(toLinkId)); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - mainRunElement = mainRunBuilder.build(); - - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - secondReloadElement = secondReloadingElementBuilder.build(); - - - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - - - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolutionBuilder.addSolutionElement(secondReloadElement); - completeSolution = completeSolutionBuilder.build(); - - assigner = new DeterministicShipmentAssigner(); - completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - - simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - simpleScheduler.setBufferTime(300); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = completeLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - - for(int i = 1; i < 2; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = new Random().nextInt(10); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - lsp.assignShipmentToLSP(shipment); - } - lsp.scheduleSoultions(); - - } - - @Test - public void testSecondReloadLSPScheduling() { - - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); - System.out.println(); - for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); - } - System.out.println(); - } - - for(LSPShipment shipment : lsp.getShipments()){ - assertTrue(shipment.getSchedule().getPlanElements().size() == 8); - ArrayList planElements = new ArrayList<>(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - - assertTrue(planElements.get(7).getElementType() == "HANDLE"); - assertTrue(planElements.get(7).getEndTime() >= (0)); - assertTrue(planElements.get(7).getEndTime() <= (24*3600)); - assertTrue(planElements.get(7).getStartTime() <= planElements.get(7).getEndTime()); - assertTrue(planElements.get(7).getStartTime() >= (0)); - assertTrue(planElements.get(7).getStartTime() <= (24*3600)); - assertTrue(planElements.get(7).getResourceId() == secondReloadingPointAdapter.getId()); - assertTrue(planElements.get(7).getSolutionElement() == secondReloadElement); - - assertTrue(planElements.get(7).getStartTime() == (planElements.get(6).getEndTime() + 300)); - - assertTrue(planElements.get(6).getElementType() == "UNLOAD"); - assertTrue(planElements.get(6).getEndTime() >= (0)); - assertTrue(planElements.get(6).getEndTime() <= (24*3600)); - assertTrue(planElements.get(6).getStartTime() <= planElements.get(6).getEndTime()); - assertTrue(planElements.get(6).getStartTime() >= (0)); - assertTrue(planElements.get(6).getStartTime() <= (24*3600)); - assertTrue(planElements.get(6).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(6).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(6).getStartTime() == planElements.get(5).getEndTime()); - - assertTrue(planElements.get(5).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(5).getEndTime() >= (0)); - assertTrue(planElements.get(5).getEndTime() <= (24*3600)); - assertTrue(planElements.get(5).getStartTime() <= planElements.get(5).getEndTime()); - assertTrue(planElements.get(5).getStartTime() >= (0)); - assertTrue(planElements.get(5).getStartTime() <= (24*3600)); - assertTrue(planElements.get(5).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(5).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(5).getStartTime() == planElements.get(4).getEndTime()); - - assertTrue(planElements.get(4).getElementType() == "LOAD"); - assertTrue(planElements.get(4).getEndTime() >= (0)); - assertTrue(planElements.get(4).getEndTime() <= (24*3600)); - assertTrue(planElements.get(4).getStartTime() <= planElements.get(4).getEndTime()); - assertTrue(planElements.get(4).getStartTime() >= (0)); - assertTrue(planElements.get(4).getStartTime() <= (24*3600)); - assertTrue(planElements.get(4).getResourceId() == mainRunAdapter.getId()); - assertTrue(planElements.get(4).getSolutionElement() == mainRunElement); - - assertTrue(planElements.get(4).getStartTime() >= (planElements.get(3).getEndTime() / (1.0001)) + 300); - - assertTrue(planElements.get(3).getElementType() == "HANDLE"); - assertTrue(planElements.get(3).getEndTime() >= (0)); - assertTrue(planElements.get(3).getEndTime() <= (24*3600)); - assertTrue(planElements.get(3).getStartTime() <= planElements.get(3).getEndTime()); - assertTrue(planElements.get(3).getStartTime() >= (0)); - assertTrue(planElements.get(3).getStartTime() <= (24*3600)); - assertTrue(planElements.get(3).getResourceId() == firstReloadingPointAdapter.getId()); - assertTrue(planElements.get(3).getSolutionElement() == firstReloadElement); - - assertTrue(planElements.get(3).getStartTime() == (planElements.get(2).getEndTime() + 300)); - - assertTrue(planElements.get(2).getElementType() == "UNLOAD"); - assertTrue(planElements.get(2).getEndTime() >= (0)); - assertTrue(planElements.get(2).getEndTime() <= (24*3600)); - assertTrue(planElements.get(2).getStartTime() <= planElements.get(2).getEndTime()); - assertTrue(planElements.get(2).getStartTime() >= (0)); - assertTrue(planElements.get(2).getStartTime() <= (24*3600)); - assertTrue(planElements.get(2).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(2).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(2).getStartTime() == planElements.get(1).getEndTime()); - - assertTrue(planElements.get(1).getElementType() == "TRANSPORT"); - assertTrue(planElements.get(1).getEndTime() >= (0)); - assertTrue(planElements.get(1).getEndTime() <= (24*3600)); - assertTrue(planElements.get(1).getStartTime() <= planElements.get(1).getEndTime()); - assertTrue(planElements.get(1).getStartTime() >= (0)); - assertTrue(planElements.get(1).getStartTime() <= (24*3600)); - assertTrue(planElements.get(1).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(1).getSolutionElement() == collectionElement); - - assertTrue(planElements.get(1).getStartTime() == planElements.get(0).getEndTime()); - - assertTrue(planElements.get(0).getElementType() == "LOAD"); - assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertTrue(planElements.get(0).getResourceId() == collectionAdapter.getId()); - assertTrue(planElements.get(0).getSolutionElement() == collectionElement); - } - - assertTrue(firstReloadingPointAdapter.getEventHandlers().size() ==1); - ArrayList eventHandlers = new ArrayList(firstReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - ReloadingPointEventHandler reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - assertTrue(secondReloadingPointAdapter.getEventHandlers().size() ==1); - eventHandlers = new ArrayList(secondReloadingPointAdapter.getEventHandlers()); - assertTrue(eventHandlers.iterator().next() instanceof ReloadingPointEventHandler); - reloadEventHandler = (ReloadingPointEventHandler) eventHandlers.iterator().next(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while(iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LSPShipment shipment = entry.getValue().shipment; - LogisticsSolutionElement element = entry.getValue().element; - assertTrue(service.getLocationLinkId() == toLinkId); - assertTrue(service.getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(service.getServiceDuration() == shipment.getServiceTime()); - boolean handledByReloadingPoint = false; - for(LogisticsSolutionElement clientElement : reloadEventHandler.getReloadingPoint().getClientElements()) { - if(clientElement == element) { - handledByReloadingPoint = true; - } - } - assertTrue(handledByReloadingPoint); - - assertFalse(element.getOutgoingShipments().getShipments().contains(shipment)); - assertFalse(element.getIncomingShipments().getShipments().contains(shipment)); - } - - for(LSPShipment shipment : lsp.getShipments()) { - assertTrue(shipment.getEventHandlers().size() == 4); - eventHandlers = new ArrayList(shipment.getEventHandlers()); - ArrayList planElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(planElements, new AbstractShipmentPlanElementComparator()); - ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getSolutions().iterator().next().getSolutionElements()); - ArrayList resources = new ArrayList<>(lsp.getResources()); - - assertTrue(eventHandlers.get(0) instanceof CollectionTourEndEventHandler); - CollectionTourEndEventHandler collectionEndHandler = (CollectionTourEndEventHandler) eventHandlers.get(0); - assertTrue(collectionEndHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(collectionEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(collectionEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(collectionEndHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(collectionEndHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(collectionEndHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(collectionEndHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(collectionEndHandler.getElement() == solutionElements.get(0)); - assertTrue(collectionEndHandler.getLspShipment() == shipment); - assertTrue(collectionEndHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(collectionEndHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(collectionEndHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(collectionEndHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEventHandler); - CollectionServiceEventHandler collectionServiceHandler = (CollectionServiceEventHandler) eventHandlers.get(1); - assertTrue(collectionServiceHandler.getCarrierService().getLocationLinkId() == shipment.getFromLinkId()); - assertTrue(collectionServiceHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(collectionServiceHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow() == shipment.getStartTimeWindow()); - assertTrue(collectionServiceHandler.getElement() == planElements.get(0).getSolutionElement()); - assertTrue(collectionServiceHandler.getElement() == planElements.get(1).getSolutionElement()); - assertTrue(collectionServiceHandler.getElement() == planElements.get(2).getSolutionElement()); - assertTrue(collectionServiceHandler.getElement() == solutionElements.get(0)); - assertTrue(collectionServiceHandler.getLspShipment() == shipment); - assertTrue(collectionServiceHandler.getResourceId() == planElements.get(0).getResourceId()); - assertTrue(collectionServiceHandler.getResourceId() == planElements.get(1).getResourceId()); - assertTrue(collectionServiceHandler.getResourceId() == planElements.get(2).getResourceId()); - assertTrue(collectionServiceHandler.getResourceId() == resources.get(0).getId()); - - assertTrue(eventHandlers.get(2) instanceof MainRunStartEventHandler); - MainRunStartEventHandler mainRunStartHandler = (MainRunStartEventHandler) eventHandlers.get(2); - assertTrue(mainRunStartHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunStartHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunStartHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunStartHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunStartHandler.getLspShipment() == shipment); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunStartHandler.getResource().getId() == resources.get(2).getId()); - - assertTrue(eventHandlers.get(3) instanceof MainRunEndEventHandler); - MainRunEndEventHandler mainRunEndHandler = (MainRunEndEventHandler) eventHandlers.get(3); - assertTrue(mainRunEndHandler.getCarrierService().getLocationLinkId() == toLinkId); - assertTrue(mainRunEndHandler.getCarrierService().getServiceDuration() == shipment.getServiceTime()); - assertTrue(mainRunEndHandler.getCarrierService().getCapacityDemand() == shipment.getCapacityDemand()); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart() == 0); - assertTrue(mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd() == Integer.MAX_VALUE); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(4).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(5).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == planElements.get(6).getSolutionElement()); - assertTrue(mainRunEndHandler.getSolutionElement() == solutionElements.get(2)); - assertTrue(mainRunEndHandler.getLspShipment() == shipment); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(4).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(5).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == planElements.get(6).getResourceId()); - assertTrue(mainRunEndHandler.getResource().getId() == resources.get(2).getId()); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(LogisticsSolutionElement element : solution.getSolutionElements()) { - assertTrue(element.getIncomingShipments().getShipments().isEmpty()); - if(element.getNextElement() != null) { - assertTrue(element.getOutgoingShipments().getShipments().isEmpty()); - } - else { - assertFalse(element.getOutgoingShipments().getShipments().isEmpty()); - } - } - } - } -} diff --git a/test/testLSPWithCostTracker/CollectionServiceHandler.java b/test/testLSPWithCostTracker/CollectionServiceHandler.java deleted file mode 100644 index daba8d97718..00000000000 --- a/test/testLSPWithCostTracker/CollectionServiceHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -package testLSPWithCostTracker; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.contrib.freight.carrier.CarrierService; - -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; -import lsp.events.ServiceEndEvent; -import lsp.events.ServiceEndEventHandler; - - -public class CollectionServiceHandler implements ServiceStartEventHandler, ServiceEndEventHandler{ - - - - private class ServiceTuple { - private CarrierService service; - private double startTime; - - public ServiceTuple(CarrierService service, double startTime) { - this.service = service; - this.startTime = startTime; - } - - public CarrierService getService() { - return service; - } - - public double getStartTime() { - return startTime; - } - - } - - private Collection tuples; - private double totalLoadingCosts; - private int totalNumberOfShipments; - private int totalWeightOfShipments; - - public CollectionServiceHandler() { - this.tuples = new ArrayList(); - } - - @Override - public void reset(int iteration) { - tuples.clear(); - totalNumberOfShipments = 0; - totalWeightOfShipments = 0; - } - - @Override - public void handleEvent(ServiceEndEvent event) { - System.out.println("Service Ends"); - double loadingCosts = 0; - for(ServiceTuple tuple : tuples) { - if(tuple.getService() == event.getService()) { - double serviceDuration = event.getTime() - tuple.getStartTime(); - loadingCosts = serviceDuration * event.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; - totalLoadingCosts = totalLoadingCosts + loadingCosts; - tuples.remove(tuple); - break; - } - } - } - - @Override - public void handleEvent(ServiceStartEvent event) { - totalNumberOfShipments++; - totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); - tuples.add(new ServiceTuple(event.getService(), event.getTime())); - } - - public double getTotalLoadingCosts() { - return totalLoadingCosts; - } - - public int getTotalNumberOfShipments() { - return totalNumberOfShipments; - } - - public int getTotalWeightOfShipments() { - return totalWeightOfShipments; - } - -} diff --git a/test/testLSPWithCostTracker/CollectionTrackerTest.java b/test/testLSPWithCostTracker/CollectionTrackerTest.java deleted file mode 100644 index 6cdffcdcbfc..00000000000 --- a/test/testLSPWithCostTracker/CollectionTrackerTest.java +++ /dev/null @@ -1,328 +0,0 @@ -package testLSPWithCostTracker; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierPlan; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.ScheduledTour; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.Tour; -import org.matsim.contrib.freight.carrier.Tour.End; -import org.matsim.contrib.freight.carrier.Tour.Leg; -import org.matsim.contrib.freight.carrier.Tour.ServiceActivity; -import org.matsim.contrib.freight.carrier.Tour.Start; -import org.matsim.contrib.freight.carrier.Tour.TourElement; -import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; -import org.matsim.contrib.freight.jsprit.NetworkRouter; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.population.routes.NetworkRoute; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.resources.Resource; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.tracking.SimulationTracker; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; - - - -public class CollectionTrackerTest { - - private Network network; - private LSP collectionLSP; - private Carrier carrier; - private Resource collectionAdapter; - private LogisticsSolutionElement collectionElement; - private LogisticsSolution collectionSolution; - private double shareOfFixedCosts; - - @Before - public void initialize() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - this.network = scenario.getNetwork(); - - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Link collectionLink = network.getLinks().get(collectionLinkId); - - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLink.getId()); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - collectionAdapter = adapterBuilder.build(); - - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - collectionElement = collectionElementBuilder.build(); - - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - collectionSolution = collectionSolutionBuilder.build(); - - shareOfFixedCosts = 0.2; - LinearCostTracker tracker = new LinearCostTracker(shareOfFixedCosts); - tracker.getEventHandlers().add(new TourStartHandler()); - tracker.getEventHandlers().add(new CollectionServiceHandler()); - tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); - - collectionSolution.addSimulationTracker(tracker); - - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - collectionLSP = collectionLSPBuilder.build(); - - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id toLinkId = collectionLinkId; - - - for(int i = 1; i < 2; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - collectionLSP.assignShipmentToLSP(shipment); - } - collectionLSP.scheduleSoultions(); - - - - ArrayList lspList = new ArrayList(); - lspList.add(collectionLSP); - LSPs lsps = new LSPs(lspList); - - Controler controler = new Controler(config); - - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); - controler.run(); - } - - @Test - public void testCollectionTracker() { - assertTrue(collectionSolution.getSimulationTrackers().size() == 1); - SimulationTracker tracker = collectionSolution.getSimulationTrackers().iterator().next(); - assertTrue(tracker instanceof LinearCostTracker); - LinearCostTracker linearTracker = (LinearCostTracker) tracker; - double totalScheduledCosts = 0; - double totalTrackedCosts = 0; - double totalScheduledWeight = 0; - double totalTrackedWeight = 0; - int totalNumberOfScheduledShipments = 0; - int totalNumberOfTrackedShipments = 0; - for(EventHandler handler : linearTracker.getEventHandlers()) { - if(handler instanceof TourStartHandler) { - TourStartHandler startHandler = (TourStartHandler) handler; - double scheduledCosts = 0; - for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { - scheduledCosts += scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().fix; - totalScheduledCosts += scheduledCosts; - } - double trackedCosts = startHandler.getVehicleFixedCosts(); - totalTrackedCosts += trackedCosts; - assertEquals(trackedCosts, scheduledCosts, 0.1); - } - if(handler instanceof CollectionServiceHandler) { - CollectionServiceHandler serviceHandler = (CollectionServiceHandler) handler; - totalTrackedWeight = serviceHandler.getTotalWeightOfShipments(); - totalNumberOfTrackedShipments = serviceHandler.getTotalNumberOfShipments(); - double scheduledCosts = 0; - for(ScheduledTour scheduledTour: carrier.getSelectedPlan().getScheduledTours()) { - Tour tour = scheduledTour.getTour(); - for(TourElement element : tour.getTourElements()) { - if(element instanceof ServiceActivity){ - ServiceActivity activity = (ServiceActivity) element; - scheduledCosts += activity.getService().getServiceDuration() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; - totalScheduledCosts += scheduledCosts; - totalScheduledWeight += activity.getService().getCapacityDemand(); - totalNumberOfScheduledShipments++; - } - } - } - double trackedCosts = serviceHandler.getTotalLoadingCosts(); - totalTrackedCosts += trackedCosts; - assertEquals(trackedCosts, scheduledCosts, 0.1); - } - if(handler instanceof DistanceAndTimeHandler) { - DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; - double trackedTimeCosts = distanceHandler.getTimeCosts(); - totalTrackedCosts += trackedTimeCosts; - double scheduledTimeCosts = 0; - for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { - Tour tour = scheduledTour.getTour(); - for(TourElement element : tour.getTourElements() ) { - if(element instanceof Leg) { - Leg leg = (Leg) element; - scheduledTimeCosts += leg.getExpectedTransportTime() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; - } - } - } - totalScheduledCosts += scheduledTimeCosts; - assertEquals(scheduledTimeCosts, trackedTimeCosts, Math.max(scheduledTimeCosts,trackedTimeCosts)*0.01); - - double scheduledDistanceCosts = 0; - double trackedDistanceCosts = distanceHandler.getDistanceCosts(); - totalTrackedCosts += trackedDistanceCosts; - for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { - scheduledDistanceCosts += network.getLinks().get(scheduledTour.getTour().getEndLinkId()).getLength() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit; - for(TourElement element : scheduledTour.getTour().getTourElements()) { - System.out.println(element); - if(element instanceof Leg) { - Leg leg = (Leg) element; - NetworkRoute linkRoute = (NetworkRoute) leg.getRoute(); - for(Id linkId: linkRoute.getLinkIds()) { - scheduledDistanceCosts += network.getLinks().get(linkId).getLength() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit; - } - } - if(element instanceof ServiceActivity) { - ServiceActivity activity = (ServiceActivity) element; - scheduledDistanceCosts += network.getLinks().get(activity.getLocation()).getLength() * scheduledTour.getVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit; - } - } - } - totalScheduledCosts += scheduledDistanceCosts; - assertEquals(scheduledDistanceCosts, trackedDistanceCosts, Math.max(scheduledDistanceCosts,trackedDistanceCosts)*0.01); - } - } - - double linearTrackedCostsPerShipment = (totalTrackedCosts * (1-shareOfFixedCosts))/totalTrackedWeight; - double linearScheduledCostsPerShipment = (totalScheduledCosts * (1-shareOfFixedCosts))/totalScheduledWeight; - double fixedTrackedCostsPerShipment = (totalTrackedCosts * shareOfFixedCosts)/totalNumberOfTrackedShipments; - double fixedScheduledCostsPerShipment = (totalScheduledCosts * shareOfFixedCosts)/totalNumberOfScheduledShipments; - - assertEquals(totalTrackedWeight, totalTrackedWeight, 0); - assertEquals(totalNumberOfTrackedShipments, totalNumberOfScheduledShipments, 0); - assertEquals(totalTrackedCosts, totalScheduledCosts, Math.max(totalScheduledCosts, totalTrackedCosts)*0.01); - assertEquals(linearTrackedCostsPerShipment, linearScheduledCostsPerShipment, Math.max(linearTrackedCostsPerShipment, linearScheduledCostsPerShipment)*0.01); - assertEquals(fixedScheduledCostsPerShipment, fixedTrackedCostsPerShipment, Math.max(fixedTrackedCostsPerShipment, fixedScheduledCostsPerShipment)*0.01); - - assertTrue(collectionSolution.getInfos().size() == 1); - Info info = collectionSolution.getInfos().iterator().next(); - assertTrue(info instanceof CostInfo); - CostInfo costInfo = (CostInfo) info; - assertTrue(costInfo.getFunction() instanceof CostInfoFunction); - CostInfoFunction function = (CostInfoFunction) costInfo.getFunction(); - ArrayList> values = new ArrayList>(function.getValues()); - for(InfoFunctionValue value : values) { - if(value instanceof LinearCostFunctionValue) { - LinearCostFunctionValue linearValue = (LinearCostFunctionValue) value; - assertEquals(linearValue.getValue(),linearTrackedCostsPerShipment, Math.max(linearTrackedCostsPerShipment,linearValue.getValue()) * 0.01 ); - assertEquals(linearValue.getValue(),linearScheduledCostsPerShipment, Math.max(linearScheduledCostsPerShipment,linearValue.getValue()) * 0.01 ); - } - if(value instanceof FixedCostFunctionValue) { - FixedCostFunctionValue fixedValue = (FixedCostFunctionValue) value; - assertEquals(fixedValue.getValue(),fixedTrackedCostsPerShipment, Math.max(fixedTrackedCostsPerShipment,fixedValue.getValue()) * 0.01 ); - assertEquals(fixedValue.getValue(),fixedScheduledCostsPerShipment, Math.max(fixedScheduledCostsPerShipment,fixedValue.getValue()) * 0.01 ); - } - } - } -} diff --git a/test/testLSPWithCostTracker/CostInfo.java b/test/testLSPWithCostTracker/CostInfo.java deleted file mode 100644 index 60e47764d1f..00000000000 --- a/test/testLSPWithCostTracker/CostInfo.java +++ /dev/null @@ -1,49 +0,0 @@ -package testLSPWithCostTracker; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; - -public class CostInfo extends Info { - - private CostInfoFunction costFunction; - - public CostInfo() { - this.costFunction = new CostInfoFunction(); - } - - - @Override - public String getName() { - return "cost_function"; - } - - @Override - public InfoFunction getFunction() { - return costFunction; - } - - @Override - public double getFromTime() { - return 0; - } - - @Override - public double getToTime() { - return Double.MAX_VALUE; - } - - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - -} diff --git a/test/testLSPWithCostTracker/CostInfoFunction.java b/test/testLSPWithCostTracker/CostInfoFunction.java deleted file mode 100644 index 25978420268..00000000000 --- a/test/testLSPWithCostTracker/CostInfoFunction.java +++ /dev/null @@ -1,31 +0,0 @@ -package testLSPWithCostTracker; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; - - - -public class CostInfoFunction implements InfoFunction { - - private FixedCostFunctionValue fixedValue; - private LinearCostFunctionValue linearValue; - private Collection> values; - - public CostInfoFunction() { - values = new ArrayList>(); - fixedValue = new FixedCostFunctionValue(); - linearValue = new LinearCostFunctionValue(); - values.add(fixedValue); - values.add(linearValue); - - } - - @Override - public Collection> getValues() { - return values; - } - -} diff --git a/test/testLSPWithCostTracker/DistanceAndTimeHandler.java b/test/testLSPWithCostTracker/DistanceAndTimeHandler.java deleted file mode 100644 index bd7877eaacd..00000000000 --- a/test/testLSPWithCostTracker/DistanceAndTimeHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -package testLSPWithCostTracker; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; - -import lsp.events.FreightLinkEnterEvent; -import lsp.events.FreightLinkLeaveEvent; -import lsp.events.FreightLinkLeaveEventHandler; -import lsp.events.FreightVehicleLeavesTrafficEvent; -import lsp.events.FreightVehicleLeavesTrafficEventHandler; -import lsp.usecase.FreightLinkEnterEventHandler; - - -public class DistanceAndTimeHandler implements FreightLinkEnterEventHandler, FreightVehicleLeavesTrafficEventHandler, FreightLinkLeaveEventHandler { - - private Collection events; - private double distanceCosts; - private double timeCosts; - private Network network; - - public DistanceAndTimeHandler(Network network) { - this.network = network; - this.events = new ArrayList(); - } - - - @Override - public void handleEvent(FreightLinkEnterEvent event) { - events.add(event); - } - - @Override - public void reset(int iteration) { - events.clear(); - } - - - @Override - public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { - for(FreightLinkEnterEvent enterEvent : events) { - if(enterEvent != null) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } - } - } - - - @Override - public void handleEvent(FreightLinkLeaveEvent leaveEvent) { - if(events.size() > 0) { - for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } - } - } - - public double getDistanceCosts() { - return distanceCosts; - } - - public double getTimeCosts() { - return timeCosts; - } - -} diff --git a/test/testLSPWithCostTracker/FixedCostFunctionValue.java b/test/testLSPWithCostTracker/FixedCostFunctionValue.java deleted file mode 100644 index e6b2b0998af..00000000000 --- a/test/testLSPWithCostTracker/FixedCostFunctionValue.java +++ /dev/null @@ -1,24 +0,0 @@ -package testLSPWithCostTracker; - -import lsp.functions.InfoFunctionValue; - -public class FixedCostFunctionValue implements InfoFunctionValue { - - private double value; - - @Override - public String getName() { - return "fixed"; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public void setValue(Double value) { - this.value = value; - } - -} diff --git a/test/testLSPWithCostTracker/LinearCostFunctionValue.java b/test/testLSPWithCostTracker/LinearCostFunctionValue.java deleted file mode 100644 index 8a151b0e258..00000000000 --- a/test/testLSPWithCostTracker/LinearCostFunctionValue.java +++ /dev/null @@ -1,23 +0,0 @@ -package testLSPWithCostTracker; - -import lsp.functions.InfoFunctionValue; - -public class LinearCostFunctionValue implements InfoFunctionValue { - - private Double value; - - @Override - public String getName() { - return "linear"; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public void setValue(Double value) { - this.value = value; - } -} diff --git a/test/testLSPWithCostTracker/LinearCostTracker.java b/test/testLSPWithCostTracker/LinearCostTracker.java deleted file mode 100644 index f8b956be4b0..00000000000 --- a/test/testLSPWithCostTracker/LinearCostTracker.java +++ /dev/null @@ -1,102 +0,0 @@ -package testLSPWithCostTracker; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.events.handler.EventHandler; - -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.tracking.SimulationTracker; - -public class LinearCostTracker implements SimulationTracker{ - - private Collection eventHandlers; - private Collection infos; - private double distanceCosts; - private double timeCosts; - private double loadingCosts; - private double vehicleFixedCosts; - private int totalNumberOfShipments; - private int totalWeightOfShipments; - - private double fixedUnitCosts; - private double linearUnitCosts; - - private double shareOfFixedCosts; - - public LinearCostTracker(double shareOfFixedCosts) { - this.shareOfFixedCosts = shareOfFixedCosts; - CostInfo costInfo = new CostInfo(); - infos = new ArrayList(); - infos.add(costInfo); - this.eventHandlers = new ArrayList(); - } - - - @Override - public Collection getEventHandlers() { - return eventHandlers; - } - - @Override - public Collection getInfos() { - return infos; - } - - @Override - public void notifyAfterMobsim(AfterMobsimEvent event) { - for(EventHandler handler : eventHandlers) { - if(handler instanceof TourStartHandler) { - TourStartHandler startHandler = (TourStartHandler) handler; - this.vehicleFixedCosts = startHandler.getVehicleFixedCosts(); - } - if(handler instanceof DistanceAndTimeHandler) { - DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; - this.distanceCosts = distanceHandler.getDistanceCosts(); - this.timeCosts = distanceHandler.getTimeCosts(); - } - if(handler instanceof CollectionServiceHandler) { - CollectionServiceHandler collectionHandler = (CollectionServiceHandler) handler; - totalNumberOfShipments = collectionHandler.getTotalNumberOfShipments(); - System.out.println(totalNumberOfShipments); - totalWeightOfShipments = collectionHandler.getTotalWeightOfShipments(); - loadingCosts = collectionHandler.getTotalLoadingCosts(); - } - } - - double totalCosts = distanceCosts + timeCosts + loadingCosts + vehicleFixedCosts; - fixedUnitCosts = (totalCosts * shareOfFixedCosts)/totalNumberOfShipments; - linearUnitCosts = (totalCosts * (1-shareOfFixedCosts))/totalWeightOfShipments; - - CostInfo info = (CostInfo) infos.iterator().next(); - for(InfoFunctionValue value : info.getFunction().getValues()) { - if(value instanceof FixedCostFunctionValue) { - ((FixedCostFunctionValue)value).setValue(fixedUnitCosts); - } - if(value instanceof LinearCostFunctionValue) { - ((LinearCostFunctionValue)value).setValue(linearUnitCosts); - } - } - - - } - - - @Override - public void reset() { - distanceCosts = 0; - timeCosts = 0; - loadingCosts = 0; - vehicleFixedCosts = 0; - totalNumberOfShipments = 0; - totalWeightOfShipments = 0; - fixedUnitCosts = 0; - linearUnitCosts = 0; - - } - - - -} diff --git a/test/testLSPWithCostTracker/TourStartHandler.java b/test/testLSPWithCostTracker/TourStartHandler.java deleted file mode 100644 index 0f35e6a0edd..00000000000 --- a/test/testLSPWithCostTracker/TourStartHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package testLSPWithCostTracker; - -import lsp.events.TourStartEvent; -import lsp.events.TourStartEventHandler; - -public class TourStartHandler implements TourStartEventHandler{ - - private double vehicleFixedCosts; - - @Override - public void reset(int iteration) { - vehicleFixedCosts = 0; - } - - @Override - public void handleEvent(TourStartEvent event) { - vehicleFixedCosts = vehicleFixedCosts + event.getVehicle().getVehicleType().getVehicleCostInformation().fix; - } - - public double getVehicleFixedCosts() { - return vehicleFixedCosts; - } - -} diff --git a/test/testMutualReplanning/AllOffersRequester.java b/test/testMutualReplanning/AllOffersRequester.java deleted file mode 100644 index d1cc91c5b96..00000000000 --- a/test/testMutualReplanning/AllOffersRequester.java +++ /dev/null @@ -1,37 +0,0 @@ -package testMutualReplanning; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.OfferRequester; -import demand.offer.Offer; - -public class AllOffersRequester implements OfferRequester{ - - private DemandObject demandObject; - - public AllOffersRequester() { - - } - - @Override - public Collection requestOffers(Collection lsps) { - ArrayList offers = new ArrayList(); - for(LSPDecorator lsp : lsps) { - for(LogisticsSolutionDecorator solution : lsp.getSelectedPlan().getSolutionDecorators()) { - offers.add(lsp.getOffer(demandObject, "linear", solution.getId())); - } - } - return offers; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/test/testMutualReplanning/FortyTwoDemandScorer.java b/test/testMutualReplanning/FortyTwoDemandScorer.java deleted file mode 100644 index c4dcd847d54..00000000000 --- a/test/testMutualReplanning/FortyTwoDemandScorer.java +++ /dev/null @@ -1,19 +0,0 @@ -package testMutualReplanning; - -import demand.demandObject.DemandObject; -import demand.scoring.DemandScorer; - -public class FortyTwoDemandScorer implements DemandScorer { - - @Override - public double scoreCurrentPlan(DemandObject demandObject) { - return 42; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - // TODO Auto-generated method stub - - } - -} diff --git a/test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java b/test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java deleted file mode 100644 index 036702b453f..00000000000 --- a/test/testMutualReplanning/HalfLotSizeDemandPlanGenerator.java +++ /dev/null @@ -1,40 +0,0 @@ -package testMutualReplanning; - -import java.util.Collection; - -import demand.demandObject.DemandObject; -import demand.demandObject.DemandPlan; -import demand.demandObject.DemandPlanGenerator; -import demand.demandObject.DemandPlanImpl; -import demand.demandObject.ShipperShipmentImpl; -import demand.offer.Offer; - -public class HalfLotSizeDemandPlanGenerator implements DemandPlanGenerator{ - - private DemandObject demandObject; - - @Override - public DemandPlan createDemandPlan(Collection offers) { - Offer singleOffer = offers.iterator().next(); - DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); - planBuilder.setLsp(singleOffer.getLsp()); - planBuilder.setLogisticsSolutionId(singleOffer.getSolution().getId()); - planBuilder.setDemandObject(demandObject); - - ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); - shipmentBuilder.setDemandObject(demandObject); - shipmentBuilder.setId(demandObject.getSelectedPlan().getShipment().getId()); - shipmentBuilder.setEndTimeWindow(demandObject.getSelectedPlan().getShipment().getEndTimeWindow()); - shipmentBuilder.setStartTimeWindow(demandObject.getSelectedPlan().getShipment().getStartTimeWindow()); - shipmentBuilder.setServiceTime(demandObject.getSelectedPlan().getShipment().getServiceTime()); - shipmentBuilder.setShipmentSize(demandObject.getSelectedPlan().getShipment().getShipmentSize()/2); - planBuilder.setShipperShipment(shipmentBuilder.build()); - return planBuilder.build(); - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/test/testMutualReplanning/InitialLSPGenerator.java b/test/testMutualReplanning/InitialLSPGenerator.java deleted file mode 100644 index dfa8285099a..00000000000 --- a/test/testMutualReplanning/InitialLSPGenerator.java +++ /dev/null @@ -1,252 +0,0 @@ -package testMutualReplanning; - -import java.util.ArrayList; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPPlanDecorator; -import demand.decoratedLSP.LSPPlanWithOfferTransferrer; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.offer.OfferFactoryImpl; -import demand.offer.OfferTransferrer; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import requirementsCheckerTests.BlueInfo; -import requirementsCheckerTests.NonsenseOffer; -import requirementsCheckerTests.RedInfo; -import requirementsCheckerTests.RequirementsTransferrer; - -public class InitialLSPGenerator { - - - public LSPDecorator createInitialLSP() { - - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - Network network = scenario.getNetwork(); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(20); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); - - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(collectionCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - - - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); - mainRunAdapterBuilder.setCarrier(collectionCarrier); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); - - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); - - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); - - DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); - Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); - Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); - dsitributionVehicleTypeBuilder.setCapacity(10); - dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - dsitributionVehicleTypeBuilder.setFixCost(49); - dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); - - Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); - distributionCarrierVehicle.setVehicleType(distributionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); - capabilitiesBuilder.addVehicle(distributionCarrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); - Carrier carrier = CarrierImpl.newInstance(distributionCarrierId); - carrier.setCarrierCapabilities(distributionCapabilities); - - - Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); - DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); - distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - distributionAdapterBuilder.setCarrier(carrier); - distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - Resource distributionAdapter = distributionAdapterBuilder.build(); - - Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); - distributionBuilder.setResource(distributionAdapter); - LogisticsSolutionElement distributionElement = distributionBuilder.build(); - - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - secondReloadElement.setNextElement(distributionElement); - distributionElement.setPreviousElement(secondReloadElement); - - Id solutionId = Id.create("Solution", LogisticsSolution.class); - LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); - solutionBuilder.addSolutionElement(collectionElement); - solutionBuilder.addSolutionElement(firstReloadElement); - solutionBuilder.addSolutionElement(mainRunElement); - solutionBuilder.addSolutionElement(secondReloadElement); - solutionBuilder.addSolutionElement(distributionElement); - LogisticsSolutionDecorator solution = solutionBuilder.build(); - - OfferFactoryImpl offerFactory = new OfferFactoryImpl(solution); - offerFactory.addOffer(new LinearOffer(solution)); - solution.setOfferFactory(offerFactory); - - LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); - plan.addSolution(solution); - - OfferTransferrer transferrer = new SimpleOfferTransferrer(); - plan.setOfferTransferrer(transferrer); - - LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); - offerLSPBuilder.setInitialPlan(plan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - offerLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - resourcesList.add(distributionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - offerLSPBuilder.setSolutionScheduler(simpleScheduler); - return offerLSPBuilder.build(); - } - -} diff --git a/test/testMutualReplanning/LinearOffer.java b/test/testMutualReplanning/LinearOffer.java deleted file mode 100644 index ed53d10a50e..00000000000 --- a/test/testMutualReplanning/LinearOffer.java +++ /dev/null @@ -1,85 +0,0 @@ -package testMutualReplanning; - -import java.util.Random; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.offer.Offer; -import demand.offer.OfferVisitor; -import example.simulationTrackers.CostInfo; -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.LSP; -import lsp.LogisticsSolution; - - -public class LinearOffer implements Offer{ - - private LSPDecorator lsp; - private LogisticsSolutionDecorator solution; - private String type; - private double fix; - private double linear; - - public LinearOffer(LogisticsSolutionDecorator solution) { - this.lsp = solution.getLSP(); - this.solution = solution; - this.type = "linear"; - Random random = new Random(1); - fix = random.nextDouble() * 10; - linear = random.nextDouble() * 10; - } - - @Override - public LSPDecorator getLsp() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getSolution() { - return solution; - } - - @Override - public String getType() { - return type; - } - - public double getFix() { - return fix; - } - - public void setFix(double fix) { - this.fix = fix; - } - - public double getLinear() { - return linear; - } - - public void setLinear(double linear) { - this.linear = linear; - } - - @Override - public void accept(OfferVisitor visitor) { - visitor.visit(this); - } - - @Override - public void update() { - - - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public void setSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - -} diff --git a/test/testMutualReplanning/MutualReplanningTest.java b/test/testMutualReplanning/MutualReplanningTest.java deleted file mode 100644 index 59f2e51d31f..00000000000 --- a/test/testMutualReplanning/MutualReplanningTest.java +++ /dev/null @@ -1,239 +0,0 @@ -package testMutualReplanning; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.replanning.selectors.BestPlanSelector; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import demand.controler.MutualModule; -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPPlanDecorator; -import demand.decoratedLSP.LSPPlanWithOfferTransferrer; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LSPDecorators; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.demandAgent.DemandAgent; -import demand.demandAgent.DemandAgentImpl; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjectImpl; -import demand.demandObject.DemandObjects; -import demand.demandObject.DemandPlanImpl; -import demand.demandObject.ShipperShipment; -import demand.demandObject.ShipperShipmentImpl; -import demand.mutualReplanning.DemandPlanStrategyImpl; -import demand.mutualReplanning.DemandReplannerImpl; -import demand.mutualReplanning.MutualReplanningModule; -import demand.mutualReplanning.MutualReplanningModuleImpl; -import demand.mutualReplanning.OfferReplanningStrategyModuleImpl; -import demand.offer.OfferFactoryImpl; -import demand.offer.OfferTransferrer; -import demand.scoring.MutualScoringModule; -import demand.scoring.MutualScoringModuleImpl; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.SolutionScheduler; -import lsp.events.EventUtils; -import lsp.resources.Resource; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import testLSPWithCostTracker.CollectionServiceHandler; -import testLSPWithCostTracker.DistanceAndTimeHandler; -import testLSPWithCostTracker.LinearCostTracker; -import testLSPWithCostTracker.TourStartHandler; - -public class MutualReplanningTest { - - private LSPDecorator lsp; - private Collection demandObjects; - - - @Before - public void initialize(){ - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - Network network = scenario.getNetwork(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Random random = new Random(1); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(20); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - Id solutionId = Id.create("Solution", LogisticsSolution.class); - LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); - solutionBuilder.addSolutionElement(collectionElement); - LogisticsSolutionDecorator solution = solutionBuilder.build(); - - LinearCostTracker tracker = new LinearCostTracker(0.2); - tracker.getEventHandlers().add(new TourStartHandler()); - tracker.getEventHandlers().add(new CollectionServiceHandler()); - tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); - solution.addSimulationTracker(tracker); - - - OfferFactoryImpl offerFactory = new OfferFactoryImpl(solution); - offerFactory.addOffer(new LinearOffer(solution)); - solution.setOfferFactory(offerFactory); - - LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); - plan.addSolution(solution); - - OfferTransferrer transferrer = new SimpleOfferTransferrer(); - plan.setOfferTransferrer(transferrer); - - LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); - offerLSPBuilder.setInitialPlan(plan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - offerLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - offerLSPBuilder.setSolutionScheduler(simpleScheduler); - lsp = offerLSPBuilder.build(); - - demandObjects = new ArrayList<>(); - for(int i = 1; i < 11 ; i++) { - DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); - builder.setId(Id.create("DemandObject_" + i, DemandObject.class)); - DemandAgentImpl.Builder shipperBuilder = DemandAgentImpl.Builder.newInstance(); - shipperBuilder.setId(Id.create("DemandObject_" + i+ "_Shipper", DemandAgent.class)); - builder.setShipper(shipperBuilder.build()); - DemandAgentImpl.Builder recipientBuilder = DemandAgentImpl.Builder.newInstance(); - recipientBuilder.setId(Id.create("DemandObject_" + i+ "_Recipient", DemandAgent.class)); - builder.setRecipient(recipientBuilder.build()); - double shipmentSize= 5 + random.nextDouble()*5; - builder.setStrengthOfFlow(shipmentSize); - builder.setToLinkId(collectionLinkId); - - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); - ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); - shipmentBuilder.setId(Id.create("DemandObject_" + i+ "_Shipment", ShipperShipment.class)); - shipmentBuilder.setShipmentSize(shipmentSize); - shipmentBuilder.setServiceTime(shipmentSize * 60); - planBuilder.setShipperShipment(shipmentBuilder.build()); - planBuilder.setLsp(lsp); - planBuilder.setLogisticsSolutionId(lsp.getSelectedPlan().getSolutions().iterator().next().getId()); - builder.setInitialPlan(planBuilder.build()); - builder.setScorer(new FortyTwoDemandScorer()); - DemandReplannerImpl replanner = new DemandReplannerImpl(); - DemandPlanStrategyImpl planStrategy = new DemandPlanStrategyImpl(new BestPlanSelector()); - planStrategy.addStrategyModule(new OfferReplanningStrategyModuleImpl()); - replanner.addStrategy(planStrategy); - builder.setReplanner(replanner); - builder.setOfferRequester(new AllOffersRequester()); - builder.setDemandPlanGenerator(new HalfLotSizeDemandPlanGenerator()); - DemandObject demandObject = builder.build(); - demandObjects.add(demandObject); - - } - - - Collectionlsps = new ArrayList<>(); - lsps.add(lsp); - MutualScoringModule mutScoreModule = new MutualScoringModuleImpl(demandObjects, lsps); - - MutualReplanningModule mutReplanModule = new MutualReplanningModuleImpl( lsps, demandObjects); - - MutualModule.Builder moduleBuilder = MutualModule.Builder.newInstance(); - moduleBuilder.setDemandObjects(new DemandObjects(demandObjects)); - moduleBuilder.setLsps(new LSPDecorators(lsps)); - moduleBuilder.setMutualReplanningModule(mutReplanModule); - moduleBuilder.setMutualScoringModule(mutScoreModule); - moduleBuilder.setEventCreators(EventUtils.getStandardEventCreators()); - MutualModule mutualModule = moduleBuilder.build(); - - Controler controler = new Controler(config); - controler.addOverridingModule(mutualModule); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(2); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); - controler.run(); - } - - @Test - public void testReplanning() { - for(DemandObject demandObject : demandObjects) { - assertEquals((demandObject.getStrengthOfFlow()/2), demandObject.getSelectedPlan().getShipment().getShipmentSize(), 0.1); - } - - } - -} diff --git a/test/testMutualReplanning/SimpleOfferTransferrer.java b/test/testMutualReplanning/SimpleOfferTransferrer.java deleted file mode 100644 index 808a6c85dea..00000000000 --- a/test/testMutualReplanning/SimpleOfferTransferrer.java +++ /dev/null @@ -1,30 +0,0 @@ -package testMutualReplanning; - -import org.matsim.api.core.v01.Id; - -import demand.decoratedLSP.LSPDecorator; -import demand.demandObject.DemandObject; -import demand.offer.Offer; -import demand.offer.OfferTransferrer; -import lsp.LogisticsSolution; - -public class SimpleOfferTransferrer implements OfferTransferrer{ - - private LSPDecorator lsp; - - @Override - public Offer transferOffer(DemandObject object, String type, Id solutionId) { - return lsp.getSelectedPlan().getSolutionDecorators().iterator().next().getOffer(object, type); - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public LSPDecorator getLSP() { - return lsp; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java b/test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java deleted file mode 100644 index 7c436f015c3..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/AllOffersRequester.java +++ /dev/null @@ -1,37 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.demandObject.DemandObject; -import demand.demandObject.OfferRequester; -import demand.offer.Offer; - -public class AllOffersRequester implements OfferRequester{ - - private DemandObject demandObject; - - public AllOffersRequester() { - - } - - @Override - public Collection requestOffers(Collection lsps) { - ArrayList offers = new ArrayList(); - for(LSPDecorator lsp : lsps) { - for(LogisticsSolutionDecorator solution : lsp.getSelectedPlan().getSolutionDecorators()) { - offers.add(lsp.getOffer(demandObject, "linear", solution.getId())); - } - } - return offers; - } - - @Override - public void setDemandObject(DemandObject demandObject) { - this.demandObject = demandObject; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java b/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java deleted file mode 100644 index 3a758440b5c..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/CollectionServiceHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.contrib.freight.carrier.CarrierService; - -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; -import lsp.events.ServiceEndEvent; -import lsp.events.ServiceEndEventHandler; - - -public class CollectionServiceHandler implements ServiceStartEventHandler, ServiceEndEventHandler{ - - - - private class ServiceTuple { - private CarrierService service; - private double startTime; - - public ServiceTuple(CarrierService service, double startTime) { - this.service = service; - this.startTime = startTime; - } - - public CarrierService getService() { - return service; - } - - public double getStartTime() { - return startTime; - } - - } - - private Collection tuples; - private double totalLoadingCosts; - private int totalNumberOfShipments; - private int totalWeightOfShipments; - - public CollectionServiceHandler() { - this.tuples = new ArrayList(); - } - - @Override - public void reset(int iteration) { - tuples.clear(); - totalNumberOfShipments = 0; - totalWeightOfShipments = 0; - totalLoadingCosts = 0; - } - - @Override - public void handleEvent(ServiceEndEvent event) { - double loadingCosts = 0; - for(ServiceTuple tuple : tuples) { - if(tuple.getService() == event.getService()) { - double serviceDuration = event.getTime() - tuple.getStartTime(); - loadingCosts = serviceDuration * event.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; - totalLoadingCosts = totalLoadingCosts + loadingCosts; - tuples.remove(tuple); - break; - } - } - } - - @Override - public void handleEvent(ServiceStartEvent event) { - totalNumberOfShipments++; - totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); - tuples.add(new ServiceTuple(event.getService(), event.getTime())); - } - - public double getTotalLoadingCosts() { - return totalLoadingCosts; - } - - public int getTotalNumberOfShipments() { - return totalNumberOfShipments; - } - - public int getTotalWeightOfShipments() { - return totalWeightOfShipments; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/CostInfo.java b/test/testMutualreplanningWithOfferUpdate/CostInfo.java deleted file mode 100644 index fe29814e611..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/CostInfo.java +++ /dev/null @@ -1,49 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; - -public class CostInfo extends Info { - - private CostInfoFunction costFunction; - - public CostInfo() { - this.costFunction = new CostInfoFunction(); - } - - - @Override - public String getName() { - return "cost_function"; - } - - @Override - public InfoFunction getFunction() { - return costFunction; - } - - @Override - public double getFromTime() { - return 0; - } - - @Override - public double getToTime() { - return Double.MAX_VALUE; - } - - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java b/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java deleted file mode 100644 index 4c46792c88e..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/CostInfoFunction.java +++ /dev/null @@ -1,29 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; - -public class CostInfoFunction implements InfoFunction { - - private FixedCostFunctionValue fixedValue; - private LinearCostFunctionValue linearValue; - private Collection> values; - - public CostInfoFunction() { - values = new ArrayList>(); - fixedValue = new FixedCostFunctionValue(); - linearValue = new LinearCostFunctionValue(); - values.add(fixedValue); - values.add(linearValue); - - } - - @Override - public Collection> getValues() { - return values; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java b/test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java deleted file mode 100644 index 5303f78faf1..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/DistanceAndTimeHandler.java +++ /dev/null @@ -1,82 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; - -import lsp.events.FreightLinkEnterEvent; -import lsp.events.FreightLinkLeaveEvent; -import lsp.events.FreightLinkLeaveEventHandler; -import lsp.events.FreightVehicleLeavesTrafficEvent; -import lsp.events.FreightVehicleLeavesTrafficEventHandler; -import lsp.usecase.FreightLinkEnterEventHandler; - -public class DistanceAndTimeHandler implements FreightLinkEnterEventHandler, FreightVehicleLeavesTrafficEventHandler, FreightLinkLeaveEventHandler { - - private Collection events; - private double distanceCosts; - private double timeCosts; - private Network network; - - public DistanceAndTimeHandler(Network network) { - this.network = network; - this.events = new ArrayList(); - } - - - @Override - public void handleEvent(FreightLinkEnterEvent event) { - events.add(event); - - } - - @Override - public void reset(int iteration) { - events.clear(); - distanceCosts = 0; - timeCosts = 0; - } - - - @Override - public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { - for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } - } - - - @Override - public void handleEvent(FreightLinkLeaveEvent leaveEvent) { - for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } - } - - public double getDistanceCosts() { - return distanceCosts; - } - - public double getTimeCosts() { - return timeCosts; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java b/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java deleted file mode 100644 index 7961985596a..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/FixedCostFunctionValue.java +++ /dev/null @@ -1,24 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import lsp.functions.InfoFunctionValue; - -public class FixedCostFunctionValue implements InfoFunctionValue { - - private Double value; - - @Override - public String getName() { - return "fixed"; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public void setValue(Double value) { - this.value = value; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java b/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java deleted file mode 100644 index cecf624b46c..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/LinearCostFunctionValue.java +++ /dev/null @@ -1,24 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import lsp.functions.InfoFunctionValue; - -public class LinearCostFunctionValue implements InfoFunctionValue { - - private Double value; - - @Override - public String getName() { - return "linear"; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public void setValue(Double value) { - this.value = value; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java b/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java deleted file mode 100644 index 3fc8f89833d..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/LinearCostTracker.java +++ /dev/null @@ -1,104 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.events.handler.EventHandler; - -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.tracking.SimulationTracker; - -public class LinearCostTracker implements SimulationTracker{ - - private Collection eventHandlers; - private Collection infos; - private double distanceCosts; - private double timeCosts; - private double loadingCosts; - private double vehicleFixedCosts; - private int totalNumberOfShipments; - private int totalWeightOfShipments; - - private double fixedUnitCosts; - private double linearUnitCosts; - - private double shareOfFixedCosts; - - public LinearCostTracker(double shareOfFixedCosts) { - this.shareOfFixedCosts = shareOfFixedCosts; - CostInfo costInfo = new CostInfo(); - infos = new ArrayList(); - infos.add(costInfo); - this.eventHandlers = new ArrayList(); - } - - - @Override - public Collection getEventHandlers() { - return eventHandlers; - } - - @Override - public Collection getInfos() { - return infos; - } - - @Override - public void notifyAfterMobsim(AfterMobsimEvent event) { - - for(EventHandler handler : eventHandlers) { - if(handler instanceof TourStartHandler) { - TourStartHandler startHandler = (TourStartHandler) handler; - this.vehicleFixedCosts = startHandler.getVehicleFixedCosts(); - } - if(handler instanceof DistanceAndTimeHandler) { - DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; - this.distanceCosts = distanceHandler.getDistanceCosts(); - this.timeCosts = distanceHandler.getTimeCosts(); - } - if(handler instanceof CollectionServiceHandler) { - CollectionServiceHandler collectionHandler = (CollectionServiceHandler) handler; - totalNumberOfShipments = collectionHandler.getTotalNumberOfShipments(); - totalWeightOfShipments = collectionHandler.getTotalWeightOfShipments(); - loadingCosts = collectionHandler.getTotalLoadingCosts(); - } - } - - double totalCosts = distanceCosts + timeCosts + loadingCosts + vehicleFixedCosts; - fixedUnitCosts = (totalCosts * shareOfFixedCosts)/totalNumberOfShipments; - linearUnitCosts = (totalCosts * (1-shareOfFixedCosts))/totalWeightOfShipments; - - CostInfo info = (CostInfo) infos.iterator().next(); - for(InfoFunctionValue value : info.getFunction().getValues()) { - if(value instanceof FixedCostFunctionValue) { - ((FixedCostFunctionValue)value).setValue(fixedUnitCosts); - } - if(value instanceof LinearCostFunctionValue) { - ((LinearCostFunctionValue)value).setValue(linearUnitCosts); - } - } - - - } - - - @Override - public void reset() { - for(EventHandler eventHandler : eventHandlers) { - eventHandler.reset(0); - } - distanceCosts = 0; - timeCosts = 0; - loadingCosts = 0; - vehicleFixedCosts = 0; - totalNumberOfShipments = 0; - totalWeightOfShipments = 0; - fixedUnitCosts = 0; - linearUnitCosts = 0; - } - - - -} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOffer.java b/test/testMutualreplanningWithOfferUpdate/LinearOffer.java deleted file mode 100644 index 79256a0b1c2..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/LinearOffer.java +++ /dev/null @@ -1,98 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.Random; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.offer.Offer; -import demand.offer.OfferVisitor; -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; - - -public class LinearOffer implements Offer{ - - private LSPDecorator lsp; - private LogisticsSolutionDecorator solution; - private String type; - private double fix; - private double linear; - - public LinearOffer(LogisticsSolutionDecorator solution) { - this.lsp = solution.getLSP(); - this.solution = solution; - this.type = "linear"; - Random random = new Random(1); - fix = random.nextDouble() * 10; - linear = random.nextDouble() * 10; - } - - @Override - public LSPDecorator getLsp() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getSolution() { - return solution; - } - - @Override - public String getType() { - return type; - } - - public double getFix() { - return fix; - } - - public void setFix(double fix) { - this.fix = fix; - } - - public double getLinear() { - return linear; - } - - public void setLinear(double linear) { - this.linear = linear; - } - - @Override - public void accept(OfferVisitor visitor) { - visitor.visit(this); - } - - @Override - public void update() { - for(Info info : solution.getInfos()) { - if(info instanceof CostInfo) { - CostInfo costInfo = (CostInfo) info; - CostInfoFunction costFunction = (CostInfoFunction) costInfo.getFunction(); - FixedCostFunctionValue fixedValue; - LinearCostFunctionValue linearValue; - for(InfoFunctionValue value : costFunction.getValues()) { - if(value instanceof FixedCostFunctionValue) { - fixedValue = (FixedCostFunctionValue) value; - this.fix = fixedValue.getValue(); - } - if(value instanceof LinearCostFunctionValue) { - linearValue = (LinearCostFunctionValue) value; - this.linear = linearValue.getValue(); - } - } - } - } - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public void setSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java b/test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java deleted file mode 100644 index f08a357df04..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/LinearOfferFactoryImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import java.util.ArrayList; -import java.util.Collection; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.demandObject.DemandObject; -import demand.offer.DefaultOfferImpl; -import demand.offer.Offer; -import demand.offer.OfferFactory; -import lsp.LSP; -import lsp.LogisticsSolution; - -public class LinearOfferFactoryImpl implements OfferFactory{ - - - private ArrayList offerList; - private LogisticsSolutionDecorator solution; - private LSPDecorator lsp; - - public LinearOfferFactoryImpl(LogisticsSolutionDecorator solution) { - this.solution = solution; - this.lsp = solution.getLSP(); - offerList = new ArrayList(); - offerList.add(new LinearOffer(solution)); - } - - @Override - public Offer makeOffer(DemandObject object, String offerType) { - for(Offer offer : offerList) { - if(offer.getType() == offerType) { - offer.setLSP(lsp); - return offer; - } - } - return new DefaultOfferImpl(this.lsp, this.solution); - } - - @Override - public Collection getOffers() { - return offerList; - } - - @Override - public LSPDecorator getLSP() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getLogisticsSolution() { - return solution; - } - - @Override - public void setLogisticsSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - @Override - public void addOffer(Offer offer) { - // TODO Auto-generated method stub - - } - - -} diff --git a/test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java b/test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java deleted file mode 100644 index 4cec7cb4e93..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/LinearOfferVisitor.java +++ /dev/null @@ -1,35 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.offer.Offer; -import demand.offer.OfferVisitor; -import lsp.LogisticsSolution; - -public class LinearOfferVisitor implements OfferVisitor { - - private LogisticsSolutionDecorator solution; - - public LinearOfferVisitor(LogisticsSolutionDecorator solution) { - this.solution = solution; - } - - - @Override - public void visit(Offer offer) { - if(offer instanceof LinearOffer) { - LinearOffer linearOffer = (LinearOffer) offer; - linearOffer.update(); - } - } - - @Override - public Class getOfferClass(){ - return LinearOffer.class; - } - - @Override - public LogisticsSolution getLogisticsSolution() { - return solution; - } - -} diff --git a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java b/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java deleted file mode 100644 index e5d52ee392c..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/MutualReplanningAndOfferUpdateTest.java +++ /dev/null @@ -1,291 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.events.handler.EventHandler; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.replanning.selectors.BestPlanSelector; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import demand.controler.MutualModule; -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPDecorators; -import demand.decoratedLSP.LSPPlanDecorator; -import demand.decoratedLSP.LSPPlanWithOfferTransferrer; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.demandAgent.DemandAgent; -import demand.demandAgent.DemandAgentImpl; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjectImpl; -import demand.demandObject.DemandObjects; -import demand.demandObject.DemandPlanImpl; -import demand.demandObject.ShipperShipment; -import demand.demandObject.ShipperShipmentImpl; -import demand.mutualReplanning.DemandPlanStrategyImpl; -import demand.mutualReplanning.DemandReplannerImpl; -import demand.mutualReplanning.LSPWithOffersReplanner; -import demand.mutualReplanning.MutualReplanningModule; -import demand.mutualReplanning.MutualReplanningModuleImpl; -import demand.mutualReplanning.OfferReplanningStrategyModuleImpl; -import demand.offer.Offer; -import demand.offer.OfferFactoryImpl; -import demand.offer.OfferTransferrer; -import demand.offer.OfferUpdater; -import demand.offer.OfferUpdaterImpl; -import demand.scoring.MutualScoringModule; -import demand.scoring.MutualScoringModuleImpl; -import lsp.functions.Info; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.SolutionScheduler; -import lsp.events.EventUtils; -import lsp.resources.Resource; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import testMutualReplanning.FortyTwoDemandScorer; -import testMutualReplanning.HalfLotSizeDemandPlanGenerator; -import testMutualReplanning.SimpleOfferTransferrer; - - -@SuppressWarnings("unused") -public class MutualReplanningAndOfferUpdateTest { - - private LSPDecorator lsp; - private OfferFactoryImpl offerFactory; - private LinearCostTracker tracker; - private LinearOfferVisitor linearVisitor; - private LogisticsSolutionDecorator solution; - private double initialFixed; - private double initialVariable; - - @Before - public void initialize() { - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); - Network network = scenario.getNetwork(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Random random = new Random(1); - - CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(20); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id collectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle collectionVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId); - collectionVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); - collectionCapabilitiesBuilder.addVehicle(collectionVehicle); - collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(collectionCapabilities); - - Id collectionAdapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder collectionAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(collectionAdapterId, network); - collectionAdapterBuilder.setCollectionScheduler(collectionScheduler); - collectionAdapterBuilder.setCarrier(collectionCarrier); - collectionAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = collectionAdapterBuilder.build(); - - Id collectionElementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(collectionElementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - Id solutionId = Id.create("Solution", LogisticsSolution.class); - LogisticsSolutionWithOffers.Builder solutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(solutionId); - solutionBuilder.addSolutionElement(collectionElement); - solution = solutionBuilder.build(); - - tracker = new LinearCostTracker(0.2); - tracker.getEventHandlers().add(new TourStartHandler()); - tracker.getEventHandlers().add(new CollectionServiceHandler()); - tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); - solution.addSimulationTracker(tracker); - - offerFactory = new OfferFactoryImpl(solution); - LinearOffer offer = new LinearOffer(solution); - initialFixed = offer.getFix(); - initialVariable = offer.getLinear(); - offerFactory.addOffer(offer); - solution.setOfferFactory(offerFactory); - - LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); - plan.addSolution(solution); - - OfferTransferrer transferrer = new SimpleOfferTransferrer(); - plan.setOfferTransferrer(transferrer); - - LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); - offerLSPBuilder.setInitialPlan(plan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - offerLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - offerLSPBuilder.setSolutionScheduler(simpleScheduler); - - lsp = offerLSPBuilder.build(); - - LSPWithOffersReplanner replanner = new LSPWithOffersReplanner(lsp); - lsp.setReplanner(replanner); - - OfferUpdater updater = new OfferUpdaterImpl(); - lsp.setOfferUpdater(updater); - replanner.setOfferUpdater(updater); - linearVisitor = new LinearOfferVisitor(solution); - updater.getOfferVisitors().add(linearVisitor); - - - ArrayListdemandObjects = new ArrayList(); - - for(int i = 1; i < 11 ; i++) { - DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); - builder.setId(Id.create("DemandObject_" + i, DemandObject.class)); - DemandAgentImpl.Builder shipperBuilder = DemandAgentImpl.Builder.newInstance(); - shipperBuilder.setId(Id.create("DemandObject_" + i+ "_Shipper", DemandAgent.class)); - builder.setShipper(shipperBuilder.build()); - DemandAgentImpl.Builder recipientBuilder = DemandAgentImpl.Builder.newInstance(); - recipientBuilder.setId(Id.create("DemandObject_" + i+ "_Recipient", DemandAgent.class)); - builder.setRecipient(recipientBuilder.build()); - double shipmentSize= 5 + random.nextDouble()*5; - builder.setStrengthOfFlow(shipmentSize); - builder.setToLinkId(collectionLinkId); - - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - DemandPlanImpl.Builder planBuilder = DemandPlanImpl.Builder.newInstance(); - ShipperShipmentImpl.Builder shipmentBuilder = ShipperShipmentImpl.Builder.newInstance(); - shipmentBuilder.setId(Id.create("DemandObject_" + i+ "_Shipment", ShipperShipment.class)); - shipmentBuilder.setShipmentSize(shipmentSize); - shipmentBuilder.setServiceTime(shipmentSize * 60); - planBuilder.setShipperShipment(shipmentBuilder.build()); - planBuilder.setLsp(lsp); - planBuilder.setLogisticsSolutionId(lsp.getSelectedPlan().getSolutions().iterator().next().getId()); - builder.setInitialPlan(planBuilder.build()); - builder.setScorer(new FortyTwoDemandScorer()); - DemandReplannerImpl demandReplanner = new DemandReplannerImpl(); - DemandPlanStrategyImpl planStrategy = new DemandPlanStrategyImpl(new BestPlanSelector()); - planStrategy.addStrategyModule(new OfferReplanningStrategyModuleImpl()); - demandReplanner.addStrategy(planStrategy); - builder.setReplanner(demandReplanner); - builder.setOfferRequester(new AllOffersRequester()); - builder.setDemandPlanGenerator(new HalfLotSizeDemandPlanGenerator()); - DemandObject demandObject = builder.build(); - demandObjects.add(demandObject); - - } - - ArrayList lspList = new ArrayList<>(); - lspList.add(lsp); - - Controler controler = new Controler(config); - - MutualScoringModule mutScoreModule = new MutualScoringModuleImpl(demandObjects, lspList); - - MutualReplanningModule mutReplanModule = new MutualReplanningModuleImpl(lspList, demandObjects); - - MutualModule.Builder moduleBuilder = MutualModule.Builder.newInstance(); - moduleBuilder.setDemandObjects(new DemandObjects(demandObjects)); - moduleBuilder.setLsps(new LSPDecorators(lspList)); - moduleBuilder.setMutualReplanningModule(mutReplanModule); - moduleBuilder.setMutualScoringModule(mutScoreModule); - moduleBuilder.setEventCreators(EventUtils.getStandardEventCreators()); - MutualModule mutualModule = moduleBuilder.build(); - - controler.addOverridingModule(mutualModule); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(2); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); - controler.run(); - - - } - - @Test - public void testOfferUpdater() { - - assertTrue(tracker == solution.getSimulationTrackers().iterator().next()); - int numberOfHandlers = 0; - for(EventHandler solutionHandler : solution.getEventHandlers()) { - for(EventHandler trackerHandler : tracker.getEventHandlers()) { - if(solutionHandler == trackerHandler) { - numberOfHandlers++; - } - } - } - assertTrue(numberOfHandlers == tracker.getEventHandlers().size()); - - for(Info solutionInfo : solution.getInfos()) { - for(Info trackerInfo : tracker.getInfos()) { - assertTrue(solutionInfo == trackerInfo); - } - } - - - assertTrue(offerFactory.getOffers().size() == 1 ); - for(Offer offer : offerFactory.getOffers()) { - assertTrue(offer instanceof LinearOffer); - LinearOffer linearOffer = (LinearOffer) offer; - assertTrue(linearOffer.getSolution() == solution); - assertTrue(linearOffer.getSolution().getLSP() == solution.getLSP()); - assertTrue(linearOffer.getSolution().getLSP() == lsp); - assertTrue(linearOffer.getLsp() == lsp); - assertTrue(linearOffer.getFix() != initialFixed); - assertTrue(linearOffer.getLinear() != initialVariable); - } - - } -} diff --git a/test/testMutualreplanningWithOfferUpdate/TourStartHandler.java b/test/testMutualreplanningWithOfferUpdate/TourStartHandler.java deleted file mode 100644 index 2b47b2412e1..00000000000 --- a/test/testMutualreplanningWithOfferUpdate/TourStartHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package testMutualreplanningWithOfferUpdate; - -import lsp.events.TourStartEvent; -import lsp.events.TourStartEventHandler; - -public class TourStartHandler implements TourStartEventHandler{ - - private double vehicleFixedCosts; - - @Override - public void reset(int iteration) { - vehicleFixedCosts = 0; - } - - @Override - public void handleEvent(TourStartEvent event) { - vehicleFixedCosts = vehicleFixedCosts + event.getVehicle().getVehicleType().getVehicleCostInformation().fix; - } - - public double getVehicleFixedCosts() { - return vehicleFixedCosts; - } - -} From 650278a687b18fee4dcb4610fbada98e561dd511 Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 17:10:41 +0200 Subject: [PATCH 0048/1340] merge pom.xml from changed freight_tm --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7c54cd0211a..9344fc86147 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,13 @@ ojo-snapshots http://oss.jfrog.org/libs-snapshot - + + + osgeo + Geotools repository + http://download.osgeo.org/webdav/geotools + + From 8ab4bb13cc8d569a7bfb41d5b757357d0546dfbc Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 18:09:42 +0200 Subject: [PATCH 0049/1340] fix errors --- src/timeSliceTest/TimeSliceAssigner.java | 30 -- .../TimeSliceCarrierAdapter.java | 168 ---------- src/timeSliceTest/TimeSliceScheduler.java | 295 ------------------ .../TimeSliceSolutionScheduler.java | 52 --- 4 files changed, 545 deletions(-) delete mode 100644 src/timeSliceTest/TimeSliceAssigner.java delete mode 100644 src/timeSliceTest/TimeSliceCarrierAdapter.java delete mode 100644 src/timeSliceTest/TimeSliceScheduler.java delete mode 100644 src/timeSliceTest/TimeSliceSolutionScheduler.java diff --git a/src/timeSliceTest/TimeSliceAssigner.java b/src/timeSliceTest/TimeSliceAssigner.java deleted file mode 100644 index a746ea90899..00000000000 --- a/src/timeSliceTest/TimeSliceAssigner.java +++ /dev/null @@ -1,30 +0,0 @@ -package timeSliceTest; - -import lsp.LSP; -import lsp.ShipmentAssigner; -import lsp.shipment.LSPShipment; - -public class TimeSliceAssigner implements ShipmentAssigner{ - - private LSP lsp; - - - @Override - public void assignShipment(LSPShipment shipment) { - for(LogisticsSolution solution ) { - - } - - } - - @Override - public void setLSP(LSP lsp) { - this.lsp = lsp; - } - - @Override - public LSP getLSP() { - return lsp; - } - -} diff --git a/src/timeSliceTest/TimeSliceCarrierAdapter.java b/src/timeSliceTest/TimeSliceCarrierAdapter.java deleted file mode 100644 index dd7f84bd34e..00000000000 --- a/src/timeSliceTest/TimeSliceCarrierAdapter.java +++ /dev/null @@ -1,168 +0,0 @@ -package timeSliceTest; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.events.handler.EventHandler; - -import lsp.LogisticsSolutionElement; -import lsp.functions.Info; -import lsp.resources.CarrierResource; -import lsp.resources.Resource; -import lsp.tracking.SimulationTracker; - -public class TimeSliceCarrierAdapter implements CarrierResource{ - - private Idid; - private Carrier carrier; - private Id locationLinkId; - private ArrayList clientElements; - private TimeSliceScheduler timeSliceScheduler; - private Network network; - private Collection eventHandlers; - private Collection infos; - private Collection trackers; - private EventsManager eventsManager; - - public static class Builder { - - private Idid; - private Carrier carrier; - private Id locationLinkId; - private ArrayList clientElements; - private TimeSliceScheduler timeSliceScheduler; - private Network network; - - public static Builder newInstance(Id id, Network network){ - return new Builder(id,network); - } - - private Builder(Id id, Network network){ - this.id = id; - this.clientElements = new ArrayList (); - this.network = network; - } - - public Builder setLocationLinkId(Id locationLinkId){ - this.locationLinkId = locationLinkId; - return this; - } - - public Builder setCarrier(Carrier carrier){ - this.carrier = carrier; - return this; - } - - - public Builder setTimeSliceScheduler(TimeSliceScheduler timeSliceHandler){ - this.timeSliceScheduler = timeSliceHandler; - return this; - } - - public TimeSliceCarrierAdapter build(){ - return new TimeSliceCarrierAdapter(this); - } - - } - - private TimeSliceCarrierAdapter(TimeSliceCarrierAdapter.Builder builder){ - this.id = builder.id; - this.locationLinkId = builder.locationLinkId; - this.timeSliceScheduler = builder.timeSliceScheduler; - this.clientElements = builder.clientElements; - this.carrier = builder.carrier; - this.network = builder.network; - this.eventHandlers = new ArrayList(); - this.infos = new ArrayList(); - this.trackers = new ArrayList(); - } - - @Override - public Id getId() { - return id; - } - - @Override - public Id getStartLinkId() { - Id depotLinkId = null; - for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()){ - if(depotLinkId == null || depotLinkId == vehicle.getLocation()){ - depotLinkId = vehicle.getLocation(); - } - - } - - return depotLinkId; - } - - @Override - public Class getClassOfResource() { - return carrier.getClass(); - } - - @Override - public Id getEndLinkId() { - Id depotLinkId = null; - for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()){ - if(depotLinkId == null || depotLinkId == vehicle.getLocation()){ - depotLinkId = vehicle.getLocation(); - } - - } - - return depotLinkId; - } - - @Override - public Collection getClientElements() { - return clientElements; - } - - @Override - public void schedule(int bufferTime) { - timeSliceScheduler.scheduleShipments(this, bufferTime); - } - - @Override - public Collection getEventHandlers() { - return eventHandlers; - } - - @Override - public Collection getInfos() { - return infos; - } - - @Override - public void addSimulationTracker(SimulationTracker tracker) { - this.trackers.add(tracker); - this.eventHandlers.addAll(tracker.getEventHandlers()); - this.infos.addAll(tracker.getInfos()); - } - - @Override - public Collection getSimulationTrackers() { - return trackers; - } - - @Override - public void setEventsManager(EventsManager eventsManager) { - this.eventsManager = eventsManager; - } - - @Override - public Carrier getCarrier() { - return carrier; - } - - public Network getNetwork() { - return network; - } - -} diff --git a/src/timeSliceTest/TimeSliceScheduler.java b/src/timeSliceTest/TimeSliceScheduler.java deleted file mode 100644 index 9b506d4c680..00000000000 --- a/src/timeSliceTest/TimeSliceScheduler.java +++ /dev/null @@ -1,295 +0,0 @@ -package timeSliceTest; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; - -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierPlan; -import org.matsim.contrib.freight.carrier.CarrierService; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.ScheduledTour; -import org.matsim.contrib.freight.carrier.Tour; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.contrib.freight.carrier.Tour.Leg; -import org.matsim.contrib.freight.carrier.Tour.TourElement; -import org.matsim.contrib.freight.jsprit.MatsimJspritFactory; -import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; -import org.matsim.contrib.freight.jsprit.NetworkRouter; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.box.Jsprit; -import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; -import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import com.graphhopper.jsprit.core.util.Solutions; - -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.ShipmentTuple; -import lsp.resources.CarrierResource; -import lsp.resources.Resource; -import lsp.resources.ResourceScheduler; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.ScheduledShipmentLoad; -import lsp.shipment.ScheduledShipmentTransport; -import lsp.shipment.ScheduledShipmentUnload; -import lsp.usecase.CollectionServiceEventHandler; -import lsp.usecase.CollectionTourEndEventHandler; - - - - -public class TimeSliceScheduler extends ResourceScheduler{ - - class LSPCarrierPair{ - private ShipmentTuple tuple; - private CarrierService service; - - public LSPCarrierPair(ShipmentTuple tuple, CarrierService service){ - this.tuple = tuple; - this.service = service; - } - } - - private Carrier carrier; - private HashMap,Carrier> auxiliaryCarriers; - private TimeSliceCarrierAdapter adapter; - private ArrayListpairs; - - - @Override - protected void initializeValues(Resource resource) { - this.pairs = new ArrayList(); - this.auxiliaryCarriers = new HashMap<>(); - if(resource.getClass() == TimeSliceCarrierAdapter.class){ - this.adapter = (TimeSliceCarrierAdapter) resource; - this.carrier = adapter.getCarrier(); - this.carrier.getServices().clear(); - this.carrier.getShipments().clear(); - this.carrier.getPlans().clear(); - this.carrier.setSelectedPlan(null); - } - } - - @Override - protected void scheduleResource() { - int i = 0; - for(ShipmentTuple tupleToBeAssigned: shipments){ - CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); - if(auxiliaryCarriers.containsKey(tupleToBeAssigned.getShipment().getSolutionId())) { - auxiliaryCarriers.get(tupleToBeAssigned.getShipment().getSolutionId()).getServices().add(carrierService); - } - else { - Carrier auxiliaryCarrier = createAuxiliaryCarrier(Id.create("AuxiliaryCarrier_"+i, Carrier.class), tupleToBeAssigned); - i++; - auxiliaryCarrier.getServices().add(carrierService); - auxiliaryCarriers.put(tupleToBeAssigned.getShipment().getSolutionId(), auxiliaryCarrier); - } - } - - for(Carrier carrier : auxiliaryCarriers.values()) { - routeCarrier(carrier); - } - - ArrayList scheduledTours = new ArrayList<>(); - for(Carrier carrier : auxiliaryCarriers.values()) { - scheduledTours.addAll(carrier.getSelectedPlan().getScheduledTours()); - } - - CarrierPlan plan = new CarrierPlan(carrier,scheduledTours); - carrier.setSelectedPlan(plan); - } - - private CarrierService convertToCarrierService(ShipmentTuple tuple){ - Id serviceId = Id.create(tuple.getShipment().getId().toString(), CarrierService.class); - CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, tuple.getShipment().getFromLinkId()); - builder.setServiceStartTimeWindow(tuple.getShipment().getStartTimeWindow()); - builder.setCapacityDemand(tuple.getShipment().getCapacityDemand()); - builder.setServiceDuration(tuple.getShipment().getServiceTime()); - CarrierService service = builder.build(); - pairs.add(new LSPCarrierPair(tuple, service)); - return service; - } - - private Carrier createAuxiliaryCarrier(Id id, ShipmentTuple tupleToBeAssigned) { - Carrier auxiliaryCarrier = CarrierImpl.newInstance(id); - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - - for(CarrierVehicleType vehicleType : carrier.getCarrierCapabilities().getVehicleTypes()) { - capabilitiesBuilder.addType(vehicleType); - } - - CarrierVehicle latestAvailable = carrier.getCarrierCapabilities().getCarrierVehicles().iterator().next(); - double smallestDifference = Double.MAX_VALUE; - - for(CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles()) { - if(vehicle.getEarliestStartTime() < tupleToBeAssigned.getTime() && vehicle.getLatestEndTime() > tupleToBeAssigned.getTime()) { - double timeDifference = tupleToBeAssigned.getTime() - vehicle.getEarliestStartTime(); - if(timeDifference < smallestDifference) { - smallestDifference = timeDifference; - latestAvailable = vehicle; - } - } - } - - capabilitiesBuilder.addVehicle(latestAvailable); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - auxiliaryCarrier.setCarrierCapabilities(capabilitiesBuilder.build()); - return auxiliaryCarrier; - } - - private void routeCarrier(Carrier carrier){ - VehicleRoutingProblem.Builder vrpBuilder = MatsimJspritFactory.createRoutingProblemBuilder(carrier, adapter.getNetwork()); - NetworkBasedTransportCosts.Builder tpcostsBuilder = NetworkBasedTransportCosts.Builder.newInstance(adapter.getNetwork(), carrier.getCarrierCapabilities().getVehicleTypes()); - NetworkBasedTransportCosts netbasedTransportcosts = tpcostsBuilder.build(); - vrpBuilder.setRoutingCost(netbasedTransportcosts); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp); - - Collection solutions = algorithm.searchSolutions(); - - VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - - CarrierPlan plan = MatsimJspritFactory.createPlan(carrier, solution); - NetworkRouter.routePlan(plan, netbasedTransportcosts); - carrier.setSelectedPlan(plan); - } - - - - @Override - protected void updateShipments() { - for(ShipmentTuple tuple : shipments) { - updateShipment(tuple); - } - } - - private void updateShipment(ShipmentTuple tuple){ - - for(ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()){ - Tour tour = scheduledTour.getTour(); - for(TourElement element: tour.getTourElements()){ - if(element instanceof Tour.ServiceActivity){ - Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; - LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); - for(LSPCarrierPair pair : pairs){ - if(pair.tuple == carrierPair.tuple && pair.service.getId() == carrierPair.service.getId()){ - addShipmentLoadElement(tuple, tour, serviceActivity); - addShipmentTransportElement(tuple, tour, serviceActivity); - addShipmentUnloadElement(tuple, tour, serviceActivity); - addCollectionTourEndEventHandler(pair.service, tuple, adapter); - addCollectionServiceEventHandler(pair.service, tuple, adapter); - } - } - } - } - } - } - - private void addShipmentLoadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ - ScheduledShipmentLoad.Builder builder = ScheduledShipmentLoad.Builder.newInstance(); - builder.setResourceId(adapter.getId()); - for(LogisticsSolutionElement element : adapter.getClientElements()){ - if(element.getIncomingShipments().getShipments().contains(tuple)){ - builder.setLogisticsSolutionElement(element); - } - } - int serviceIndex = tour.getTourElements().indexOf(serviceActivity); - Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex-1); - double startTimeOfLoading = legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime(); - builder.setStartTime(startTimeOfLoading); - builder.setEndTime(startTimeOfLoading + tuple.getShipment().getServiceTime()); - builder.setCarrierId(carrier.getId()); - builder.setLinkId(serviceActivity.getLocation()); - builder.setCarrierService(serviceActivity.getService()); - ScheduledShipmentLoad load = builder.build(); - String idString = load.getResourceId() + "" + load.getSolutionElement().getId() + "" + load.getElementType(); - Id id = Id.create(idString, AbstractShipmentPlanElement.class); - tuple.getShipment().getSchedule().addPlanElement(id, load); - } - - private void addCollectionServiceEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ - for(LogisticsSolutionElement element : adapter.getClientElements()){ - if(element.getIncomingShipments().getShipments().contains(tuple)){ - CollectionServiceEventHandler endHandler = new CollectionServiceEventHandler(carrierService, tuple.getShipment(), element, resource); - tuple.getShipment().getEventHandlers().add(endHandler); - break; - } - } - } - - private void addCollectionTourEndEventHandler(CarrierService carrierService, ShipmentTuple tuple, CarrierResource resource){ - for(LogisticsSolutionElement element : adapter.getClientElements()){ - if(element.getIncomingShipments().getShipments().contains(tuple)){ - CollectionTourEndEventHandler handler = new CollectionTourEndEventHandler(carrierService, tuple.getShipment(), element, resource); - tuple.getShipment().getEventHandlers().add(handler); - break; - } - } - } - - private void addShipmentTransportElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ - ScheduledShipmentTransport.Builder builder = ScheduledShipmentTransport.Builder.newInstance(); - builder.setResourceId(adapter.getId()); - for(LogisticsSolutionElement element : adapter.getClientElements()){ - if(element.getIncomingShipments().getShipments().contains(tuple)){ - builder.setLogisticsSolutionElement(element); - } - } - int serviceIndex = tour.getTourElements().indexOf(serviceActivity); - Leg legAfterService = (Leg) tour.getTourElements().get(serviceIndex+1); - double startTimeOfTransport = legAfterService.getExpectedDepartureTime(); - builder.setStartTime(startTimeOfTransport); - Leg lastLeg = (Leg) tour.getTourElements().get(tour.getTourElements().size()-1); - double endTimeOfTransport = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); - builder.setEndTime(endTimeOfTransport); - builder.setCarrierId(carrier.getId()); - builder.setFromLinkId(serviceActivity.getLocation()); - builder.setToLinkId(tour.getEndLinkId()); - builder.setCarrierService(serviceActivity.getService()); - ScheduledShipmentTransport transport = builder.build(); - String idString = transport.getResourceId() + "" + transport.getSolutionElement().getId() + "" + transport.getElementType(); - Id id = Id.create(idString, AbstractShipmentPlanElement.class); - tuple.getShipment().getSchedule().addPlanElement(id, transport); - } - - private void addShipmentUnloadElement(ShipmentTuple tuple, Tour tour, Tour.ServiceActivity serviceActivity){ - ScheduledShipmentUnload.Builder builder = ScheduledShipmentUnload.Builder.newInstance(); - builder.setResourceId(adapter.getId()); - for(LogisticsSolutionElement element : adapter.getClientElements()){ - if(element.getIncomingShipments().getShipments().contains(tuple)){ - builder.setLogisticsSolutionElement(element); - } - } - Leg lastLeg = (Leg) tour.getTourElements().get(tour.getTourElements().size()-1); - double startTime = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); - builder.setStartTime(startTime); - builder.setEndTime(startTime + getUnloadEndTime(tour)); - builder.setCarrierId(carrier.getId()); - builder.setLinkId(tour.getEndLinkId()); - builder.setCarrierService(serviceActivity.getService()); - ScheduledShipmentUnload unload = builder.build(); - String idString = unload.getResourceId() + "" + unload.getSolutionElement().getId() + "" + unload.getElementType(); - Id id = Id.create(idString, AbstractShipmentPlanElement.class); - tuple.getShipment().getSchedule().addPlanElement(id, unload); - } - - private double getUnloadEndTime(Tour tour){ - double unloadEndTime = 0; - for(TourElement element: tour.getTourElements()){ - if(element instanceof Tour.ServiceActivity){ - Tour.ServiceActivity serviceActivity = (Tour.ServiceActivity) element; - unloadEndTime = unloadEndTime + serviceActivity.getDuration(); - } - } - return unloadEndTime; - } - -} diff --git a/src/timeSliceTest/TimeSliceSolutionScheduler.java b/src/timeSliceTest/TimeSliceSolutionScheduler.java deleted file mode 100644 index 284e51ddc77..00000000000 --- a/src/timeSliceTest/TimeSliceSolutionScheduler.java +++ /dev/null @@ -1,52 +0,0 @@ -package timeSliceTest; - -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.SolutionScheduler; -import lsp.shipment.LSPShipment; - -public class TimeSliceSolutionScheduler implements SolutionScheduler{ - - private LSP lsp; - private int bufferTime; - - - @Override - public void scheduleSolutions() { - // TODO Auto-generated method stub - - } - - @Override - public void setLSP(LSP lsp) { - this.lsp = lsp; - } - - @Override - public void setBufferTime(int bufferTime) { - this.bufferTime = bufferTime; - } - - /*Die methode muss anders werden. Wichtig ist der Zeitpunkt in der Reihenfolge. Der entspricht dem Abfahrtszeitpunkt aus der - * entsprechenden Info. Dann wird der auxiliaryCarrier entsprechend zugeordnet - */ - private void insertShipmentsAtBeginning() { - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - LogisticsSolutionElement firstElement = getFirstElement(solution); - for(LSPShipment shipment : solution.getShipments() ) { - firstElement.getIncomingShipments().addShipment(shipment.getStartTimeWindow().getStart(), shipment); - } - } - } - - private LogisticsSolutionElement getFirstElement(LogisticsSolution solution){ - for(LogisticsSolutionElement element : solution.getSolutionElements()){ - if(element.getPreviousElement() == null){ - return element; - } - } - return null; - } - -} From 32f9e8f578cf788d0df97027793d1dac28e297d5 Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 18:32:56 +0200 Subject: [PATCH 0050/1340] replace \ in file paths with / --- examples/example/LSPReplanning/ExampleLSPReplanning.java | 4 ++-- examples/example/LSPScoring/ExampleLSPScoring.java | 4 ++-- .../example/initialPlans/ExampleSchedulingOfInitialPlan.java | 2 +- .../initialPlans/ExampleSchedulingOfTransportChain.java | 2 +- examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java | 4 ++-- .../example/mobsimExamples/ExampleMobsimOfTransportChain.java | 4 ++-- .../ExampleCheckRequirementsOfAssigner.java | 2 +- .../ExampleCheckRequirementsOfOfferTransferrer.java | 2 +- .../example/simulationTrackers/ExampleSimulationTrackers.java | 4 ++-- src/main/java/lsp/usecase/LSPShipmentMaker.java | 2 +- src/main/java/lsp/usecase/NetworkMaker.java | 2 +- src/test/java/adapterTests/CollectionAdapterTest.java | 4 ++-- src/test/java/adapterTests/DistributionAdapterTest.java | 4 ++-- src/test/java/adapterTests/MainRunAdapterTest.java | 2 +- src/test/java/lspCreationTests/CollectionLSPCreationTest.java | 2 +- src/test/java/lspCreationTests/CompleteLSPCreationTest.java | 2 +- src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java | 4 ++-- src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java | 4 ++-- src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java | 4 ++-- src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java | 4 ++-- src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java | 4 ++-- .../MultipleIterationsCollectionLSPMobsimTest.java | 4 ++-- .../MultipleIterationsFirstReloadLSPMobsimTest.java | 4 ++-- .../MultipleIterationsMainRunLSPMobsimTest.java | 4 ++-- .../MultipleIterationsSecondReloadLSPMobsimTest.java | 4 ++-- .../MultipleItreationsCompleteLSPMobsimTest.java | 4 ++-- .../MultipleShipmentsCollectionLSPMobsimTest.java | 4 ++-- .../MultipleShipmentsCompleteLSPMobsimTest.java | 4 ++-- .../MultipleShipmentsFirstReloadLSPMobsimTest.java | 4 ++-- .../lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java | 4 ++-- .../MultipleShipmentsSecondReloadLSPMobsimTest.java | 4 ++-- .../RepeatedMultipleShipmentsCompleteLSPMobsimTest.java | 4 ++-- src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java | 4 ++-- src/test/java/lspPlanTests/CollectionLSPPlanTest.java | 2 +- src/test/java/lspPlanTests/CompleteLSPPlanTest.java | 2 +- .../java/lspReplanningTests/CollectionLSPReplanningTest.java | 4 ++-- src/test/java/lspScoringTests/CollectionLSPScoringTest.java | 4 ++-- .../MultipleIterationsCollectionLSPScoringTest.java | 4 ++-- .../CollectionLSPShipmentAssigmentTest.java | 2 +- .../CompleteLSPShipmentAssignerTest.java | 2 +- .../java/lspShipmentTest/CollectionShipmentBuilderTest.java | 2 +- .../java/lspShipmentTest/CompleteShipmentBuilderTest.java | 2 +- .../java/lspShipmentTest/DistributionShipmentBuilderTest.java | 2 +- .../requirementsCheckerTests/AssignerRequirementsTest.java | 2 +- .../requirementsCheckerTests/TransferrerRequirementsTest.java | 2 +- src/test/java/solutionElementTests/CollectionElementTest.java | 2 +- .../java/solutionElementTests/DistributionElementTest.java | 2 +- src/test/java/solutionElementTests/MainRunElementTest.java | 2 +- src/test/java/solutionTests/CollectionSolutionTest.java | 2 +- src/test/java/solutionTests/CompleteSolutionTest.java | 2 +- 50 files changed, 77 insertions(+), 77 deletions(-) diff --git a/examples/example/LSPReplanning/ExampleLSPReplanning.java b/examples/example/LSPReplanning/ExampleLSPReplanning.java index b2531c475f5..cf3f346519a 100644 --- a/examples/example/LSPReplanning/ExampleLSPReplanning.java +++ b/examples/example/LSPReplanning/ExampleLSPReplanning.java @@ -173,7 +173,7 @@ public static void main(String[]args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments @@ -198,7 +198,7 @@ public static void main(String[]args) { config.controler().setFirstIteration(0); config.controler().setLastIteration(4); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); System.out.println("Shipments delivered today:"); diff --git a/examples/example/LSPScoring/ExampleLSPScoring.java b/examples/example/LSPScoring/ExampleLSPScoring.java index 96a83eeecfe..df3421124b1 100644 --- a/examples/example/LSPScoring/ExampleLSPScoring.java +++ b/examples/example/LSPScoring/ExampleLSPScoring.java @@ -190,7 +190,7 @@ public static void main(String []args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments @@ -217,7 +217,7 @@ public static void main(String []args) { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); System.out.println("The tip of all customers was: " + lsp.getSelectedPlan().getScore()); diff --git a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java index 465fd100b82..1dc786a5516 100644 --- a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java +++ b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java @@ -161,7 +161,7 @@ public static void main(String [] args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments diff --git a/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java b/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java index 515c6629a00..10d309c4911 100644 --- a/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java +++ b/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java @@ -328,7 +328,7 @@ public static void main (String [] args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments diff --git a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java index 96c4d08d160..9ab75cbba68 100644 --- a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java +++ b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java @@ -165,7 +165,7 @@ public static void main (String[]args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments @@ -191,7 +191,7 @@ public static void main (String[]args) { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); for(LSPShipment shipment : lsp.getShipments()) { diff --git a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java index f7e792760de..3ae5c7f6987 100644 --- a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java +++ b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java @@ -330,7 +330,7 @@ public static void main (String[]args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments @@ -356,7 +356,7 @@ public static void main (String[]args) { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); for(LSPShipment shipment : lsp.getShipments()) { diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java index b4a8d7ec4bb..5ad833159e8 100644 --- a/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java +++ b/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java @@ -203,7 +203,7 @@ public static void main (String[]args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java index ded16d1ebff..2ed38e3740a 100644 --- a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java +++ b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java @@ -201,7 +201,7 @@ public static void main (String[]args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and demand objects diff --git a/examples/example/simulationTrackers/ExampleSimulationTrackers.java b/examples/example/simulationTrackers/ExampleSimulationTrackers.java index bacdc941059..e03bc74dc3f 100644 --- a/examples/example/simulationTrackers/ExampleSimulationTrackers.java +++ b/examples/example/simulationTrackers/ExampleSimulationTrackers.java @@ -177,7 +177,7 @@ public static void main (String [] args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); Network network = scenario.getNetwork(); //Create LSP and shipments @@ -204,7 +204,7 @@ public static void main (String [] args) { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); //Retrieve cost info from lsp diff --git a/src/main/java/lsp/usecase/LSPShipmentMaker.java b/src/main/java/lsp/usecase/LSPShipmentMaker.java index 164ac62abac..997bfa78062 100644 --- a/src/main/java/lsp/usecase/LSPShipmentMaker.java +++ b/src/main/java/lsp/usecase/LSPShipmentMaker.java @@ -22,7 +22,7 @@ public static void main (String[]args){ Network network = NetworkUtils.createNetwork(); MatsimNetworkReader reader = new MatsimNetworkReader(network); - reader.readFile("D:\\Working_Copies_Dissertation\\Code_Dissertation\\logistics\\input\\lsp\\network\\2regions.xml"); + reader.readFile("D:/Working_Copies_Dissertation/Code_Dissertation/logistics/input/lsp/network/2regions.xml"); Random random = new Random(1); ArrayList shipments = new ArrayList(); diff --git a/src/main/java/lsp/usecase/NetworkMaker.java b/src/main/java/lsp/usecase/NetworkMaker.java index 1dad0b279a8..54d8d18bff6 100644 --- a/src/main/java/lsp/usecase/NetworkMaker.java +++ b/src/main/java/lsp/usecase/NetworkMaker.java @@ -137,7 +137,7 @@ public static void main (String[]args){ network.addLink(link2); NetworkWriter writer = new NetworkWriter(network); - writer.write("D:\\Transport_Chains\\workspace_TransportChains\\logistics\\input\\lsp\\network\\2regions.xml"); + writer.write("D:/Transport_Chains/workspace_TransportChains/logistics/input/lsp/network/2regions.xml"); } diff --git a/src/test/java/adapterTests/CollectionAdapterTest.java b/src/test/java/adapterTests/CollectionAdapterTest.java index 9337921796e..e3aa9b7abff 100644 --- a/src/test/java/adapterTests/CollectionAdapterTest.java +++ b/src/test/java/adapterTests/CollectionAdapterTest.java @@ -32,7 +32,7 @@ public class CollectionAdapterTest { //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. - //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. + //Man kann sie deshalb ja extra au�erhalb des Builders einsetzen. private Network network; private CollectionCarrierScheduler scheduler; @@ -48,7 +48,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/adapterTests/DistributionAdapterTest.java b/src/test/java/adapterTests/DistributionAdapterTest.java index e142deb0e5b..0e35b2a4239 100644 --- a/src/test/java/adapterTests/DistributionAdapterTest.java +++ b/src/test/java/adapterTests/DistributionAdapterTest.java @@ -33,7 +33,7 @@ public class DistributionAdapterTest { //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. - //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. + //Man kann sie deshalb ja extra au�erhalb des Builders einsetzen. private Network network; private DistributionCarrierScheduler scheduler; @@ -49,7 +49,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); scheduler = new DistributionCarrierScheduler(); diff --git a/src/test/java/adapterTests/MainRunAdapterTest.java b/src/test/java/adapterTests/MainRunAdapterTest.java index 79e7c7ae410..1a998f51536 100644 --- a/src/test/java/adapterTests/MainRunAdapterTest.java +++ b/src/test/java/adapterTests/MainRunAdapterTest.java @@ -48,7 +48,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); diff --git a/src/test/java/lspCreationTests/CollectionLSPCreationTest.java b/src/test/java/lspCreationTests/CollectionLSPCreationTest.java index bf13579898a..13ea4594b62 100644 --- a/src/test/java/lspCreationTests/CollectionLSPCreationTest.java +++ b/src/test/java/lspCreationTests/CollectionLSPCreationTest.java @@ -55,7 +55,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/lspCreationTests/CompleteLSPCreationTest.java b/src/test/java/lspCreationTests/CompleteLSPCreationTest.java index 9844d4c8c01..f47d42475e7 100644 --- a/src/test/java/lspCreationTests/CompleteLSPCreationTest.java +++ b/src/test/java/lspCreationTests/CompleteLSPCreationTest.java @@ -57,7 +57,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); diff --git a/src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java b/src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java index b6b9e937b5e..c3ed16a2caf 100644 --- a/src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/CollectionLSPMobsimTest.java @@ -65,7 +65,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); @@ -174,7 +174,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java index 37b2a0a5d52..0451c965885 100644 --- a/src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/CompleteLSPMobsimTest.java @@ -72,7 +72,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -325,7 +325,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java index 12d73283e1c..3e47e93091d 100644 --- a/src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -74,7 +74,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -220,7 +220,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java b/src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java index 37a48af8e69..d491e3b7bd3 100644 --- a/src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MainRunLSPMobsimTest.java @@ -70,7 +70,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -258,7 +258,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } @Test diff --git a/src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java index 31110070860..6770c1a3b14 100644 --- a/src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -70,7 +70,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); @@ -198,7 +198,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } @Test diff --git a/src/test/java/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java index ac59ceb03d4..cf723f6c1c5 100644 --- a/src/test/java/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java @@ -69,7 +69,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); @@ -178,7 +178,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1 + new Random().nextInt(10)); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java index bbfdbcc5ce3..139b3e519bb 100644 --- a/src/test/java/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java @@ -75,7 +75,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -222,7 +222,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1 + new Random().nextInt(10)); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java index c7d4848cb13..bd99299c10f 100644 --- a/src/test/java/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java @@ -71,7 +71,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -260,7 +260,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1 + new Random().nextInt(10)); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } @Test diff --git a/src/test/java/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java index 736ef448732..43e50291aa7 100644 --- a/src/test/java/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleIterationsSecondReloadLSPMobsimTest.java @@ -73,7 +73,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -285,7 +285,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1 + new Random().nextInt(10)); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java index f3b995d1982..fe53c2683bc 100644 --- a/src/test/java/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleItreationsCompleteLSPMobsimTest.java @@ -72,7 +72,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -327,7 +327,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1 + new Random().nextInt(10)); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java index 46c24b0b9db..2c193108c3f 100644 --- a/src/test/java/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java @@ -66,7 +66,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); @@ -175,7 +175,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java index 8cd2c753b20..872af4623ff 100644 --- a/src/test/java/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java @@ -72,7 +72,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -327,7 +327,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1 + new Random().nextInt(10)); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java index e1678963ff1..68eba4660d2 100644 --- a/src/test/java/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java @@ -75,7 +75,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -222,7 +222,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java index 167ef38d68d..71928fbec36 100644 --- a/src/test/java/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java @@ -71,7 +71,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -260,7 +260,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } @Test diff --git a/src/test/java/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java index be84fbe2b71..630e4e3f163 100644 --- a/src/test/java/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/MultipleShipmentsSecondReloadLSPMobsimTest.java @@ -73,7 +73,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -285,7 +285,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(4); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java b/src/test/java/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java index 8ecac22d6dc..35f5b01d2b0 100644 --- a/src/test/java/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java @@ -72,7 +72,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -327,7 +327,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java b/src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java index a41db6a4452..63a2499d8f2 100644 --- a/src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java +++ b/src/test/java/lspMobsimTests/SecondReloadLSPMobsimTest.java @@ -72,7 +72,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); @@ -284,7 +284,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspPlanTests/CollectionLSPPlanTest.java b/src/test/java/lspPlanTests/CollectionLSPPlanTest.java index b04e4a1c162..8b4e5dfd9c5 100644 --- a/src/test/java/lspPlanTests/CollectionLSPPlanTest.java +++ b/src/test/java/lspPlanTests/CollectionLSPPlanTest.java @@ -44,7 +44,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/lspPlanTests/CompleteLSPPlanTest.java b/src/test/java/lspPlanTests/CompleteLSPPlanTest.java index 3570dc3fc58..d1114a1aa56 100644 --- a/src/test/java/lspPlanTests/CompleteLSPPlanTest.java +++ b/src/test/java/lspPlanTests/CompleteLSPPlanTest.java @@ -49,7 +49,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); diff --git a/src/test/java/lspReplanningTests/CollectionLSPReplanningTest.java b/src/test/java/lspReplanningTests/CollectionLSPReplanningTest.java index 162a43d8665..c9b78d6aaf7 100644 --- a/src/test/java/lspReplanningTests/CollectionLSPReplanningTest.java +++ b/src/test/java/lspReplanningTests/CollectionLSPReplanningTest.java @@ -66,7 +66,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); @@ -184,7 +184,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(1); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspScoringTests/CollectionLSPScoringTest.java b/src/test/java/lspScoringTests/CollectionLSPScoringTest.java index 2e4b42300bf..a3988cd0d4e 100644 --- a/src/test/java/lspScoringTests/CollectionLSPScoringTest.java +++ b/src/test/java/lspScoringTests/CollectionLSPScoringTest.java @@ -74,7 +74,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); @@ -195,7 +195,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(0); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java b/src/test/java/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java index cf52f82c536..98691831444 100644 --- a/src/test/java/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java +++ b/src/test/java/lspScoringTests/MultipleIterationsCollectionLSPScoringTest.java @@ -74,7 +74,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); @@ -198,7 +198,7 @@ public void initialize() { config.controler().setFirstIteration(0); config.controler().setLastIteration(10); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input\\lsp\\network\\2regions.xml"); + config.network().setInputFile("input/lsp/network/2regions.xml"); controler.run(); } diff --git a/src/test/java/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java b/src/test/java/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java index 89f0849c61f..db0fdc02b66 100644 --- a/src/test/java/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java +++ b/src/test/java/lspShipmentAssignmentTests/CollectionLSPShipmentAssigmentTest.java @@ -57,7 +57,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java b/src/test/java/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java index 935b318eab1..e4fdf486572 100644 --- a/src/test/java/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java +++ b/src/test/java/lspShipmentAssignmentTests/CompleteLSPShipmentAssignerTest.java @@ -63,7 +63,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); diff --git a/src/test/java/lspShipmentTest/CollectionShipmentBuilderTest.java b/src/test/java/lspShipmentTest/CollectionShipmentBuilderTest.java index cab6178bded..bbcc3a9ae78 100644 --- a/src/test/java/lspShipmentTest/CollectionShipmentBuilderTest.java +++ b/src/test/java/lspShipmentTest/CollectionShipmentBuilderTest.java @@ -32,7 +32,7 @@ public void initialize(){ Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); ArrayList linkList = new ArrayList(network.getLinks().values()); Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); diff --git a/src/test/java/lspShipmentTest/CompleteShipmentBuilderTest.java b/src/test/java/lspShipmentTest/CompleteShipmentBuilderTest.java index 3386f8b3d4d..e47a8d956da 100644 --- a/src/test/java/lspShipmentTest/CompleteShipmentBuilderTest.java +++ b/src/test/java/lspShipmentTest/CompleteShipmentBuilderTest.java @@ -33,7 +33,7 @@ public void initialize(){ Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); ArrayList linkList = new ArrayList(network.getLinks().values()); this.shipments = new ArrayList(); diff --git a/src/test/java/lspShipmentTest/DistributionShipmentBuilderTest.java b/src/test/java/lspShipmentTest/DistributionShipmentBuilderTest.java index 2d08c411454..149073ec959 100644 --- a/src/test/java/lspShipmentTest/DistributionShipmentBuilderTest.java +++ b/src/test/java/lspShipmentTest/DistributionShipmentBuilderTest.java @@ -34,7 +34,7 @@ public void initialize(){ Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); ArrayList linkList = new ArrayList(network.getLinks().values()); Id distributionLinkId = Id.createLinkId("(14 2) (14 3)"); diff --git a/src/test/java/requirementsCheckerTests/AssignerRequirementsTest.java b/src/test/java/requirementsCheckerTests/AssignerRequirementsTest.java index f3223515b25..ab1b2997ee6 100644 --- a/src/test/java/requirementsCheckerTests/AssignerRequirementsTest.java +++ b/src/test/java/requirementsCheckerTests/AssignerRequirementsTest.java @@ -58,7 +58,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/requirementsCheckerTests/TransferrerRequirementsTest.java b/src/test/java/requirementsCheckerTests/TransferrerRequirementsTest.java index 53ca42d61e8..f03c574a319 100644 --- a/src/test/java/requirementsCheckerTests/TransferrerRequirementsTest.java +++ b/src/test/java/requirementsCheckerTests/TransferrerRequirementsTest.java @@ -58,7 +58,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/solutionElementTests/CollectionElementTest.java b/src/test/java/solutionElementTests/CollectionElementTest.java index f6369504c17..1f2525057ae 100644 --- a/src/test/java/solutionElementTests/CollectionElementTest.java +++ b/src/test/java/solutionElementTests/CollectionElementTest.java @@ -42,7 +42,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/solutionElementTests/DistributionElementTest.java b/src/test/java/solutionElementTests/DistributionElementTest.java index dffc1bca916..0029a5eeabc 100644 --- a/src/test/java/solutionElementTests/DistributionElementTest.java +++ b/src/test/java/solutionElementTests/DistributionElementTest.java @@ -43,7 +43,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); scheduler = new DistributionCarrierScheduler(); diff --git a/src/test/java/solutionElementTests/MainRunElementTest.java b/src/test/java/solutionElementTests/MainRunElementTest.java index f9cfd215d6a..b5bb37230f9 100644 --- a/src/test/java/solutionElementTests/MainRunElementTest.java +++ b/src/test/java/solutionElementTests/MainRunElementTest.java @@ -38,7 +38,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); diff --git a/src/test/java/solutionTests/CollectionSolutionTest.java b/src/test/java/solutionTests/CollectionSolutionTest.java index 28c24ed961e..623227913e1 100644 --- a/src/test/java/solutionTests/CollectionSolutionTest.java +++ b/src/test/java/solutionTests/CollectionSolutionTest.java @@ -43,7 +43,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/solutionTests/CompleteSolutionTest.java b/src/test/java/solutionTests/CompleteSolutionTest.java index 9df359e9434..b59e8b6f772 100644 --- a/src/test/java/solutionTests/CompleteSolutionTest.java +++ b/src/test/java/solutionTests/CompleteSolutionTest.java @@ -52,7 +52,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); CollectionCarrierScheduler collectionScheduler = new CollectionCarrierScheduler(); From 6730dc4034f6c29f5f7ae85af63d603f028e1899 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 23 May 2018 18:35:16 +0200 Subject: [PATCH 0051/1340] Minor changes in pathname of file --- src/test/java/adapterTests/CollectionAdapterTest.java | 4 ++-- src/test/java/adapterTests/DistributionAdapterTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/adapterTests/CollectionAdapterTest.java b/src/test/java/adapterTests/CollectionAdapterTest.java index 9337921796e..e3aa9b7abff 100644 --- a/src/test/java/adapterTests/CollectionAdapterTest.java +++ b/src/test/java/adapterTests/CollectionAdapterTest.java @@ -32,7 +32,7 @@ public class CollectionAdapterTest { //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. - //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. + //Man kann sie deshalb ja extra au�erhalb des Builders einsetzen. private Network network; private CollectionCarrierScheduler scheduler; @@ -48,7 +48,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); scheduler = new CollectionCarrierScheduler(); diff --git a/src/test/java/adapterTests/DistributionAdapterTest.java b/src/test/java/adapterTests/DistributionAdapterTest.java index e142deb0e5b..0e35b2a4239 100644 --- a/src/test/java/adapterTests/DistributionAdapterTest.java +++ b/src/test/java/adapterTests/DistributionAdapterTest.java @@ -33,7 +33,7 @@ public class DistributionAdapterTest { //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. - //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. + //Man kann sie deshalb ja extra au�erhalb des Builders einsetzen. private Network network; private DistributionCarrierScheduler scheduler; @@ -49,7 +49,7 @@ public void initialize() { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input\\lsp\\network\\2regions.xml"); + new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); this.network = scenario.getNetwork(); scheduler = new DistributionCarrierScheduler(); From f5fdd794331eaf6605bebe7f9b6ab2283cc6b15b Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 18:40:58 +0200 Subject: [PATCH 0052/1340] move gitlab-ci.yml up to java 8 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9cfa2e409c7..2fc6456ddda 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: maven:3-jdk-7 +image: maven:3-jdk-8 build: script: "mvn install -B --fail-at-end -B -Dmaven.test.redirectTestOutputToFile -Dmatsim.preferLocalDtds=true" From 19c5d9860ae0d8e89933bc84d7d6c22ba6b95d7f Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 18:46:15 +0200 Subject: [PATCH 0053/1340] remove non-ascii (and non-utf8) characters --- src/main/java/lsp/LogisticsSolutionElementImpl.java | 2 +- src/main/java/lsp/controler/LSPControlerListener.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/lsp/LogisticsSolutionElementImpl.java b/src/main/java/lsp/LogisticsSolutionElementImpl.java index e798db6741b..d172087fad4 100644 --- a/src/main/java/lsp/LogisticsSolutionElementImpl.java +++ b/src/main/java/lsp/LogisticsSolutionElementImpl.java @@ -16,7 +16,7 @@ public class LogisticsSolutionElementImpl implements LogisticsSolutionElement { private Idid; - //die beiden nicht im Builder. Die können erst in der Solution als ganzes gesetzt werden + //die beiden nicht im Builder. Die koennen erst in der Solution als ganzes gesetzt werden private LogisticsSolutionElement previousElement; private LogisticsSolutionElement nextElement; private Resource resource; diff --git a/src/main/java/lsp/controler/LSPControlerListener.java b/src/main/java/lsp/controler/LSPControlerListener.java index 4dc0f9ab1c6..19e5474884b 100644 --- a/src/main/java/lsp/controler/LSPControlerListener.java +++ b/src/main/java/lsp/controler/LSPControlerListener.java @@ -106,8 +106,8 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) { } - //Hier muss noch die Möglichkeit reinkommen, dass nicht alle LSPs nach jeder Iteration neu planen, sondern nur ein Teil von denen - //Das kann durch ein entsprechendes replanningModule erreicht werden. Hier muss man dann nix ändern + //Hier muss noch die Moeglichkeit reinkommen, dass nicht alle LSPs nach jeder Iteration neu planen, sondern nur ein Teil von denen + //Das kann durch ein entsprechendes replanningModule erreicht werden. Hier muss man dann nix aendern @Override public void notifyReplanning(ReplanningEvent event) { replanningModule.replanLSPs(event); From 7bd3b5c13fa7b29de84c121bf0e36b0f119f205f Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 23 May 2018 18:52:20 +0200 Subject: [PATCH 0054/1340] move examples directory, which contains java sources, into src/main/java/... --- .../LSPReplanning/ExampleLSPReplanning.java | 219 ---------- .../GenericStrategyManagerFactoryImpl.java | 22 - .../LSPReplanning/TomorrowAssigner.java | 37 -- ...morrowShipmentAssignerStrategyFactory.java | 58 --- .../example/LSPScoring/ExampleLSPScoring.java | 228 ----------- .../example/LSPScoring/TipEventHandler.java | 32 -- examples/example/LSPScoring/TipInfo.java | 47 --- examples/example/LSPScoring/TipScorer.java | 43 -- .../LSPScoring/TipSimulationTracker.java | 52 --- .../ExampleSchedulingOfInitialPlan.java | 198 --------- .../ExampleSchedulingOfTransportChain.java | 361 ----------------- .../ExampleMobsimOfSimpleLSP.java | 218 ---------- .../ExampleMobsimOfTransportChain.java | 381 ------------------ .../requirementsChecking/BlueInfo.java | 53 --- .../requirementsChecking/BlueRequirement.java | 19 - .../ExampleCheckRequirementsOfAssigner.java | 239 ----------- ...leCheckRequirementsOfOfferTransferrer.java | 230 ----------- .../requirementsChecking/NonsenseOffer.java | 52 --- .../example/requirementsChecking/RedInfo.java | 54 --- .../requirementsChecking/RedRequirement.java | 19 - .../RequirementsAssigner.java | 49 --- .../RequirementsTransferrer.java | 59 --- .../CollectionServiceHandler.java | 87 ---- .../example/simulationTrackers/CostInfo.java | 50 --- .../simulationTrackers/CostInfoFunction.java | 33 -- .../DistanceAndTimeHandler.java | 81 ---- .../ExampleSimulationTrackers.java | 221 ---------- .../FixedCostFunctionValue.java | 24 -- .../LinearCostFunctionValue.java | 23 -- .../simulationTrackers/LinearCostTracker.java | 108 ----- .../simulationTrackers/TourStartHandler.java | 24 -- examples/examples/ExampleCascadingInfos.java | 5 - 32 files changed, 3326 deletions(-) delete mode 100644 examples/example/LSPReplanning/ExampleLSPReplanning.java delete mode 100644 examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java delete mode 100644 examples/example/LSPReplanning/TomorrowAssigner.java delete mode 100644 examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java delete mode 100644 examples/example/LSPScoring/ExampleLSPScoring.java delete mode 100644 examples/example/LSPScoring/TipEventHandler.java delete mode 100644 examples/example/LSPScoring/TipInfo.java delete mode 100644 examples/example/LSPScoring/TipScorer.java delete mode 100644 examples/example/LSPScoring/TipSimulationTracker.java delete mode 100644 examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java delete mode 100644 examples/example/initialPlans/ExampleSchedulingOfTransportChain.java delete mode 100644 examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java delete mode 100644 examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java delete mode 100644 examples/example/requirementsChecking/BlueInfo.java delete mode 100644 examples/example/requirementsChecking/BlueRequirement.java delete mode 100644 examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java delete mode 100644 examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java delete mode 100644 examples/example/requirementsChecking/NonsenseOffer.java delete mode 100644 examples/example/requirementsChecking/RedInfo.java delete mode 100644 examples/example/requirementsChecking/RedRequirement.java delete mode 100644 examples/example/requirementsChecking/RequirementsAssigner.java delete mode 100644 examples/example/requirementsChecking/RequirementsTransferrer.java delete mode 100644 examples/example/simulationTrackers/CollectionServiceHandler.java delete mode 100644 examples/example/simulationTrackers/CostInfo.java delete mode 100644 examples/example/simulationTrackers/CostInfoFunction.java delete mode 100644 examples/example/simulationTrackers/DistanceAndTimeHandler.java delete mode 100644 examples/example/simulationTrackers/ExampleSimulationTrackers.java delete mode 100644 examples/example/simulationTrackers/FixedCostFunctionValue.java delete mode 100644 examples/example/simulationTrackers/LinearCostFunctionValue.java delete mode 100644 examples/example/simulationTrackers/LinearCostTracker.java delete mode 100644 examples/example/simulationTrackers/TourStartHandler.java delete mode 100644 examples/examples/ExampleCascadingInfos.java diff --git a/examples/example/LSPReplanning/ExampleLSPReplanning.java b/examples/example/LSPReplanning/ExampleLSPReplanning.java deleted file mode 100644 index cf3f346519a..00000000000 --- a/examples/example/LSPReplanning/ExampleLSPReplanning.java +++ /dev/null @@ -1,219 +0,0 @@ -package example.LSPReplanning; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.replanning.GenericStrategyManager; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlan; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.replanning.LSPReplannerImpl; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.resources.Resource; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; - -public class ExampleLSPReplanning { - - public static LSP createLSPWithReplanner(Network network) { - //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - //The Adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - - //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - - LSP lsp = collectionLSPBuilder.build(); - - //Create StrategyManager, insert it in Replanner and add it to the lsp; - GenericStrategyManagerFactoryImpl factory = new GenericStrategyManagerFactoryImpl(); - GenericStrategyManager manager = factory.createStrategyManager(lsp); - LSPReplannerImpl replanner = new LSPReplannerImpl(lsp); - replanner.setStrategyManager(manager); - lsp.setReplanner(replanner); - - return lsp; - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id toLinkId = collectionLinkId; - - //Create five LSPShipments that are located in the left half of the network. - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - public static void main(String[]args) { - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createLSPWithReplanner(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - - //Prepare LSPModule and add the LSP - ArrayList lspList = new ArrayList(); - lspList.add(lsp); - LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - //Start the Mobsim two iterations are necessary for replanning - Controler controler = new Controler(config); - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(4); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input/lsp/network/2regions.xml"); - controler.run(); - - System.out.println("Shipments delivered today:"); - for(LSPShipment shipment : lsp.getSelectedPlan().getSolutions().iterator().next().getShipments()) { - System.out.println(shipment.getId()); - } - - lsp.getShipments().removeAll(lsp.getSelectedPlan().getSolutions().iterator().next().getShipments()); - - System.out.println("Shipments delivered tomorrow:"); - for(LSPShipment shipment : lsp.getShipments()) { - System.out.println(shipment.getId()); - } - - } - - -} diff --git a/examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java b/examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java deleted file mode 100644 index b72d29cad87..00000000000 --- a/examples/example/LSPReplanning/GenericStrategyManagerFactoryImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package example.LSPReplanning; - -import org.matsim.core.replanning.GenericStrategyManager; - -import lsp.LSP; -import lsp.LSPPlan; -import lsp.LSPPlanImpl; -import lsp.ShipmentAssigner; -import lsp.replanning.LSPPlanStrategyManagerFactory; - -public class GenericStrategyManagerFactoryImpl implements LSPPlanStrategyManagerFactory { - - @Override - public GenericStrategyManager createStrategyManager(LSP lsp) { - GenericStrategyManager strategyManager = new GenericStrategyManager(); - ShipmentAssigner tomorrowAssigner = new TomorrowAssigner(); - tomorrowAssigner.setLSP(lsp); - strategyManager.addStrategy(new TomorrowShipmentAssignerStrategyFactory(tomorrowAssigner).createStrategy(), null, 1); - return strategyManager; - } - -} diff --git a/examples/example/LSPReplanning/TomorrowAssigner.java b/examples/example/LSPReplanning/TomorrowAssigner.java deleted file mode 100644 index ca276223736..00000000000 --- a/examples/example/LSPReplanning/TomorrowAssigner.java +++ /dev/null @@ -1,37 +0,0 @@ -package example.LSPReplanning; - -import java.util.Random; - -import lsp.LSP; -import lsp.ShipmentAssigner; -import lsp.shipment.LSPShipment; - -public class TomorrowAssigner implements ShipmentAssigner{ - - private LSP lsp; - private Random random; - - public TomorrowAssigner() { - this.random = new Random(1); - } - - @Override - public void assignShipment(LSPShipment shipment) { - boolean assignToday = random.nextBoolean(); - if(assignToday) { - lsp.getSelectedPlan().getSolutions().iterator().next().assignShipment(shipment); - } - } - - @Override - public void setLSP(LSP lsp) { - this.lsp = lsp; - - } - - @Override - public LSP getLSP() { - return lsp; - } - -} diff --git a/examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java b/examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java deleted file mode 100644 index 34c9654899f..00000000000 --- a/examples/example/LSPReplanning/TomorrowShipmentAssignerStrategyFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -package example.LSPReplanning; - -import java.util.Collection; - -import org.matsim.core.replanning.GenericPlanStrategy; -import org.matsim.core.replanning.GenericPlanStrategyImpl; -import org.matsim.core.replanning.ReplanningContext; -import org.matsim.core.replanning.modules.GenericPlanStrategyModule; -import org.matsim.core.replanning.selectors.BestPlanSelector; - -import lsp.LSP; -import lsp.LSPPlan; -import lsp.LSPPlanImpl; -import lsp.ShipmentAssigner; -import lsp.shipment.LSPShipment; - -public class TomorrowShipmentAssignerStrategyFactory { - - private ShipmentAssigner assigner; - - public TomorrowShipmentAssignerStrategyFactory(ShipmentAssigner assigner) { - this.assigner = assigner; - } - - public GenericPlanStrategy createStrategy(){ - GenericPlanStrategyImpl strategy = new GenericPlanStrategyImpl( new BestPlanSelector()); - - GenericPlanStrategyModule tomorrowModule = new GenericPlanStrategyModule() { - - @Override - public void prepareReplanning(ReplanningContext replanningContext) { - // TODO Auto-generated method stub - - } - - @Override - public void handlePlan(LSPPlan plan) { - plan.setAssigner(assigner); - LSP lsp = assigner.getLSP(); - Collection shipments = lsp.getShipments(); - for(LSPShipment shipment : shipments) { - assigner.assignShipment(shipment); - } - } - - @Override - public void finishReplanning() { - // TODO Auto-generated method stub - - } - - }; - - strategy.addStrategyModule(tomorrowModule); - return strategy; - } - -} diff --git a/examples/example/LSPScoring/ExampleLSPScoring.java b/examples/example/LSPScoring/ExampleLSPScoring.java deleted file mode 100644 index df3421124b1..00000000000 --- a/examples/example/LSPScoring/ExampleLSPScoring.java +++ /dev/null @@ -1,228 +0,0 @@ -package example.LSPScoring; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionImpl; -import lsp.functions.InfoFunctionValue; -import lsp.functions.InfoFunctionValueImpl; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.resources.Resource; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; - -/* Example for customized scoring. Each customer that is visited will give a random tip between zero and five - * - * - */ - - -public class ExampleLSPScoring { - - public static LSP createLSPWithScorer(Network network) { - - //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - //The Adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - - //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - - LSP lsp = collectionLSPBuilder.build(); - - //Create EventHandler for the SimulationTracker which the scorer needs - TipEventHandler handler = new TipEventHandler(); - - //Create Info for the SimulationTracker which the scorer needs - InfoFunction function = new InfoFunctionImpl(); - TipInfo info = new TipInfo(function); - - //Create SimulationTracker for the information that the Scorer needs - TipSimulationTracker tracker = new TipSimulationTracker(handler,info); - //add SimulationTracker to the Resource - collectionAdapter.addSimulationTracker(tracker); - - //Create the Scorer and add it to the lsp - TipScorer scorer = new TipScorer(lsp, tracker); - lsp.setScorer(scorer); - - return lsp; - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id toLinkId = collectionLinkId; - - //Create five LSPShipments that are located in the left half of the network. - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - public static void main(String []args) { - - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createLSPWithScorer(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - //schedule the LSP with the shipments and according to the scheduler of the Resource - lsp.scheduleSoultions(); - - //Prepare LSPModule and add the LSP - ArrayList lspList = new ArrayList(); - lspList.add(lsp); - LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - //Start the Mobsim one iteration is sufficient for scoring - Controler controler = new Controler(config); - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input/lsp/network/2regions.xml"); - controler.run(); - - System.out.println("The tip of all customers was: " + lsp.getSelectedPlan().getScore()); - - } - - -} diff --git a/examples/example/LSPScoring/TipEventHandler.java b/examples/example/LSPScoring/TipEventHandler.java deleted file mode 100644 index a95e4dcfdc4..00000000000 --- a/examples/example/LSPScoring/TipEventHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package example.LSPScoring; - -import java.util.Random; - -import lsp.events.ServiceEndEvent; -import lsp.events.ServiceEndEventHandler; - -public class TipEventHandler implements ServiceEndEventHandler{ - - private double tipSum; - private Random tipRandom; - - public TipEventHandler() { - tipRandom = new Random(1); - tipSum = 0; - } - - @Override - public void reset(int iteration) { - tipSum = 0; - } - - @Override - public void handleEvent(ServiceEndEvent event) { - double tip = tipRandom.nextDouble() * 5; - tipSum += tip; - } - - public double getTip() { - return tipSum; - } -} diff --git a/examples/example/LSPScoring/TipInfo.java b/examples/example/LSPScoring/TipInfo.java deleted file mode 100644 index 2692f2ed676..00000000000 --- a/examples/example/LSPScoring/TipInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -package example.LSPScoring; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; - -public class TipInfo extends Info{ - - private InfoFunction function; - private String name = "TIPINFO"; - - public TipInfo (InfoFunction function) { - this.function = function; - } - - @Override - public String getName() { - return name; - } - - @Override - public InfoFunction getFunction() { - return function; - } - - @Override - public double getFromTime() { - return 0; - } - - @Override - public double getToTime() { - return Double.MAX_VALUE; - } - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - -} diff --git a/examples/example/LSPScoring/TipScorer.java b/examples/example/LSPScoring/TipScorer.java deleted file mode 100644 index 04b22a75744..00000000000 --- a/examples/example/LSPScoring/TipScorer.java +++ /dev/null @@ -1,43 +0,0 @@ -package example.LSPScoring; - -import lsp.LSP; -import lsp.functions.Info; -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; -import lsp.scoring.LSPScorer; - -public class TipScorer implements LSPScorer { - - private LSP lsp; - private TipSimulationTracker tracker; - - public TipScorer(LSP lsp, TipSimulationTracker tracker) { - this.lsp = lsp; - this.tracker = tracker; - } - - @Override - public double scoreCurrentPlan(LSP lsp) { - double score = 0; - for(Info info : tracker.getInfos()) { - if(info instanceof TipInfo) { - InfoFunction function = info.getFunction(); - for(InfoFunctionValue value : function.getValues()) { - if(value.getName() == "TIP IN EUR" && value.getValue() instanceof Double) { - double trinkgeldValue = (Double) value.getValue(); - score += trinkgeldValue; - } - } - } - } - return score; - } - - @Override - public void setLSP(LSP lsp) { - // TODO Auto-generated method stub - - } - - -} diff --git a/examples/example/LSPScoring/TipSimulationTracker.java b/examples/example/LSPScoring/TipSimulationTracker.java deleted file mode 100644 index 7c4fe527367..00000000000 --- a/examples/example/LSPScoring/TipSimulationTracker.java +++ /dev/null @@ -1,52 +0,0 @@ -package example.LSPScoring; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.events.handler.EventHandler; - -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.functions.InfoFunctionValueImpl; -import lsp.tracking.SimulationTracker; - -public class TipSimulationTracker implements SimulationTracker { - - private TipEventHandler handler; - private Info info; - - public TipSimulationTracker(TipEventHandler handler, Info info) { - this.info = info; - this.handler = handler; - } - - @Override - public Collection getEventHandlers() { - ArrayList handlers = new ArrayList(); - handlers.add(handler); - return handlers; - } - - @Override - public Collection getInfos() { - ArrayList infos = new ArrayList(); - infos.add(info); - return infos; - } - - @Override - public void notifyAfterMobsim(AfterMobsimEvent event) { - double tip = handler.getTip(); - InfoFunctionValue value = new InfoFunctionValueImpl<>("TIP IN EUR"); - value.setValue(tip); - info.getFunction().getValues().add(value); - } - - @Override - public void reset() { - // TODO Auto-generated method stub - } - - -} diff --git a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java b/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java deleted file mode 100644 index 1dc786a5516..00000000000 --- a/examples/example/initialPlans/ExampleSchedulingOfInitialPlan.java +++ /dev/null @@ -1,198 +0,0 @@ -package example.initialPlans; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; -import lsp.usecase.CollectionCarrierAdapter.Builder; - -public class ExampleSchedulingOfInitialPlan { - - - - public static LSP createInitialLSP(Network network) { - - //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - //The Adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - - //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - - return collectionLSPBuilder.build(); - - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id toLinkId = collectionLinkId; - - //Create five LSPShipments that are located in the left half of the network. - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - public static void main(String [] args) { - - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createInitialLSP(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - //schedule the LSP with the shipments and according to the scheduler of the Resource - lsp.scheduleSoultions(); - - //print the schedules for the assigned LSPShipments - for(LSPShipment shipment : shipments) { - System.out.println("Shipment: " + shipment.getId()); - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); - Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - - for(AbstractShipmentPlanElement element : shipment.getSchedule().getPlanElements().values()) { - System.out.println("Solution Id: " + element.getSolutionElement().getLogisticsSolution().getId() - + " SolutionElement Id: " + element.getSolutionElement().getId() - + " Resource Id: " + element.getResourceId() - + " Type: " + element.getElementType() - + " Start Time: " + element.getStartTime() - + " End Time: " + element.getEndTime()); - } - System.out.println(); - } - } -} diff --git a/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java b/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java deleted file mode 100644 index 10d309c4911..00000000000 --- a/examples/example/initialPlans/ExampleSchedulingOfTransportChain.java +++ /dev/null @@ -1,361 +0,0 @@ -package example.initialPlans; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; - -/*A transport chain with five elements (collection-> reloading -> main run -> reloading -> delivery) is created and scheduled - * - */ - -public class ExampleSchedulingOfTransportChain { - - public static LSP createInitialLSP(Network network) { - - //The Carrier for collection is created - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(capabilities); - - //The collection adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(collectionCarrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - - //The first reloading adapter i.e. the Resource is created - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - - //The scheduler for the first reloading point is created - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - //The scheduler is added to the Resource and the Resource is created - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - //The SolutionElement for the first reloading point is created - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); - - - //The Carrier for the main run Resource is created - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - //The adapter i.e. the main run resource is created - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - - //The scheduler for the main run Rescource is created and added to the Resource - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); - - //The LogisticsSolutionElement for the main run Resource is created - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); - - - //The second reloading adapter i.e. the Resource is created - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - - //The scheduler for the second reloading point is created - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - //The scheduler is added to the Resource and the Resource is created - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); - - - //The Carrier for distribution is created - Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); - Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); - dsitributionVehicleTypeBuilder.setCapacity(10); - dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - dsitributionVehicleTypeBuilder.setFixCost(49); - dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); - - Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); - CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); - distributionCarrierVehicle.setVehicleType(distributionType); - - CarrierCapabilities.Builder distributionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - distributionCapabilitiesBuilder.addType(distributionType); - distributionCapabilitiesBuilder.addVehicle(distributionCarrierVehicle); - distributionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities distributionCapabilities = distributionCapabilitiesBuilder.build(); - Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); - distributionCarrier.setCarrierCapabilities(distributionCapabilities); - - //The distribution adapter i.e. the Resource is created - Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); - DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); - distributionAdapterBuilder.setCarrier(distributionCarrier); - distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); - distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - Resource distributionAdapter = distributionAdapterBuilder.build(); - - //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); - distributionBuilder.setResource(distributionAdapter); - LogisticsSolutionElement distributionElement = distributionBuilder.build(); - - //The Order of the logisticsSolutionElements is now specified - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - secondReloadElement.setNextElement(distributionElement); - distributionElement.setPreviousElement(secondReloadElement); - - - //The SolutionElements are now inserted into the only LogisticsSolution of the LSP - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolutionBuilder.addSolutionElement(secondReloadElement); - completeSolutionBuilder.addSolutionElement(distributionElement); - LogisticsSolution completeSolution = completeSolutionBuilder.build(); - - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl completePlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id completeLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(completeLSPId); - - //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - resourcesList.add(distributionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - - return completeLSPBuilder.build(); - - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Random rand = new Random(1); - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(10); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - public static void main (String [] args) { - - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createInitialLSP(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - //schedule the LSP with the shipments and according to the scheduler of the Resource - lsp.scheduleSoultions(); - - //print the schedules for the assigned LSPShipments - for(LSPShipment shipment : lsp.getShipments()) { - ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); - System.out.println("Shipment: " + shipment.getId()); - for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + "\t\t" + element.getResourceId() + "\t\t" + element.getElementType() + "\t\t" + element.getStartTime() + "\t\t" + element.getEndTime()); - } - System.out.println(); - } - - - - } - -} diff --git a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java b/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java deleted file mode 100644 index 9ab75cbba68..00000000000 --- a/examples/example/mobsimExamples/ExampleMobsimOfSimpleLSP.java +++ /dev/null @@ -1,218 +0,0 @@ -package example.mobsimExamples; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.resources.Resource; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; - -public class ExampleMobsimOfSimpleLSP { - -public static LSP createInitialLSP(Network network) { - - //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - //The Adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - - //The exogenous list of Resoruces for the SolutuionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - - return collectionLSPBuilder.build(); - - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id toLinkId = collectionLinkId; - - //Create five LSPShipments that are located in the left half of the network. - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - - public static void main (String[]args) { - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createInitialLSP(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - //schedule the LSP with the shipments and according to the scheduler of the Resource - lsp.scheduleSoultions(); - - //set up simulation controler and LSPModule - ArrayList lspList = new ArrayList(); - lspList.add(lsp); - LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - Controler controler = new Controler(config); - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input/lsp/network/2regions.xml"); - controler.run(); - - for(LSPShipment shipment : lsp.getShipments()) { - System.out.println("Shipment: " + shipment.getId()); - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); - Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); - } - System.out.println(); - } - - - } - - -} diff --git a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java b/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java deleted file mode 100644 index 3ae5c7f6987..00000000000 --- a/examples/example/mobsimExamples/ExampleMobsimOfTransportChain.java +++ /dev/null @@ -1,381 +0,0 @@ -package example.mobsimExamples; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.resources.Resource; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.AbstractShipmentPlanElement; -import lsp.shipment.AbstractShipmentPlanElementComparator; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.DistributionCarrierAdapter; -import lsp.usecase.DistributionCarrierScheduler; -import lsp.usecase.MainRunCarrierAdapter; -import lsp.usecase.MainRunCarrierScheduler; -import lsp.usecase.ReloadingPoint; -import lsp.usecase.ReloadingPointScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; - -public class ExampleMobsimOfTransportChain { - -public static LSP createInitialLSP(Network network) { - - //The Carrier for collection is created - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier collectionCarrier = CarrierImpl.newInstance(collectionCarrierId); - collectionCarrier.setCarrierCapabilities(capabilities); - - //The collection adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(collectionCarrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - - //The first reloading adapter i.e. the Resource is created - Id firstReloadingId = Id.create("ReloadingPoint1", Resource.class); - Id firstReloadingLinkId = Id.createLinkId("(4 2) (4 3)"); - ReloadingPoint.Builder firstReloadingPointBuilder = ReloadingPoint.Builder.newInstance(firstReloadingId, firstReloadingLinkId); - - //The scheduler for the first reloading point is created - ReloadingPointScheduler.Builder firstReloadingSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - firstReloadingSchedulerBuilder.setCapacityNeedFixed(10); - firstReloadingSchedulerBuilder.setCapacityNeedLinear(1); - - //The scheduler is added to the Resource and the Resource is created - firstReloadingPointBuilder.setReloadingScheduler(firstReloadingSchedulerBuilder.build()); - Resource firstReloadingPointAdapter = firstReloadingPointBuilder.build(); - - //The SolutionElement for the first reloading point is created - Id firstReloadingElementId = Id.create("FirstReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder firstReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(firstReloadingElementId); - firstReloadingElementBuilder.setResource(firstReloadingPointAdapter); - LogisticsSolutionElement firstReloadElement = firstReloadingElementBuilder.build(); - - - //The Carrier for the main run Resource is created - Id mainRunCarrierId = Id.create("MainRunCarrier", Carrier.class); - Id mainRunVehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder mainRunVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(mainRunVehicleTypeId); - mainRunVehicleTypeBuilder.setCapacity(30); - mainRunVehicleTypeBuilder.setCostPerDistanceUnit(0.0002); - mainRunVehicleTypeBuilder.setCostPerTimeUnit(0.38); - mainRunVehicleTypeBuilder.setFixCost(120); - mainRunVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType mainRunType = mainRunVehicleTypeBuilder.build(); - - - Id fromLinkId = Id.createLinkId("(4 2) (4 3)"); - Id mainRunVehicleId = Id.createVehicleId("MainRunVehicle"); - CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId); - mainRunCarrierVehicle.setVehicleType(mainRunType); - - CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); - mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); - mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); - Carrier mainRunCarrier = CarrierImpl.newInstance(mainRunCarrierId); - mainRunCarrier.setCarrierCapabilities(mainRunCapabilities); - - //The adapter i.e. the main run resource is created - Id mainRunId = Id.create("MainRunAdapter", Resource.class); - MainRunCarrierAdapter.Builder mainRunAdapterBuilder = MainRunCarrierAdapter.Builder.newInstance(mainRunId, network); - mainRunAdapterBuilder.setFromLinkId(Id.createLinkId("(4 2) (4 3)")); - mainRunAdapterBuilder.setToLinkId(Id.createLinkId("(14 2) (14 3)")); - mainRunAdapterBuilder.setCarrier(mainRunCarrier); - - //The scheduler for the main run Rescource is created and added to the Resource - MainRunCarrierScheduler mainRunScheduler = new MainRunCarrierScheduler(); - mainRunAdapterBuilder.setMainRunCarrierScheduler(mainRunScheduler); - Resource mainRunAdapter = mainRunAdapterBuilder.build(); - - //The LogisticsSolutionElement for the main run Resource is created - Id mainRunElementId = Id.create("MainRunElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder mainRunBuilder = LogisticsSolutionElementImpl.Builder.newInstance(mainRunElementId); - mainRunBuilder.setResource(mainRunAdapter); - LogisticsSolutionElement mainRunElement = mainRunBuilder.build(); - - - //The second reloading adapter i.e. the Resource is created - Id secondReloadingId = Id.create("ReloadingPoint2", Resource.class); - Id secondReloadingLinkId = Id.createLinkId("(14 2) (14 3)"); - ReloadingPoint.Builder secondReloadingPointBuilder = ReloadingPoint.Builder.newInstance(secondReloadingId, secondReloadingLinkId); - - //The scheduler for the second reloading point is created - ReloadingPointScheduler.Builder secondSchedulerBuilder = ReloadingPointScheduler.Builder.newInstance(); - secondSchedulerBuilder.setCapacityNeedFixed(10); - secondSchedulerBuilder.setCapacityNeedLinear(1); - - //The scheduler is added to the Resource and the Resource is created - secondReloadingPointBuilder.setReloadingScheduler(secondSchedulerBuilder.build()); - Resource secondReloadingPointAdapter = secondReloadingPointBuilder.build(); - - //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id secondReloadingElementId = Id.create("SecondReloadElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder secondReloadingElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(secondReloadingElementId); - secondReloadingElementBuilder.setResource(secondReloadingPointAdapter); - LogisticsSolutionElement secondReloadElement = secondReloadingElementBuilder.build(); - - - //The Carrier for distribution is created - Id distributionCarrierId = Id.create("DistributionCarrier", Carrier.class); - Id distributionVehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder dsitributionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(distributionVehicleTypeId); - dsitributionVehicleTypeBuilder.setCapacity(10); - dsitributionVehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - dsitributionVehicleTypeBuilder.setCostPerTimeUnit(0.38); - dsitributionVehicleTypeBuilder.setFixCost(49); - dsitributionVehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType distributionType = dsitributionVehicleTypeBuilder.build(); - - Id distributionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id distributionVehicleId = Id.createVehicleId("DistributionVehicle"); - CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId); - distributionCarrierVehicle.setVehicleType(distributionType); - - CarrierCapabilities.Builder distributionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - distributionCapabilitiesBuilder.addType(distributionType); - distributionCapabilitiesBuilder.addVehicle(distributionCarrierVehicle); - distributionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities distributionCapabilities = distributionCapabilitiesBuilder.build(); - Carrier distributionCarrier = CarrierImpl.newInstance(distributionCarrierId); - distributionCarrier.setCarrierCapabilities(distributionCapabilities); - - //The distribution adapter i.e. the Resource is created - Id distributionAdapterId = Id.create("DistributionCarrierAdapter", Resource.class); - DistributionCarrierAdapter.Builder distributionAdapterBuilder = DistributionCarrierAdapter.Builder.newInstance(distributionAdapterId, network); - distributionAdapterBuilder.setCarrier(distributionCarrier); - distributionAdapterBuilder.setLocationLinkId(distributionLinkId); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - DistributionCarrierScheduler distriutionScheduler = new DistributionCarrierScheduler(); - distributionAdapterBuilder.setDistributionScheduler(distriutionScheduler); - Resource distributionAdapter = distributionAdapterBuilder.build(); - - //The adapter is now inserted into the corresponding LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id distributionElementId = Id.create("DistributionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder distributionBuilder = LogisticsSolutionElementImpl.Builder.newInstance(distributionElementId); - distributionBuilder.setResource(distributionAdapter); - LogisticsSolutionElement distributionElement = distributionBuilder.build(); - - //The Order of the logisticsSolutionElements is now specified - collectionElement.setNextElement(firstReloadElement); - firstReloadElement.setPreviousElement(collectionElement); - firstReloadElement.setNextElement(mainRunElement); - mainRunElement.setPreviousElement(firstReloadElement); - mainRunElement.setNextElement(secondReloadElement); - secondReloadElement.setPreviousElement(mainRunElement); - secondReloadElement.setNextElement(distributionElement); - distributionElement.setPreviousElement(secondReloadElement); - - - //The SolutionElements are now inserted into the only LogisticsSolution of the LSP - Id solutionId = Id.create("SolutionId", LogisticsSolution.class); - LogisticsSolutionImpl.Builder completeSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(solutionId); - completeSolutionBuilder.addSolutionElement(collectionElement); - completeSolutionBuilder.addSolutionElement(firstReloadElement); - completeSolutionBuilder.addSolutionElement(mainRunElement); - completeSolutionBuilder.addSolutionElement(secondReloadElement); - completeSolutionBuilder.addSolutionElement(distributionElement); - LogisticsSolution completeSolution = completeSolutionBuilder.build(); - - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl completePlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - completePlan.setAssigner(assigner); - completePlan.addSolution(completeSolution); - - LSPImpl.Builder completeLSPBuilder = LSPImpl.Builder.getInstance(); - completeLSPBuilder.setInitialPlan(completePlan); - Id completeLSPId = Id.create("CollectionLSP", LSP.class); - completeLSPBuilder.setId(completeLSPId); - - //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - resourcesList.add(firstReloadingPointAdapter); - resourcesList.add(mainRunAdapter); - resourcesList.add(secondReloadingPointAdapter); - resourcesList.add(distributionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - completeLSPBuilder.setSolutionScheduler(simpleScheduler); - - return completeLSPBuilder.build(); - - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Random rand = new Random(1); - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(10); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); - if((pendingToLink.getFromNode().getCoord().getX() <= 18000 && - pendingToLink.getFromNode().getCoord().getY() <= 4000 && - pendingToLink.getFromNode().getCoord().getX() >= 14000 && - pendingToLink.getToNode().getCoord().getX() <= 18000 && - pendingToLink.getToNode().getCoord().getY() <= 4000 && - pendingToLink.getToNode().getCoord().getX() >= 14000 )) { - builder.setToLinkId(pendingToLink.getId()); - break; - } - - } - - while(true) { - Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - - } - - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - LSPShipment shipment = builder.build(); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - public static void main (String[]args) { - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createInitialLSP(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - //schedule the LSP with the shipments and according to the scheduler of the Resource - lsp.scheduleSoultions(); - - //set up simulation controler and LSPModule - ArrayList lspList = new ArrayList(); - lspList.add(lsp); - LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - Controler controler = new Controler(config); - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input/lsp/network/2regions.xml"); - controler.run(); - - for(LSPShipment shipment : lsp.getShipments()) { - System.out.println("Shipment: " + shipment.getId()); - ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); - Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - ArrayList logElements = new ArrayList(shipment.getLog().getPlanElements().values()); - Collections.sort(logElements, new AbstractShipmentPlanElementComparator()); - - for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { - System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId()+ " " + scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); - } - System.out.println(); - for(int i = 0; i < shipment.getLog().getPlanElements().size(); i++) { - System.out.println("Logged: " + logElements.get(i).getSolutionElement().getId() + " " + logElements.get(i).getResourceId() +" " + logElements.get(i).getElementType() + " Start: " + logElements.get(i).getStartTime() + " End: " + logElements.get(i).getEndTime()); - } - System.out.println(); - } - } - - -} diff --git a/examples/example/requirementsChecking/BlueInfo.java b/examples/example/requirementsChecking/BlueInfo.java deleted file mode 100644 index ad3dc608343..00000000000 --- a/examples/example/requirementsChecking/BlueInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -package example.requirementsChecking; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionImpl; -import lsp.functions.InfoFunctionValue; -import lsp.functions.InfoFunctionValueImpl; - -public class BlueInfo extends Info{ - -private InfoFunctionImpl blueInfoFunction; - - public BlueInfo() { - blueInfoFunction = new InfoFunctionImpl(); - InfoFunctionValue value = new InfoFunctionValueImpl("blue"); - value.setValue("blue"); - blueInfoFunction.getValues().add(value); - } - - @Override - public String getName() { - return "blue"; - } - - @Override - public InfoFunction getFunction() { - return blueInfoFunction; - } - - @Override - public double getFromTime() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public double getToTime() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } -} diff --git a/examples/example/requirementsChecking/BlueRequirement.java b/examples/example/requirementsChecking/BlueRequirement.java deleted file mode 100644 index cfa6703667a..00000000000 --- a/examples/example/requirementsChecking/BlueRequirement.java +++ /dev/null @@ -1,19 +0,0 @@ -package example.requirementsChecking; - -import lsp.functions.Info; -import lsp.LogisticsSolution; -import lsp.shipment.Requirement; - -public class BlueRequirement implements Requirement{ - - @Override - public boolean checkRequirement(LogisticsSolution solution) { - for(Info info : solution.getInfos()) { - if(info instanceof BlueInfo) { - return true; - } - } - return false; - } - -} diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java deleted file mode 100644 index 5ad833159e8..00000000000 --- a/examples/example/requirementsChecking/ExampleCheckRequirementsOfAssigner.java +++ /dev/null @@ -1,239 +0,0 @@ -package example.requirementsChecking; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlan; -import lsp.LSPPlanImpl; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import requirementsCheckerTests.BlueInfo; -import requirementsCheckerTests.BlueRequirement; -import requirementsCheckerTests.RedInfo; -import requirementsCheckerTests.RedRequirement; -import requirementsCheckerTests.RequirementsAssigner; - -public class ExampleCheckRequirementsOfAssigner { - - public static LSP createLSPWithProperties(Network network) { - - //Create red LogisticsSolution which has the corresponding info - CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); - Id redCarrierId = Id.create("RedCarrier", Carrier.class); - Id vehicleTypeId = Id.create("RedCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id redVehicleId = Id.createVehicleId("RedVehicle"); - CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId); - redVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder redCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - redCapabilitiesBuilder.addType(collectionType); - redCapabilitiesBuilder.addVehicle(redVehicle); - redCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities redCapabilities = redCapabilitiesBuilder.build(); - Carrier redCarrier = CarrierImpl.newInstance(redCarrierId); - redCarrier.setCarrierCapabilities(redCapabilities); - - Id redAdapterId = Id.create("RedCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder redAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(redAdapterId, network); - redAdapterBuilder.setCollectionScheduler(redScheduler); - redAdapterBuilder.setCarrier(redCarrier); - redAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource redAdapter = redAdapterBuilder.build(); - - Id redElementId = Id.create("RedElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder redElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(redElementId); - redElementBuilder.setResource(redAdapter); - LogisticsSolutionElement redElement = redElementBuilder.build(); - - Id redSolutionId = Id.create("RedSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder redSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(redSolutionId); - redSolutionBuilder.addSolutionElement(redElement); - LogisticsSolution redSolution = redSolutionBuilder.build(); - - //Add info that shows the world the color of the solution - redSolution.getInfos().add(new RedInfo()); - - - //Create blue LogisticsSolution which has the corresponding info - CollectionCarrierScheduler blueScheduler = new CollectionCarrierScheduler(); - Id blueCarrierId = Id.create("BlueCarrier", Carrier.class); - Id blueVehicleId = Id.createVehicleId("BlueVehicle"); - CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId); - blueVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - blueCapabilitiesBuilder.addType(collectionType); - blueCapabilitiesBuilder.addVehicle(blueVehicle); - blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); - Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); - blueCarrier.setCarrierCapabilities(blueCapabilities); - - Id blueAdapterId = Id.create("BlueCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder blueAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(blueAdapterId, network); - blueAdapterBuilder.setCollectionScheduler(blueScheduler); - blueAdapterBuilder.setCarrier(blueCarrier); - blueAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource blueAdapter = blueAdapterBuilder.build(); - - Id blueElementId = Id.create("BlueCElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder blueElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(blueElementId); - blueElementBuilder.setResource(blueAdapter); - LogisticsSolutionElement blueElement = blueElementBuilder.build(); - - Id blueSolutionId = Id.create("BlueSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder blueSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(blueSolutionId); - blueSolutionBuilder.addSolutionElement(blueElement); - LogisticsSolution blueSolution = blueSolutionBuilder.build(); - - //Add info that shows the world the color of the solution - blueSolution.getInfos().add(new BlueInfo()); - - //Create the initial plan, add assigner that checks requirements of the shipments when assigning and add both solutions (red and blue) to the - //plan. - LSPPlan plan = new LSPPlanImpl(); - ShipmentAssigner assigner = new RequirementsAssigner(); - plan.setAssigner(assigner); - plan.addSolution(redSolution); - plan.addSolution(blueSolution); - - LSPImpl.Builder lspBuilder = LSPImpl.Builder.getInstance(); - lspBuilder.setInitialPlan(plan); - Id lspId = Id.create("CollectionLSP", LSP.class); - lspBuilder.setId(lspId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(redAdapter); - resourcesList.add(blueAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - lspBuilder.setSolutionScheduler(simpleScheduler); - return lspBuilder.build(); - } - - public static Collection createShipmentsWithRequirements(Network network){ - //Create ten shipments with either a red or blue requirement, i.e. that they only can be transported in a solution with the matching color - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id toLinkId = collectionLinkId; - - Random rand = new Random(1); - - for(int i = 1; i < 11; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - int capacityDemand = rand.nextInt(10); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000 ) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - boolean blue = rand.nextBoolean(); - if (blue == true) { - builder.addRequirement(new BlueRequirement()); - } - else { - builder.addRequirement(new RedRequirement()); - } - - shipmentList.add(builder.build()); - } - - return shipmentList; - } - - public static void main (String[]args) { - - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createLSPWithProperties(network); - Collection shipments = createShipmentsWithRequirements(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - if(solution.getId().toString() == "RedSolution") { - for(LSPShipment shipment : solution.getShipments()) { - if(!(shipment.getRequirements().iterator().next() instanceof RedRequirement)) { - break; - } - } - System.out.println("All shipments in " + solution.getId() + " are red"); - } - if(solution.getId().toString() == "BlueSolution") { - for(LSPShipment shipment : solution.getShipments()) { - if(!(shipment.getRequirements().iterator().next() instanceof BlueRequirement)) { - break; - } - } - System.out.println("All shipments in " + solution.getId() + " are blue"); - } - } - - } - -} diff --git a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java b/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java deleted file mode 100644 index 2ed38e3740a..00000000000 --- a/examples/example/requirementsChecking/ExampleCheckRequirementsOfOfferTransferrer.java +++ /dev/null @@ -1,230 +0,0 @@ -package example.requirementsChecking; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPPlanDecorator; -import demand.decoratedLSP.LSPPlanWithOfferTransferrer; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.demandObject.DemandObject; -import demand.demandObject.DemandObjectImpl; -import demand.offer.Offer; -import demand.offer.OfferFactoryImpl; -import demand.offer.OfferTransferrer; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.SolutionScheduler; -import lsp.resources.Resource; -import lsp.shipment.Requirement; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.SimpleForwardSolutionScheduler; -import requirementsCheckerTests.BlueInfo; -import requirementsCheckerTests.BlueRequirement; -import requirementsCheckerTests.NonsenseOffer; -import requirementsCheckerTests.RedInfo; -import requirementsCheckerTests.RedRequirement; -import requirementsCheckerTests.RequirementsTransferrer; - -public class ExampleCheckRequirementsOfOfferTransferrer { - - public static LSPDecorator createLSPWithProperties(Network network) { - - //Create red LogisticsSolution which has the corresponding info - CollectionCarrierScheduler redScheduler = new CollectionCarrierScheduler(); - Id redCarrierId = Id.create("RedCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id redVehicleId = Id.createVehicleId("RedVehicle"); - CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId); - redVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder redCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - redCapabilitiesBuilder.addType(collectionType); - redCapabilitiesBuilder.addVehicle(redVehicle); - redCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities redCapabilities = redCapabilitiesBuilder.build(); - Carrier redCarrier = CarrierImpl.newInstance(redCarrierId); - redCarrier.setCarrierCapabilities(redCapabilities); - - Id redAdapterId = Id.create("RedCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder redAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(redAdapterId, network); - redAdapterBuilder.setCollectionScheduler(redScheduler); - redAdapterBuilder.setCarrier(redCarrier); - redAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource redAdapter = redAdapterBuilder.build(); - - Id redElementId = Id.create("RedElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder redElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(redElementId); - redElementBuilder.setResource(redAdapter); - LogisticsSolutionElement redElement = redElementBuilder.build(); - - Id redSolutionId = Id.create("RedSolution", LogisticsSolution.class); - LogisticsSolutionWithOffers.Builder redOfferSolutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(redSolutionId); - redOfferSolutionBuilder.addSolutionElement(redElement); - LogisticsSolutionDecorator redOfferSolution = redOfferSolutionBuilder.build(); - - //Add info that shows the world the color of the solution - redOfferSolution.getInfos().add(new RedInfo()); - - //Add OfferFactory that gives some nonsense offer, as in this case only the work of the transferrer i.e. the solution from which the offer - //comes is relevant - OfferFactoryImpl redOfferFactory = new OfferFactoryImpl(redOfferSolution); - redOfferFactory.addOffer(new NonsenseOffer()); - redOfferSolution.setOfferFactory(redOfferFactory); - - - //Create blue LogisticsSolution which has the corresponding info - CollectionCarrierScheduler blueScheduler = new CollectionCarrierScheduler(); - Id blueCarrierId = Id.create("BlueCarrier", Carrier.class); - Id blueVehicleId = Id.createVehicleId("BlueVehicle"); - CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId); - blueVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder blueCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - blueCapabilitiesBuilder.addType(collectionType); - blueCapabilitiesBuilder.addVehicle(blueVehicle); - blueCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities blueCapabilities = blueCapabilitiesBuilder.build(); - Carrier blueCarrier = CarrierImpl.newInstance(blueCarrierId); - blueCarrier.setCarrierCapabilities(blueCapabilities); - - Id blueAdapterId = Id.create("BlueCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder blueAdapterBuilder = CollectionCarrierAdapter.Builder.newInstance(blueAdapterId, network); - blueAdapterBuilder.setCollectionScheduler(blueScheduler); - blueAdapterBuilder.setCarrier(blueCarrier); - blueAdapterBuilder.setLocationLinkId(collectionLinkId); - Resource blueAdapter = blueAdapterBuilder.build(); - - Id blueElementId = Id.create("BlueElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder blueElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(blueElementId); - blueElementBuilder.setResource(blueAdapter); - LogisticsSolutionElement blueElement = blueElementBuilder.build(); - - Id blueSolutionId = Id.create("BlueSolution", LogisticsSolution.class); - LogisticsSolutionWithOffers.Builder blueOfferSolutionBuilder = LogisticsSolutionWithOffers.Builder.newInstance(blueSolutionId); - blueOfferSolutionBuilder.addSolutionElement(blueElement); - LogisticsSolutionDecorator blueOfferSolution = blueOfferSolutionBuilder.build(); - - //Add info that shows the world the color of the solution - blueOfferSolution.getInfos().add(new BlueInfo()); - - //Add OfferFactory that gives some nonsense offer, as in this case only the work of the transferrer i.e. the solution from which the offer - //comes is relevant - OfferFactoryImpl blueOfferFactory = new OfferFactoryImpl(blueOfferSolution); - blueOfferFactory.addOffer(new NonsenseOffer()); - blueOfferSolution.setOfferFactory(blueOfferFactory); - - //Create PlanDecorator (i.e. Plan that has an OfferTransferrer) and add solutions - LSPPlanDecorator plan = new LSPPlanWithOfferTransferrer(); - plan.addSolution(redOfferSolution); - plan.addSolution(blueOfferSolution); - - //Create OfferTransferrer that only gives the offer of the suitable solution with the right color to the outside - OfferTransferrer transferrer = new RequirementsTransferrer(); - plan.setOfferTransferrer(transferrer); - - LSPWithOffers.Builder offerLSPBuilder = LSPWithOffers.Builder.getInstance(); - offerLSPBuilder.setInitialPlan(plan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - offerLSPBuilder.setId(collectionLSPId); - ArrayList resourcesList = new ArrayList(); - resourcesList.add(redAdapter); - resourcesList.add(blueAdapter); - - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - offerLSPBuilder.setSolutionScheduler(simpleScheduler); - return offerLSPBuilder.build(); - - } - - - public static Collection createDemandObjectsWithRequirements(){ - //Create ten demand objects with either a red or blue requirement, i.e. that they only can be transported in a solution with the matching color - ArrayList demandObjects = new ArrayList(); - - Random rand = new Random(1); - - for(int i = 1; i < 11; i++) { - Id id = Id.create(("DemandObject_" + Integer.toString(i)), DemandObject.class); - DemandObjectImpl.Builder builder = DemandObjectImpl.Builder.newInstance(); - builder.setId(id); - - boolean blue = rand.nextBoolean(); - if (blue == true) { - builder.addRequirement(new BlueRequirement()); - } - else { - builder.addRequirement(new RedRequirement()); - } - - DemandObject demandObject = builder.build(); - demandObjects.add(demandObject); - } - - return demandObjects; - } - - - public static void main (String[]args) { - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and demand objects - LSPDecorator lsp = createLSPWithProperties(network); - Collection demandObjects = createDemandObjectsWithRequirements(); - - for(DemandObject demandObject : demandObjects) { - Offer offer = lsp.getOffer(demandObject, "nonsense", null); - for(Requirement requirement : demandObject.getRequirements()) { - if((requirement instanceof RedRequirement) && (offer.getSolution().getId().toString() == "RedSolution")) { - System.out.println(demandObject.getId() +" is red and gets an offer from a " + offer.getSolution().getId().toString() ); - } - else if((requirement instanceof BlueRequirement) && (offer.getSolution().getId().toString() == "BlueSolution")){ - System.out.println(demandObject.getId() +" is blue and gets an offer from a " + offer.getSolution().getId().toString() ); - } - else { - System.out.println("Wrong sort of offer for " + demandObject.getId()+ ": " + offer.getSolution().getId().toString() + - " was wrong for shipment with " + requirement.getClass()); - } - } - } - - - } - -} diff --git a/examples/example/requirementsChecking/NonsenseOffer.java b/examples/example/requirementsChecking/NonsenseOffer.java deleted file mode 100644 index 6b2ed8c9544..00000000000 --- a/examples/example/requirementsChecking/NonsenseOffer.java +++ /dev/null @@ -1,52 +0,0 @@ -package example.requirementsChecking; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.offer.Offer; -import demand.offer.OfferVisitor; - -public class NonsenseOffer implements Offer{ - - private LSPDecorator lsp; - private LogisticsSolutionDecorator solution; - - - @Override - public LSPDecorator getLsp() { - return lsp; - } - - @Override - public LogisticsSolutionDecorator getSolution() { - return solution; - } - - @Override - public String getType() { - return "nonsense"; - } - - @Override - public void accept(OfferVisitor visitor) { - visitor.visit(this); - } - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - - } - - @Override - public void setSolution(LogisticsSolutionDecorator solution) { - this.solution = solution; - - } - -} diff --git a/examples/example/requirementsChecking/RedInfo.java b/examples/example/requirementsChecking/RedInfo.java deleted file mode 100644 index fce91143619..00000000000 --- a/examples/example/requirementsChecking/RedInfo.java +++ /dev/null @@ -1,54 +0,0 @@ -package example.requirementsChecking; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionImpl; -import lsp.functions.InfoFunctionValue; -import lsp.functions.InfoFunctionValueImpl; - -public class RedInfo extends Info{ - -private InfoFunctionImpl redInfoFunction; - - public RedInfo() { - redInfoFunction = new InfoFunctionImpl(); - InfoFunctionValue value = new InfoFunctionValueImpl("red"); - value.setValue("red"); - redInfoFunction.getValues().add(value); - } - - @Override - public String getName() { - return "red"; - } - - @Override - public InfoFunction getFunction() { - return redInfoFunction; - } - - @Override - public double getFromTime() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public double getToTime() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - -} diff --git a/examples/example/requirementsChecking/RedRequirement.java b/examples/example/requirementsChecking/RedRequirement.java deleted file mode 100644 index 499858d240e..00000000000 --- a/examples/example/requirementsChecking/RedRequirement.java +++ /dev/null @@ -1,19 +0,0 @@ -package example.requirementsChecking; - -import lsp.functions.Info; -import lsp.LogisticsSolution; -import lsp.shipment.Requirement; - -public class RedRequirement implements Requirement{ - - @Override - public boolean checkRequirement(LogisticsSolution solution) { - for(Info info : solution.getInfos()) { - if(info instanceof RedInfo) { - return true; - } - } - return false; - } - -} diff --git a/examples/example/requirementsChecking/RequirementsAssigner.java b/examples/example/requirementsChecking/RequirementsAssigner.java deleted file mode 100644 index 0926cdf5511..00000000000 --- a/examples/example/requirementsChecking/RequirementsAssigner.java +++ /dev/null @@ -1,49 +0,0 @@ -package example.requirementsChecking; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.ShipmentAssigner; -import lsp.shipment.LSPShipment; -import lsp.shipment.Requirement; - -public class RequirementsAssigner implements ShipmentAssigner { - - private LSP lsp; - private Collection feasibleSolutions; - - public RequirementsAssigner() { - this.feasibleSolutions = new ArrayList(); - } - - @Override - public void assignShipment(LSPShipment shipment) { - feasibleSolutions.clear(); - - label: - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - for(Requirement requirement : shipment.getRequirements()) { - if(requirement.checkRequirement(solution) == false) { - - continue label; - } - } - feasibleSolutions.add(solution); - } - LogisticsSolution chosenSolution = feasibleSolutions.iterator().next(); - chosenSolution.assignShipment(shipment); - } - - @Override - public void setLSP(LSP lsp) { - this.lsp = lsp; - } - - @Override - public LSP getLSP() { - return lsp; - } - -} diff --git a/examples/example/requirementsChecking/RequirementsTransferrer.java b/examples/example/requirementsChecking/RequirementsTransferrer.java deleted file mode 100644 index fb18f221d9c..00000000000 --- a/examples/example/requirementsChecking/RequirementsTransferrer.java +++ /dev/null @@ -1,59 +0,0 @@ -package example.requirementsChecking; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.Id; - -import demand.decoratedLSP.LSPDecorator; -import demand.decoratedLSP.LSPWithOffers; -import demand.decoratedLSP.LogisticsSolutionDecorator; -import demand.decoratedLSP.LogisticsSolutionWithOffers; -import demand.demandObject.DemandObject; -import demand.offer.DefaultOfferImpl; -import demand.offer.Offer; -import demand.offer.OfferTransferrer; -import lsp.LSP; -import lsp.LogisticsSolution; -import lsp.shipment.Requirement; - -public class RequirementsTransferrer implements OfferTransferrer{ - - private LSPDecorator lsp; - private Collection feasibleSolutions; - - public RequirementsTransferrer() { - this.feasibleSolutions = new ArrayList(); - } - - - @Override - public Offer transferOffer(DemandObject object, String type, Id solutionId) { - feasibleSolutions.clear(); - label: - for(LogisticsSolution solution : lsp.getSelectedPlan().getSolutions()) { - LogisticsSolutionWithOffers solutionWithOffers = (LogisticsSolutionWithOffers) solution; - for(Requirement requirement : object.getRequirements()) { - if(requirement.checkRequirement(solutionWithOffers) == false) { - continue label; - } - } - feasibleSolutions.add(solutionWithOffers); - } - - LogisticsSolutionDecorator chosenSolution = feasibleSolutions.iterator().next(); - return chosenSolution.getOffer(object, type); - - } - - @Override - public void setLSP(LSPDecorator lsp) { - this.lsp = lsp; - } - - - @Override - public LSPDecorator getLSP() { - return lsp; - } -} diff --git a/examples/example/simulationTrackers/CollectionServiceHandler.java b/examples/example/simulationTrackers/CollectionServiceHandler.java deleted file mode 100644 index bed8728b61c..00000000000 --- a/examples/example/simulationTrackers/CollectionServiceHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -package example.simulationTrackers; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.contrib.freight.carrier.CarrierService; - -import lsp.events.ServiceStartEvent; -import lsp.events.ServiceStartEventHandler; -import lsp.events.ServiceEndEvent; -import lsp.events.ServiceEndEventHandler; - - -public class CollectionServiceHandler implements ServiceStartEventHandler, ServiceEndEventHandler{ - - - - private class ServiceTuple { - private CarrierService service; - private double startTime; - - public ServiceTuple(CarrierService service, double startTime) { - this.service = service; - this.startTime = startTime; - } - - public CarrierService getService() { - return service; - } - - public double getStartTime() { - return startTime; - } - - } - - private Collection tuples; - private double totalLoadingCosts; - private int totalNumberOfShipments; - private int totalWeightOfShipments; - - public CollectionServiceHandler() { - this.tuples = new ArrayList(); - } - - @Override - public void reset(int iteration) { - tuples.clear(); - totalNumberOfShipments = 0; - totalWeightOfShipments = 0; - } - - @Override - public void handleEvent(ServiceEndEvent event) { - System.out.println("Service Ends"); - double loadingCosts = 0; - for(ServiceTuple tuple : tuples) { - if(tuple.getService() == event.getService()) { - double serviceDuration = event.getTime() - tuple.getStartTime(); - loadingCosts = serviceDuration * event.getVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit; - totalLoadingCosts = totalLoadingCosts + loadingCosts; - tuples.remove(tuple); - break; - } - } - } - - @Override - public void handleEvent(ServiceStartEvent event) { - totalNumberOfShipments++; - totalWeightOfShipments = totalWeightOfShipments + event.getService().getCapacityDemand(); - tuples.add(new ServiceTuple(event.getService(), event.getTime())); - } - - public double getTotalLoadingCosts() { - return totalLoadingCosts; - } - - public int getTotalNumberOfShipments() { - return totalNumberOfShipments; - } - - public int getTotalWeightOfShipments() { - return totalWeightOfShipments; - } - -} diff --git a/examples/example/simulationTrackers/CostInfo.java b/examples/example/simulationTrackers/CostInfo.java deleted file mode 100644 index 5d2eb0ccbbc..00000000000 --- a/examples/example/simulationTrackers/CostInfo.java +++ /dev/null @@ -1,50 +0,0 @@ -package example.simulationTrackers; - -import lsp.functions.Info; -import lsp.functions.InfoFunction; -import testLSPWithCostTracker.CostInfoFunction; - -public class CostInfo extends Info { - -private CostInfoFunction costFunction; - - public CostInfo() { - this.costFunction = new CostInfoFunction(); - } - - - @Override - public String getName() { - return "cost_function"; - } - - @Override - public InfoFunction getFunction() { - return costFunction; - } - - @Override - public double getFromTime() { - return 0; - } - - @Override - public double getToTime() { - return Double.MAX_VALUE; - } - - - @Override - public void update() { - // TODO Auto-generated method stub - - } - - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - -} diff --git a/examples/example/simulationTrackers/CostInfoFunction.java b/examples/example/simulationTrackers/CostInfoFunction.java deleted file mode 100644 index 7cf9ba62e63..00000000000 --- a/examples/example/simulationTrackers/CostInfoFunction.java +++ /dev/null @@ -1,33 +0,0 @@ -package example.simulationTrackers; - -import java.util.ArrayList; -import java.util.Collection; - -import lsp.functions.InfoFunction; -import lsp.functions.InfoFunctionValue; -import testLSPWithCostTracker.FixedCostFunctionValue; -import testLSPWithCostTracker.LinearCostFunctionValue; - - - -public class CostInfoFunction implements InfoFunction { - - private FixedCostFunctionValue fixedValue; - private LinearCostFunctionValue linearValue; - private Collection> values; - - public CostInfoFunction() { - values = new ArrayList>(); - fixedValue = new FixedCostFunctionValue(); - linearValue = new LinearCostFunctionValue(); - values.add(fixedValue); - values.add(linearValue); - - } - - @Override - public Collection> getValues() { - return values; - } - -} diff --git a/examples/example/simulationTrackers/DistanceAndTimeHandler.java b/examples/example/simulationTrackers/DistanceAndTimeHandler.java deleted file mode 100644 index 715441f0860..00000000000 --- a/examples/example/simulationTrackers/DistanceAndTimeHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -package example.simulationTrackers; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; - -import lsp.events.FreightLinkEnterEvent; -import lsp.events.FreightLinkLeaveEvent; -import lsp.events.FreightLinkLeaveEventHandler; -import lsp.events.FreightVehicleLeavesTrafficEvent; -import lsp.events.FreightVehicleLeavesTrafficEventHandler; -import lsp.usecase.FreightLinkEnterEventHandler; - - -public class DistanceAndTimeHandler implements FreightLinkEnterEventHandler, FreightVehicleLeavesTrafficEventHandler, FreightLinkLeaveEventHandler { - - private Collection events; - private double distanceCosts; - private double timeCosts; - private Network network; - - public DistanceAndTimeHandler(Network network) { - this.network = network; - this.events = new ArrayList(); - } - - - @Override - public void handleEvent(FreightLinkEnterEvent event) { - events.add(event); - - } - - @Override - public void reset(int iteration) { - events.clear(); - } - - - @Override - public void handleEvent(FreightVehicleLeavesTrafficEvent leaveEvent) { - for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } - } - - - @Override - public void handleEvent(FreightLinkLeaveEvent leaveEvent) { - for(FreightLinkEnterEvent enterEvent : events) { - if((enterEvent.getLinkId() == leaveEvent.getLinkId()) && (enterEvent.getVehicleId() == leaveEvent.getVehicleId()) && - (enterEvent.getCarrierId() == leaveEvent.getCarrierId()) && (enterEvent.getDriverId() == leaveEvent.getDriverId())) { - double linkDuration = leaveEvent.getTime() - enterEvent.getTime(); - timeCosts = timeCosts + (linkDuration * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perTimeUnit); - double linkLength = network.getLinks().get(enterEvent.getLinkId()).getLength(); - distanceCosts = distanceCosts + (linkLength * enterEvent.getCarrierVehicle().getVehicleType().getVehicleCostInformation().perDistanceUnit); - events.remove(enterEvent); - break; - } - } - } - - public double getDistanceCosts() { - return distanceCosts; - } - - public double getTimeCosts() { - return timeCosts; - } - -} diff --git a/examples/example/simulationTrackers/ExampleSimulationTrackers.java b/examples/example/simulationTrackers/ExampleSimulationTrackers.java deleted file mode 100644 index e03bc74dc3f..00000000000 --- a/examples/example/simulationTrackers/ExampleSimulationTrackers.java +++ /dev/null @@ -1,221 +0,0 @@ -package example.simulationTrackers; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierImpl; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; -import org.matsim.contrib.freight.carrier.TimeWindow; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.core.config.Config; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.network.io.MatsimNetworkReader; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vehicles.Vehicle; -import org.matsim.vehicles.VehicleType; - -import lsp.LSP; -import lsp.LSPImpl; -import lsp.LSPPlanImpl; -import lsp.LSPs; -import lsp.LogisticsSolution; -import lsp.LogisticsSolutionElement; -import lsp.LogisticsSolutionElementImpl; -import lsp.LogisticsSolutionImpl; -import lsp.ShipmentAssigner; -import lsp.SolutionScheduler; -import lsp.controler.LSPModule; -import lsp.events.EventUtils; -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.replanning.LSPReplanningModuleImpl; -import lsp.resources.Resource; -import lsp.scoring.LSPScoringModuleImpl; -import lsp.shipment.LSPShipment; -import lsp.shipment.LSPShipmentImpl; -import lsp.usecase.CollectionCarrierAdapter; -import lsp.usecase.CollectionCarrierScheduler; -import lsp.usecase.DeterministicShipmentAssigner; -import lsp.usecase.SimpleForwardSolutionScheduler; -import testLSPWithCostTracker.CollectionServiceHandler; -import testLSPWithCostTracker.DistanceAndTimeHandler; -import testLSPWithCostTracker.LinearCostTracker; -import testLSPWithCostTracker.TourStartHandler; - -public class ExampleSimulationTrackers { - -public static LSP createLSPWithTracker(Network network) { - - //The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created - Id carrierId = Id.create("CollectionCarrier", Carrier.class); - Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); - CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); - vehicleTypeBuilder.setCapacity(10); - vehicleTypeBuilder.setCostPerDistanceUnit(0.0004); - vehicleTypeBuilder.setCostPerTimeUnit(0.38); - vehicleTypeBuilder.setFixCost(49); - vehicleTypeBuilder.setMaxVelocity(50/3.6); - CarrierVehicleType collectionType = vehicleTypeBuilder.build(); - - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id vollectionVehicleId = Id.createVehicleId("CollectionVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId); - carrierVehicle.setVehicleType(collectionType); - - CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); - capabilitiesBuilder.addVehicle(carrierVehicle); - capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); - CarrierCapabilities capabilities = capabilitiesBuilder.build(); - - Carrier carrier = CarrierImpl.newInstance(carrierId); - carrier.setCarrierCapabilities(capabilities); - - //The Adapter i.e. the Resource is created - Id adapterId = Id.create("CollectionCarrierAdapter", Resource.class); - CollectionCarrierAdapter.Builder adapterBuilder = CollectionCarrierAdapter.Builder.newInstance(adapterId, network); - - //The scheduler for the Resource is created and added. This is where jsprit comes into play. - CollectionCarrierScheduler scheduler = new CollectionCarrierScheduler(); - adapterBuilder.setCollectionScheduler(scheduler); - adapterBuilder.setCarrier(carrier); - adapterBuilder.setLocationLinkId(collectionLinkId); - Resource collectionAdapter = adapterBuilder.build(); - - //The adapter is now inserted into the only LogisticsSolutionElement of the only LogisticsSolution of the LSP - Id elementId = Id.create("CollectionElement", LogisticsSolutionElement.class); - LogisticsSolutionElementImpl.Builder collectionElementBuilder = LogisticsSolutionElementImpl.Builder.newInstance(elementId); - collectionElementBuilder.setResource(collectionAdapter); - LogisticsSolutionElement collectionElement = collectionElementBuilder.build(); - - //The LogisticsSolutionElement is now inserted into the only LogisticsSolution of the LSP - Id collectionSolutionId = Id.create("CollectionSolution", LogisticsSolution.class); - LogisticsSolutionImpl.Builder collectionSolutionBuilder = LogisticsSolutionImpl.Builder.newInstance(collectionSolutionId); - collectionSolutionBuilder.addSolutionElement(collectionElement); - LogisticsSolution collectionSolution = collectionSolutionBuilder.build(); - - //Create cost tracker and add it to solution - LinearCostTracker tracker = new LinearCostTracker(0.2); - tracker.getEventHandlers().add(new TourStartHandler()); - tracker.getEventHandlers().add(new CollectionServiceHandler()); - tracker.getEventHandlers().add(new DistanceAndTimeHandler(network)); - collectionSolution.addSimulationTracker(tracker); - - - //The initial plan of the lsp is generated and the assigner and the solution from above are added - LSPPlanImpl collectionPlan = new LSPPlanImpl(); - ShipmentAssigner assigner = new DeterministicShipmentAssigner(); - collectionPlan.setAssigner(assigner); - collectionPlan.addSolution(collectionSolution); - - LSPImpl.Builder collectionLSPBuilder = LSPImpl.Builder.getInstance(); - collectionLSPBuilder.setInitialPlan(collectionPlan); - Id collectionLSPId = Id.create("CollectionLSP", LSP.class); - collectionLSPBuilder.setId(collectionLSPId); - - //The exogenous list of Resoruces for the SolutionScheduler is compiled and the Scheduler is added to the LSPBuilder - ArrayList resourcesList = new ArrayList(); - resourcesList.add(collectionAdapter); - SolutionScheduler simpleScheduler = new SimpleForwardSolutionScheduler(resourcesList); - collectionLSPBuilder.setSolutionScheduler(simpleScheduler); - - return collectionLSPBuilder.build(); - - } - - public static Collection createInitialLSPShipments(Network network){ - ArrayList shipmentList = new ArrayList(); - ArrayList linkList = new ArrayList(network.getLinks().values()); - Id collectionLinkId = Id.createLinkId("(4 2) (4 3)"); - Id toLinkId = collectionLinkId; - - //Create five LSPShipments that are located in the left half of the network. - for(int i = 1; i < 6; i++) { - Id id = Id.create(i, LSPShipment.class); - LSPShipmentImpl.Builder builder = LSPShipmentImpl.Builder.newInstance(id); - Random random = new Random(1); - int capacityDemand = random.nextInt(4); - builder.setCapacityDemand(capacityDemand); - - while(true) { - Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); - if(pendingFromLink.getFromNode().getCoord().getX() <= 4000 && - pendingFromLink.getFromNode().getCoord().getY() <= 4000 && - pendingFromLink.getToNode().getCoord().getX() <= 4000 && - pendingFromLink.getToNode().getCoord().getY() <= 4000) { - builder.setFromLinkId(pendingFromLink.getId()); - break; - } - } - - builder.setToLinkId(toLinkId); - TimeWindow endTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setEndTimeWindow(endTimeWindow); - TimeWindow startTimeWindow = TimeWindow.newInstance(0,(24*3600)); - builder.setStartTimeWindow(startTimeWindow); - builder.setServiceTime(capacityDemand * 60); - shipmentList.add(builder.build()); - } - return shipmentList; - } - - - public static void main (String [] args) { - - //Set up required MATSim classes - Config config = new Config(); - config.addCoreModules(); - Scenario scenario = ScenarioUtils.createScenario(config); - new MatsimNetworkReader(scenario.getNetwork()).readFile("input/lsp/network/2regions.xml"); - Network network = scenario.getNetwork(); - - //Create LSP and shipments - LSP lsp = createLSPWithTracker(network); - Collection shipments = createInitialLSPShipments(network); - - //assign the shipments to the LSP - for(LSPShipment shipment : shipments) { - lsp.assignShipmentToLSP(shipment); - } - - //schedule the LSP with the shipments and according to the scheduler of the Resource - lsp.scheduleSoultions(); - - //Prepare LSPModule and add the LSP - ArrayList lspList = new ArrayList(); - lspList.add(lsp); - LSPs lsps = new LSPs(lspList); - LSPModule module = new LSPModule(lsps, new LSPReplanningModuleImpl(lsps), new LSPScoringModuleImpl(lsps), EventUtils.getStandardEventCreators()); - - //Start the Mobsim one iteration is sufficient for tracking - Controler controler = new Controler(config); - controler.addOverridingModule(module); - config.controler().setFirstIteration(0); - config.controler().setLastIteration(0); - config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); - config.network().setInputFile("input/lsp/network/2regions.xml"); - controler.run(); - - //Retrieve cost info from lsp - Info costInfo; - for(Info info : lsp.getSelectedPlan().getSolutions().iterator().next().getInfos()) { - if(info.getName() == "cost_function") { - costInfo = info; - for(InfoFunctionValue value : costInfo.getFunction().getValues()){ - System.out.println(value.getName() + " " + value.getValue()); - } - } - } - } -} diff --git a/examples/example/simulationTrackers/FixedCostFunctionValue.java b/examples/example/simulationTrackers/FixedCostFunctionValue.java deleted file mode 100644 index 8ea20f19951..00000000000 --- a/examples/example/simulationTrackers/FixedCostFunctionValue.java +++ /dev/null @@ -1,24 +0,0 @@ -package example.simulationTrackers; - -import lsp.functions.InfoFunctionValue; - -public class FixedCostFunctionValue implements InfoFunctionValue { - - private double value; - - @Override - public String getName() { - return "fixed"; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public void setValue(Double value) { - this.value = value; - } - -} diff --git a/examples/example/simulationTrackers/LinearCostFunctionValue.java b/examples/example/simulationTrackers/LinearCostFunctionValue.java deleted file mode 100644 index 318d9b03c66..00000000000 --- a/examples/example/simulationTrackers/LinearCostFunctionValue.java +++ /dev/null @@ -1,23 +0,0 @@ -package example.simulationTrackers; - -import lsp.functions.InfoFunctionValue; - -public class LinearCostFunctionValue implements InfoFunctionValue { - - private Double value; - - @Override - public String getName() { - return "linear"; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public void setValue(Double value) { - this.value = value; - } -} diff --git a/examples/example/simulationTrackers/LinearCostTracker.java b/examples/example/simulationTrackers/LinearCostTracker.java deleted file mode 100644 index 9e692569f0d..00000000000 --- a/examples/example/simulationTrackers/LinearCostTracker.java +++ /dev/null @@ -1,108 +0,0 @@ -package example.simulationTrackers; - -import java.util.ArrayList; -import java.util.Collection; - -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.events.handler.EventHandler; - -import lsp.functions.Info; -import lsp.functions.InfoFunctionValue; -import lsp.tracking.SimulationTracker; -import testLSPWithCostTracker.CollectionServiceHandler; -import testLSPWithCostTracker.CostInfo; -import testLSPWithCostTracker.DistanceAndTimeHandler; -import testLSPWithCostTracker.FixedCostFunctionValue; -import testLSPWithCostTracker.LinearCostFunctionValue; -import testLSPWithCostTracker.TourStartHandler; - -public class LinearCostTracker implements SimulationTracker{ - - private Collection eventHandlers; - private Collection infos; - private double distanceCosts; - private double timeCosts; - private double loadingCosts; - private double vehicleFixedCosts; - private int totalNumberOfShipments; - private int totalWeightOfShipments; - - private double fixedUnitCosts; - private double linearUnitCosts; - - private double shareOfFixedCosts; - - public LinearCostTracker(double shareOfFixedCosts) { - this.shareOfFixedCosts = shareOfFixedCosts; - CostInfo costInfo = new CostInfo(); - infos = new ArrayList(); - infos.add(costInfo); - this.eventHandlers = new ArrayList(); - } - - - @Override - public Collection getEventHandlers() { - return eventHandlers; - } - - @Override - public Collection getInfos() { - return infos; - } - - @Override - public void notifyAfterMobsim(AfterMobsimEvent event) { - for(EventHandler handler : eventHandlers) { - if(handler instanceof TourStartHandler) { - TourStartHandler startHandler = (TourStartHandler) handler; - this.vehicleFixedCosts = startHandler.getVehicleFixedCosts(); - } - if(handler instanceof DistanceAndTimeHandler) { - DistanceAndTimeHandler distanceHandler = (DistanceAndTimeHandler) handler; - this.distanceCosts = distanceHandler.getDistanceCosts(); - this.timeCosts = distanceHandler.getTimeCosts(); - } - if(handler instanceof CollectionServiceHandler) { - CollectionServiceHandler collectionHandler = (CollectionServiceHandler) handler; - totalNumberOfShipments = collectionHandler.getTotalNumberOfShipments(); - System.out.println(totalNumberOfShipments); - totalWeightOfShipments = collectionHandler.getTotalWeightOfShipments(); - loadingCosts = collectionHandler.getTotalLoadingCosts(); - } - } - - double totalCosts = distanceCosts + timeCosts + loadingCosts + vehicleFixedCosts; - fixedUnitCosts = (totalCosts * shareOfFixedCosts)/totalNumberOfShipments; - linearUnitCosts = (totalCosts * (1-shareOfFixedCosts))/totalWeightOfShipments; - - CostInfo info = (CostInfo) infos.iterator().next(); - for(InfoFunctionValue value : info.getFunction().getValues()) { - if(value instanceof FixedCostFunctionValue) { - ((FixedCostFunctionValue)value).setValue(fixedUnitCosts); - } - if(value instanceof LinearCostFunctionValue) { - ((LinearCostFunctionValue)value).setValue(linearUnitCosts); - } - } - - - } - - - @Override - public void reset() { - distanceCosts = 0; - timeCosts = 0; - loadingCosts = 0; - vehicleFixedCosts = 0; - totalNumberOfShipments = 0; - totalWeightOfShipments = 0; - fixedUnitCosts = 0; - linearUnitCosts = 0; - - } - - - -} \ No newline at end of file diff --git a/examples/example/simulationTrackers/TourStartHandler.java b/examples/example/simulationTrackers/TourStartHandler.java deleted file mode 100644 index 63773d69978..00000000000 --- a/examples/example/simulationTrackers/TourStartHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package example.simulationTrackers; - -import lsp.events.TourStartEvent; -import lsp.events.TourStartEventHandler; - -public class TourStartHandler implements TourStartEventHandler{ - - private double vehicleFixedCosts; - - @Override - public void reset(int iteration) { - vehicleFixedCosts = 0; - } - - @Override - public void handleEvent(TourStartEvent event) { - vehicleFixedCosts = vehicleFixedCosts + event.getVehicle().getVehicleType().getVehicleCostInformation().fix; - } - - public double getVehicleFixedCosts() { - return vehicleFixedCosts; - } - -} diff --git a/examples/examples/ExampleCascadingInfos.java b/examples/examples/ExampleCascadingInfos.java deleted file mode 100644 index 5178e727256..00000000000 --- a/examples/examples/ExampleCascadingInfos.java +++ /dev/null @@ -1,5 +0,0 @@ -package examples; - -public class ExampleCascadingInfos { - -} From d9ad6dd68205096b8d80a82e88c6bcbd4eafa6ac Mon Sep 17 00:00:00 2001 From: kainagel Date: Mon, 28 May 2018 18:57:33 +0200 Subject: [PATCH 0055/1340] change gitattributes to lfs --- .gitattributes | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index 83ad1f3cf10..b49f12be9d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,14 @@ -*.png filter=fat -crlf -*.jpg filter=fat -crlf -*.gz filter=fat -crlf -*.zip filter=fat -crlf \ No newline at end of file +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.csv filter=lfs diff=lfs merge=lfs -text +*.shp filter=lfs diff=lfs merge=lfs -text +*.dbf filter=lfs diff=lfs merge=lfs -text +*.prj filter=lfs diff=lfs merge=lfs -text +*.shx filter=lfs diff=lfs merge=lfs -text +*.mov filter=lfs diff=lfs merge=lfs -text +*.avi filter=lfs diff=lfs merge=lfs -text +#data/** filter=lfs diff=lfs merge=lfs -text +#results/** filter=lfs diff=lfs merge=lfs -text +#It is not so practical to put whole directories under git lfs since then, +#without lfs installed, you cannot even read the README.md. kai, may'18 From 41fa815fef27db52ea38ea490645f8e643e9b1bd Mon Sep 17 00:00:00 2001 From: kainagel Date: Mon, 28 May 2018 18:57:59 +0200 Subject: [PATCH 0056/1340] change gitattributes to lfs --- .gitattributes | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index 83ad1f3cf10..b49f12be9d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,14 @@ -*.png filter=fat -crlf -*.jpg filter=fat -crlf -*.gz filter=fat -crlf -*.zip filter=fat -crlf \ No newline at end of file +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.csv filter=lfs diff=lfs merge=lfs -text +*.shp filter=lfs diff=lfs merge=lfs -text +*.dbf filter=lfs diff=lfs merge=lfs -text +*.prj filter=lfs diff=lfs merge=lfs -text +*.shx filter=lfs diff=lfs merge=lfs -text +*.mov filter=lfs diff=lfs merge=lfs -text +*.avi filter=lfs diff=lfs merge=lfs -text +#data/** filter=lfs diff=lfs merge=lfs -text +#results/** filter=lfs diff=lfs merge=lfs -text +#It is not so practical to put whole directories under git lfs since then, +#without lfs installed, you cannot even read the README.md. kai, may'18 From 5b08972b90c01e1be86f62c40d040b7b16305b30 Mon Sep 17 00:00:00 2001 From: kainagel Date: Mon, 28 May 2018 20:35:41 +0200 Subject: [PATCH 0057/1340] travis.yml --- .travis.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index dff5f3a5d02..26077a081c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,17 @@ language: java +jdk: oraclejdk8 +addons: + apt: + packages: + - oracle-java8-installer # https://github.com/travis-ci/travis-ci/issues/3259 +script: + - mvn package -B -Dmatsim.preferLocalDtds=true +# --fail-at-end +# -Dmaven.test.redirectTestOutputToFile +env: + global: + - MAVEN_OPTS="-Xmx2g" +cache: + directories: + - $HOME/.m2 + From a02fd45625fd9c73ea7647f2f571c1e212bfe66d Mon Sep 17 00:00:00 2001 From: "Johan W. Joubert" Date: Sat, 23 Jun 2018 12:17:07 +0200 Subject: [PATCH 0058/1340] Added test jar for MatsimTestUtils --- pom.xml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 9344fc86147..6aeac79b864 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -15,7 +16,7 @@ matsim https://dl.bintray.com/matsim/matsim - + ojo-snapshots http://oss.jfrog.org/libs-snapshot @@ -35,7 +36,14 @@ matsim 0.11.0-SNAPSHOT - + + org.matsim + matsim + test-jar + 0.11.0-SNAPSHOT + test + + org.matsim.contrib freight 0.11.0-SNAPSHOT From 1665d5e2c6f90f75736e1ae63dc1b9650c1b7291 Mon Sep 17 00:00:00 2001 From: "Johan W. Joubert" Date: Sat, 23 Jun 2018 12:17:31 +0200 Subject: [PATCH 0059/1340] All tests Passed locally before committing. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0f19fb612ba..38426bd6f4c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ hs_err_pid* /bin/ /.idea/ -*.iml \ No newline at end of file +*.iml +/test/output From a5f76ca0e835941e8fc8ff2deb64368d25ebe0b5 Mon Sep 17 00:00:00 2001 From: "Johan W. Joubert" Date: Tue, 3 Jul 2018 13:12:29 +0200 Subject: [PATCH 0060/1340] Ignore file written by experiment --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 38426bd6f4c..44a19572db9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ hs_err_pid* /.idea/ *.iml /test/output +/input/carrierPlanned.xml From 49d797340fe6f5fb4a4652e19b53fb2ecbb5630b Mon Sep 17 00:00:00 2001 From: "Johan W. Joubert" Date: Wed, 25 Jul 2018 14:17:23 +0200 Subject: [PATCH 0061/1340] Update receiver setup for run on Hobbes server --- pom.xml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pom.xml b/pom.xml index 6aeac79b864..90ceda6d997 100644 --- a/pom.xml +++ b/pom.xml @@ -112,4 +112,37 @@ + + + + release + + assembly:assembly + + + + maven-assembly-plugin + + + src/main/assembly/assembly-release.xml + + + + + maven-jar-plugin + + + + true + libs/ + + + + + + + + + + From 92d9618f95a4ce8eff2a1325c780e92e4d3ff07e Mon Sep 17 00:00:00 2001 From: "Johan W. Joubert" Date: Wed, 25 Jul 2018 14:21:26 +0200 Subject: [PATCH 0062/1340] Add assembly configuration --- src/main/assembly/assembly-release.xml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/assembly/assembly-release.xml diff --git a/src/main/assembly/assembly-release.xml b/src/main/assembly/assembly-release.xml new file mode 100644 index 00000000000..aa013c26a4e --- /dev/null +++ b/src/main/assembly/assembly-release.xml @@ -0,0 +1,25 @@ + + release + true + ${artifactId}-${version} + + zip + + + + ${project.build.directory}/${project.build.finalName}.jar + / + + + + + + false + /libs/ + false + + + + From e86f2f4ee2b7cc4e27cdc95b73479293c67ceba7 Mon Sep 17 00:00:00 2001 From: "Johan W. Joubert" Date: Fri, 31 Aug 2018 17:11:15 +0300 Subject: [PATCH 0063/1340] Fix package settings in pom to include input files --- pom.xml | 91 +++++++++++++------------- src/main/assembly/assembly-release.xml | 12 +++- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index 90ceda6d997..ac9c72048c5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,9 +6,14 @@ org.matsim.projects freight-dfg17 0.0.1-SNAPSHOT - freight-dfg17 freight-dfg17 internal data not to be put on public github matsim/freight-contrib repository + + https://github.com/matsim-org/matsim + scm:git:git://github.com/matsim-org/matsim.git + scm:git:git@github.com:matsim-org/matsim.git + + @@ -60,6 +65,27 @@ + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.4 + + + validate + + create + + + + + false + false + unknown + {0,date,yyyy-MM-dd HH:mm:ss} + + + org.apache.maven.plugins maven-compiler-plugin @@ -80,25 +106,32 @@ + org.apache.maven.plugins - maven-eclipse-plugin + maven-surefire-plugin + 2.19 - true - true + + **/*$* + org/matsim/testcases/TestDepth.java + org/matsim/testcases/MatsimTestCase.java + + once + + -Xmx700m -Djava.awt.headless=true + -Dmatsim.preferLocalDtds=true + maven-assembly-plugin + 2.2.1 + - - jar-with-dependencies - - - - org.matsim.gui.MATSimGUI - - + + src/main/assembly/assembly-release.xml + @@ -112,37 +145,5 @@ - - - - release - - assembly:assembly - - - - maven-assembly-plugin - - - src/main/assembly/assembly-release.xml - - - - - maven-jar-plugin - - - - true - libs/ - - - - - - - - - - + diff --git a/src/main/assembly/assembly-release.xml b/src/main/assembly/assembly-release.xml index aa013c26a4e..ba38d137b0b 100644 --- a/src/main/assembly/assembly-release.xml +++ b/src/main/assembly/assembly-release.xml @@ -2,11 +2,19 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> release - true + zip + + + + ./input/ + input + + + ${project.build.directory}/${project.build.finalName}.jar From 3928847b8de500ed7707ae06392735388635302e Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 5 Sep 2018 12:53:10 +0200 Subject: [PATCH 0064/1340] Minor Changes --- src/test/java/lspCreationTests/CompleteLSPCreationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/lspCreationTests/CompleteLSPCreationTest.java b/src/test/java/lspCreationTests/CompleteLSPCreationTest.java index f47d42475e7..9e1f66f750e 100644 --- a/src/test/java/lspCreationTests/CompleteLSPCreationTest.java +++ b/src/test/java/lspCreationTests/CompleteLSPCreationTest.java @@ -229,7 +229,7 @@ public void initialize() { assigner = new DeterministicShipmentAssigner(); LSPPlan completePlan = new LSPPlanImpl(); - completePlan.setAssigner(assigner);; + completePlan.setAssigner(assigner); completeSolution = completeSolutionBuilder.build(); completePlan.addSolution(completeSolution); From 85428f0c42fa0fd6a784827175275b250c072ac0 Mon Sep 17 00:00:00 2001 From: matt_ti Date: Wed, 5 Sep 2018 12:57:36 +0200 Subject: [PATCH 0065/1340] Minor changes --- pom.xml | 13 +++++++++++++ src/main/java/lsp/shipment/LSPShipment.java | 4 ++++ src/main/java/lsp/shipment/LSPShipmentImpl.java | 14 ++++++++++++++ .../lsp/usecase/CollectionCarrierScheduler.java | 9 +++++---- .../lsp/usecase/DistributionCarrierScheduler.java | 3 ++- .../usecase/DistributionServiceEventHandler.java | 10 ++++++---- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 9344fc86147..6aeb3a047fc 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,19 @@ 4.12 test + + org.apache.poi + poi-ooxml + 3.17 + + + com.opencsv + opencsv + 4.0 + + + + diff --git a/src/main/java/lsp/shipment/LSPShipment.java b/src/main/java/lsp/shipment/LSPShipment.java index 6667d3a9885..0b20fe20ccc 100644 --- a/src/main/java/lsp/shipment/LSPShipment.java +++ b/src/main/java/lsp/shipment/LSPShipment.java @@ -9,6 +9,7 @@ import org.matsim.core.events.handler.EventHandler; import demand.utilityFunctions.UtilityFunction; +import lsp.LogisticsSolution; import lsp.functions.Info; public interface LSPShipment { @@ -39,5 +40,8 @@ public interface LSPShipment { public Collection getInfos(); + public Id getSolutionId(); + + public void setSolutionId(Id Id); } diff --git a/src/main/java/lsp/shipment/LSPShipmentImpl.java b/src/main/java/lsp/shipment/LSPShipmentImpl.java index 916d6da02d9..d7bc93bb53c 100644 --- a/src/main/java/lsp/shipment/LSPShipmentImpl.java +++ b/src/main/java/lsp/shipment/LSPShipmentImpl.java @@ -9,6 +9,7 @@ import org.matsim.core.events.handler.EventHandler; import demand.utilityFunctions.UtilityFunction; +import lsp.LogisticsSolution; import lsp.functions.Info; public class LSPShipmentImpl implements LSPShipment { @@ -26,6 +27,7 @@ public class LSPShipmentImpl implements LSPShipment { private ArrayList requirements; private ArrayList utilityFunctions; private ArrayList infos; + private Id solutionId; public static class Builder { @@ -197,4 +199,16 @@ public Collection getInfos() { return infos; } + + public Id getSolutionId() { + return solutionId; + } + + + public void setSolutionId(Id solutionId) { + this.solutionId = solutionId; + } + + + } diff --git a/src/main/java/lsp/usecase/CollectionCarrierScheduler.java b/src/main/java/lsp/usecase/CollectionCarrierScheduler.java index b26aafb069e..c1c40f753f4 100644 --- a/src/main/java/lsp/usecase/CollectionCarrierScheduler.java +++ b/src/main/java/lsp/usecase/CollectionCarrierScheduler.java @@ -42,9 +42,10 @@ class LSPCarrierPair{ public LSPCarrierPair(ShipmentTuple tuple, CarrierService service){ this.tuple = tuple; this.service = service; - } + } + } - + private Carrier carrier; private CollectionCarrierAdapter adapter; private ArrayListpairs; @@ -121,7 +122,7 @@ private void routeCarrier(){ VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp); - + algorithm.setMaxIterations(1); Collection solutions = algorithm.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); @@ -132,7 +133,7 @@ private void routeCarrier(){ } - public void updateShipments() { + protected void updateShipments() { for(ShipmentTuple tuple : shipments) { updateShipment(tuple); } diff --git a/src/main/java/lsp/usecase/DistributionCarrierScheduler.java b/src/main/java/lsp/usecase/DistributionCarrierScheduler.java index 495ef906ea4..92be4c20c13 100644 --- a/src/main/java/lsp/usecase/DistributionCarrierScheduler.java +++ b/src/main/java/lsp/usecase/DistributionCarrierScheduler.java @@ -118,6 +118,7 @@ protected void scheduleResource() { private CarrierService convertToCarrierService(ShipmentTuple tuple){ Id serviceId = Id.create(tuple.getShipment().getId().toString(), CarrierService.class); CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, tuple.getShipment().getToLinkId()); + //builder.setServiceStartTimeWindow(tuple.getShipment().getEndTimeWindow()); builder.setCapacityDemand(tuple.getShipment().getCapacityDemand()); builder.setServiceDuration(tuple.getShipment().getServiceTime()); CarrierService service = builder.build(); @@ -133,7 +134,7 @@ private void routeCarrier(Carrier carrier){ VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp); - + algorithm.setMaxIterations(1); Collection solutions = algorithm.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); diff --git a/src/main/java/lsp/usecase/DistributionServiceEventHandler.java b/src/main/java/lsp/usecase/DistributionServiceEventHandler.java index c3d3f62fe0c..fa1429fb8fb 100644 --- a/src/main/java/lsp/usecase/DistributionServiceEventHandler.java +++ b/src/main/java/lsp/usecase/DistributionServiceEventHandler.java @@ -5,6 +5,8 @@ import lsp.events.ServiceEndEvent; import lsp.events.ServiceEndEventHandler; +import lsp.events.ServiceStartEvent; +import lsp.events.ServiceStartEventHandler; import lsp.LogisticsSolutionElement; import lsp.resources.CarrierResource; import lsp.shipment.AbstractShipmentPlanElement; @@ -12,7 +14,7 @@ import lsp.shipment.LoggedShipmentTransport; import lsp.shipment.LoggedShipmentUnload; -public class DistributionServiceEventHandler implements ServiceEndEventHandler { +public class DistributionServiceEventHandler implements ServiceStartEventHandler { private CarrierService carrierService; private LSPShipment lspShipment; @@ -33,14 +35,14 @@ public void reset(int iteration) { } @Override - public void handleEvent(ServiceEndEvent event) { + public void handleEvent(ServiceStartEvent event) { if (event.getService().getId() == carrierService.getId() && event.getCarrierId() == resource.getCarrier().getId()) { logTransport(event); logUnload(event); } } - private void logTransport(ServiceEndEvent event) { + private void logTransport(ServiceStartEvent event) { String idString = resource.getId() + "" + solutionElement.getId() + "" + "TRANSPORT"; Id id = Id.create(idString, AbstractShipmentPlanElement.class); AbstractShipmentPlanElement abstractPlanElement = lspShipment.getLog().getPlanElements().get(id); @@ -50,7 +52,7 @@ private void logTransport(ServiceEndEvent event) { } } - private void logUnload(ServiceEndEvent event) { + private void logUnload(ServiceStartEvent event) { LoggedShipmentUnload.Builder builder = LoggedShipmentUnload.Builder.newInstance(); builder.setCarrierId(event.getCarrierId()); builder.setLinkId(event.getService().getLocationLinkId()); From 7d4f326c0b0c29a30f3359328e91551058f314fd Mon Sep 17 00:00:00 2001 From: kainagel Date: Wed, 5 Sep 2018 17:20:25 +0200 Subject: [PATCH 0066/1340] some changes --- src/main/java/Doxyfile | 2439 +++++++++++++++++++++++++++++++++++ src/main/java/doxyfilter.sh | 3 + 2 files changed, 2442 insertions(+) create mode 100644 src/main/java/Doxyfile create mode 100755 src/main/java/doxyfilter.sh diff --git a/src/main/java/Doxyfile b/src/main/java/Doxyfile new file mode 100644 index 00000000000..ac21d8b8635 --- /dev/null +++ b/src/main/java/Doxyfile @@ -0,0 +1,2439 @@ +# Doxyfile 1.8.13 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = dfg-freight + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = /Users/nagel/doxygen-html/dfg-freight + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = YES + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = org/matsim + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = YES + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 0. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 0 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = YES + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = YES + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = YES + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = NO + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = NO + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = . + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, +# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf. + +FILE_PATTERNS = *.java + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = */jaxb/* + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = doxyfilter.sh + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = YES + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = YES + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = NO + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse-libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 1 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = /Users/nagel/doxygen-html/matsim + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 400 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://www.mathjax.org/mathjax + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /