git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1496 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
khouadjia 2009-03-11 13:36:27 +00:00
commit 274b633647
23 changed files with 7562 additions and 0 deletions

View file

@ -0,0 +1,32 @@
INCLUDE_DIRECTORIES(${PARADISEO_EO_SRC_DIR}/src
${PARADISEO_MO_SRC_DIR}/src
${PARADISEO_MOEO_SRC_DIR}/src
${PARADISEO_PEO_SRC_DIR}/src
${PEOPSODVRP_SOURCE_DIR}/src)
######################################################################################
######################################################################################
### Specify where CMake can find the libraries
######################################################################################
# Link with the EO library directory, only if you need it
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib)
# Link with the MOEO library directory, only if you need it
LINK_DIRECTORIES(${PARADISEO_MOEO_BIN_DIR}/lib)
# Link with the PEO library directory, only if you need it
LINK_DIRECTORIES(${PARADISEO_PEO_BIN_DIR}/lib)
LINK_DIRECTORIES(${PEOPSODVRP_BINARY_DIR}/src)
# Make sure the linker can find the Hello library once it is built.
add_library (event eoEventScheduler.cpp parser.cpp eoPsoDVRPutils.cpp eoPsoDVRP.cpp eoGlobal.cpp)

View file

@ -0,0 +1,227 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.6
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canoncical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# The program to use to edit the cache.
CMAKE_EDIT_COMMAND = /usr/bin/ccmake
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp/src && /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp/src && /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(CMAKE_COMMAND) -E cmake_progress_start /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp/CMakeFiles /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp/src/CMakeFiles/progress.make
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f CMakeFiles/Makefile2 src/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f CMakeFiles/Makefile2 src/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
src/CMakeFiles/event.dir/rule:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f CMakeFiles/Makefile2 src/CMakeFiles/event.dir/rule
.PHONY : src/CMakeFiles/event.dir/rule
# Convenience name for target.
event: src/CMakeFiles/event.dir/rule
.PHONY : event
# fast build rule for target.
event/fast:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/build
.PHONY : event/fast
# target to build an object file
eoEventScheduler.o:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoEventScheduler.o
.PHONY : eoEventScheduler.o
# target to preprocess a source file
eoEventScheduler.i:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoEventScheduler.i
.PHONY : eoEventScheduler.i
# target to generate assembly for a file
eoEventScheduler.s:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoEventScheduler.s
.PHONY : eoEventScheduler.s
# target to build an object file
eoGlobal.o:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoGlobal.o
.PHONY : eoGlobal.o
# target to preprocess a source file
eoGlobal.i:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoGlobal.i
.PHONY : eoGlobal.i
# target to generate assembly for a file
eoGlobal.s:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoGlobal.s
.PHONY : eoGlobal.s
# target to build an object file
eoPsoDVRP.o:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoPsoDVRP.o
.PHONY : eoPsoDVRP.o
# target to preprocess a source file
eoPsoDVRP.i:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoPsoDVRP.i
.PHONY : eoPsoDVRP.i
# target to generate assembly for a file
eoPsoDVRP.s:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoPsoDVRP.s
.PHONY : eoPsoDVRP.s
# target to build an object file
eoPsoDVRPutils.o:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoPsoDVRPutils.o
.PHONY : eoPsoDVRPutils.o
# target to preprocess a source file
eoPsoDVRPutils.i:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoPsoDVRPutils.i
.PHONY : eoPsoDVRPutils.i
# target to generate assembly for a file
eoPsoDVRPutils.s:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/eoPsoDVRPutils.s
.PHONY : eoPsoDVRPutils.s
# target to build an object file
parser.o:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/parser.o
.PHONY : parser.o
# target to preprocess a source file
parser.i:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/parser.i
.PHONY : parser.i
# target to generate assembly for a file
parser.s:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(MAKE) -f src/CMakeFiles/event.dir/build.make src/CMakeFiles/event.dir/parser.s
.PHONY : parser.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... event"
@echo "... rebuild_cache"
@echo "... eoEventScheduler.o"
@echo "... eoEventScheduler.i"
@echo "... eoEventScheduler.s"
@echo "... eoGlobal.o"
@echo "... eoGlobal.i"
@echo "... eoGlobal.s"
@echo "... eoPsoDVRP.o"
@echo "... eoPsoDVRP.i"
@echo "... eoPsoDVRP.s"
@echo "... eoPsoDVRPutils.o"
@echo "... eoPsoDVRPutils.i"
@echo "... eoPsoDVRPutils.s"
@echo "... parser.o"
@echo "... parser.i"
@echo "... parser.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

View file

@ -0,0 +1,34 @@
# Install script for directory: /home/mustapha/framework/paradiseo-1.1/parallelPsoDvrp/src
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "/usr/local")
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
IF(BUILD_TYPE)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Debug")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
# Set the component getting installed.
IF(NOT CMAKE_INSTALL_COMPONENT)
IF(COMPONENT)
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
ELSE(COMPONENT)
SET(CMAKE_INSTALL_COMPONENT)
ENDIF(COMPONENT)
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
# Install shared libraries without execute permission?
IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
SET(CMAKE_INSTALL_SO_NO_EXE "1")
ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)

View file

@ -0,0 +1,101 @@
/*
* Copyright (C) DOLPHIN Project-Team, Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EODVRPSECONDSELAPSEDCONTINUE_H_
#define EODVRPSECONDSELAPSEDCONTINUE_H_
#include <eo>
#include <eoContinue.h>
template< class EOT>
class eoDVRPSecondsElapsedContinue : public eoContinue<EOT>
{
time_t start;
int seconds;
public:
eoDVRPSecondsElapsedContinue(int nSeconds) : start(time(0)), seconds(nSeconds) {}
void resetStart(){ start = time(0);}
virtual bool operator() ( const eoPop<EOT>& _pop ) {
time_t now = time(0);
time_t diff = now - start;
if (diff >= seconds)
return false; //stop
return true;
}
virtual std::string className(void) const { return "eoSecondsElapsedContinue"; }
void readFrom (std :: istream & __is) {
__is >> start >> seconds;
}
void printOn (std :: ostream & __os) const {
__os << start << ' ' << seconds << std :: endl;
}
};
#endif /*EODVRPSECONDSELAPSEDCONTINUE_H_*/

View file

@ -0,0 +1,133 @@
/*
* Copyright (C) DOLPHIN Project-Team, Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EODVRPSTARTOPOLOGY_H_
#define EODVRPSTARTOPOLOGY_H_
#include <eo>
template < class POT >
class eoDVRPStarTopology:public eoTopology <POT>
{
public:
eoDVRPStarTopology(): eoTopology<POT>(), globalBest(){}
void setup(const eoPop<POT> & _pop)
{
globalBest = bestNeighbour(_pop);
}
void updateNeighborhood(POT & _po,unsigned _indice)
{
if( _po.fitness() < _po.best())
{
_po.best(_po.pLength);
_po.bestRoutes = _po.pRoutes;
_po.bestLength = _po.pLength ;
for(size_t i =0, size = _po.planifiedCustomers.size(); i < size ; ++i)
_po.planifiedCustomers[i].bestRouting = _po.planifiedCustomers[i].pRouting;
_po.firstTimeServiceBestPosition = _po.firstTimeServiceCurrentPosition;
}
if ( _po.best() < globalBest.best())
globalBest = _po ;
}
POT bestNeighbour (const eoPop<POT>& _pop)
{
unsigned index_best =0 ;
if(_pop.size() == 0)
cerr<<"You want to get the bestNeighbour from empty swarm...!!!!!!"<<endl;
for (size_t i=1, size = _pop.size(); i < size ; ++i)
if (_pop[i].best() < _pop[index_best].best()) //tester et v<>rifier
index_best = i;
return _pop[index_best];
}
virtual POT & best (unsigned i = 0){return globalBest; } ;
private:
POT globalBest;
};
#endif /*EODVRPSTARTOPOLOGY_H_*/

View file

@ -0,0 +1,453 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
redouanedz
àà * (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include "eoEventScheduler.h"
#include "eoGlobal.h"
eoEventScheduler::eoEventScheduler(unsigned _nbrts,double _tsim, double _tadvance,
double _tcutoff, const string _filename ):
nbrts(_nbrts),tsim(_tsim), tadvance(_tadvance), tcutoff(_tcutoff), tstep(0.0), tday(0.0), tslice(0.0), filename(_filename){
FindTimeDay();
SetFleetCapacity();
SetTimeSlice();
TIME_STEP =0.0;
TIME_ADVANCE = _tadvance * tday;
}
eoEventScheduler::~eoEventScheduler(){}
double eoEventScheduler::TimeOfSimulation(){return tsim;}
double eoEventScheduler::TimeSlice(){return tslice;}
double eoEventScheduler::TimeStep(){ return tstep;}
double eoEventScheduler::TimeCutoff() {return tcutoff;}
double eoEventScheduler::TimeAdvance(){return tadvance;}
void eoEventScheduler::UpdateTimeStep()
{tstep+= tslice;
TIME_STEP = tstep;}
void eoEventScheduler::setTimeStep(double _tstep){tstep = TIME_STEP = _tstep;}
void eoEventScheduler::setTimeAdvance(double _tadvance){ tadvance = TIME_ADVANCE =_tadvance ;}
double eoEventScheduler::TimeDay(){ return tday;}
std::string eoEventScheduler::TimeToString (double _time){
std::ostringstream oss;
oss << _time;
return oss.str();
}
void eoEventScheduler::SetTimeSlice() { TIME_SLICE = tslice = tday/nbrts;}
void eoEventScheduler::SetTimeDay(const double _tday){tday = TIME_DAY= _tday;}
unsigned eoEventScheduler::CapacityTour() {return VEHICULE_CAPACITY;}
void eoEventScheduler::FindTimeDay(){
ifstream file (filename.c_str());
string line;
unsigned int customer;
double time;
istringstream iss;
do
getline(file,line);
while(line.find("DEPOT_TIME_WINDOW_SECTION")== string::npos);
getline(file,line);
iss.str(line);
iss>>customer>>customer>>time;
iss.clear();
SetTimeDay(time);
file.close();
}
void eoEventScheduler::SetFleetCapacity(){
istringstream iss;
string line;
ifstream filein (filename.c_str());
IsReadable(filein);
do
getline(filein,line);
while(line.find("NUM_VEHICLES")== string::npos);
iss.str(line);
iss>>line>>FLEET_VEHICLES;
iss.clear();
do
getline(filein,line);
while(line.find("CAPACITIES")== string::npos);
iss.str(line);
iss>>line>> VEHICULE_CAPACITY;
iss.clear();
filein.close();
}
void eoEventScheduler::GenerateBenchmark(){
istringstream iss; //Input stream
string fileoutname;
unsigned int customer,TimeOrder,i; // Set of Costumers to serve, and available time of custumer order
const string fileiname = filename;
vector<unsigned int> customers;
string line,
str = fileiname;
str = str.erase(str.size() - 4); // Ajust the name of generated file according to the time slice.
while(TimeStep()<= TimeDay())
{
ifstream filein (fileiname.c_str());
IsReadable(filein); //Read benchmark file
fileoutname = str+ "out." + TimeToString(tstep)+".txt"; // The generated file name is terminated by ".out.txt"
ofstream fileout(fileoutname.c_str());
cout<<">>>>>>>> TimeStep "<<TimeStep()<<endl;
do{
getline(filein,line);
fileout<< line<<endl;
}while (line.find("DEMAND_SECTION")== string::npos);
do
getline(filein,line);
while(line.find("TIME_AVAIL_SECTION")== string::npos);
getline(filein,line);
do{
iss.str(line);
iss>>customer>>TimeOrder;
iss.clear();
if(TimeStep() == 0)
{if (TimeOrder > TimeCutoff() * TimeDay())
customers.push_back(customer);
}
else
if(TimeStep() > TimeCutoff() * TimeDay())
{
if ((TimeOrder > (TimeStep() - TimeSlice())) && (TimeOrder <= TimeCutoff() * TimeDay()))
customers.push_back(customer);
}
else
if ((TimeOrder > (TimeStep()- TimeSlice()) && TimeOrder <= TimeStep()))
customers.push_back(customer);
getline(filein,line);
}while(line.find("EOF")== string::npos);
for ( size_t k = 0; k < customers.size(); ++k)
cout <<customers[k] << '\t';
filein.seekg (std::ios_base::beg); //Return to the beginning of the benchmark file for gather informations about custumers
do
getline(filein,line);
while (line.find("DEMAND_SECTION")== string::npos);
i=0;
getline(filein,line);
while( i< customers.size() && line.find("LOCATION_COORD_SECTION")== string::npos)
{
iss.str(line); //Copy string in the stream
iss>>customer; // Move in the stream
iss.clear();
if(customer==customers[i])
{
fileout <<line<<endl;
i++;
}
getline(filein,line);
}
while(line.find("LOCATION_COORD_SECTION")== string::npos)
getline(filein,line);
fileout<<line<<endl;
getline(filein,line);
i=0;
while( i< customers.size() && line.find("DEPOT_LOCATION_SECTION")== string::npos)
{
iss.str(line);
iss>>customer;
iss.clear();
if(customer==customers[i])
{
fileout <<line<<endl;
i++;
}
getline(filein,line);
}
while(line.find("DURATION_SECTION")== string::npos)
getline(filein,line);
i=0;
fileout<<line<<endl;
getline(filein,line);
while( i< customers.size() && line.find("DEPOT_TIME_WINDOW_SECTION")== string::npos)
{
iss.str(line);
iss>>customer;
iss.clear();
if(customer==customers[i])
{
fileout <<line<<endl;
i++;
}
getline(filein,line);
}
while(line.find("DEPOT_TIME_WINDOW_SECTION")== string::npos)
getline(filein,line);
fileout<<line<<endl;
getline(filein,line);
fileout<<line<<endl;
while(line.find("TIME_AVAIL_SECTION")== string::npos)
getline(filein,line);
i=0;
fileout<<line<<endl;
getline(filein,line);
while( i< customers.size() && line.find("EOF")== string::npos)
{
iss.str(line);
iss>>customer;
iss.clear();
if(customer==customers[i])
{
fileout <<line<<endl;
i++;
}
getline(filein,line);
}
fileout<<"EOF"<<endl; //Terminate new benchmark file
customers.clear();
cout<<endl<<"The Benchmarks was generated in the step of time :"<< TimeStep()<<endl;
filein.close();
fileout.close();
if (TimeStep() > TimeCutoff()*TimeDay())
break;
else
UpdateTimeStep();
}
setTimeStep(0);
cout <<endl<<"-------------All Benchmarks were successfully generated-------------"<<endl;
}

View file

@ -0,0 +1,114 @@
/*
* Copyright (C) DOLPHIN Project-Team, Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOEVENTSCHEDULER_H_
#define EOEVENTSCHEDULER_H_
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "parser.h"
using namespace std;
class eoEventScheduler{
public:
eoEventScheduler(unsigned _nbrts, double _tsim, double _tadvance, //Constructor
double _tcutoff, const string _filename );
~eoEventScheduler();
double TimeOfSimulation(); //Return the global time of simulation
double TimeSlice();
void SetTimeSlice();
double TimeStep();
double TimeCutoff();
double TimeAdvance();
void UpdateTimeStep();
void setTimeStep(double _tstep);
void setTimeAdvance(double _tadvance);
double TimeDay();
void FindTimeDay(); // Find the duration of working day.
void SetTimeDay(double _tday);
std::string TimeToString(double _time); // Convert integer value to string
void GenerateBenchmark(); // Benchmark Generator at each time step
void SetFleetCapacity();
unsigned CapacityTour();
private:
unsigned int nbrts; //nbr of time slices
double tday; // time of working day
double tsim; //time of simulation
double tadvance; // advanced commitement time
double tcutoff; // time of cutoff
double tslice; //time slice
double tstep; // time step
const string filename;//Benchmark name
};
//}
#endif /*EOEVENTSCHEDULER_H_*/

View file

@ -0,0 +1,43 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include "eoGlobal.h"
unsigned VEHICULE_CAPACITY, FLEET_VEHICLES, NBRSLICES ;
double TIME_STEP , TIME_ADVANCE, TIME_SLICE , TIME_DAY, TIME_CUTOFF ;

View file

@ -0,0 +1,49 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOGLOBAL_H_
#define EOGLOBAL_H_
extern unsigned VEHICULE_CAPACITY, FLEET_VEHICLES, NBRSLICES;
extern double TIME_STEP , TIME_SLICE, TIME_ADVANCE, TIME_DAY, TIME_CUTOFF ;
#endif /*EOGLOBAL_H_*/

View file

@ -0,0 +1,218 @@
#ifndef EOPARTICLEDVRP_MESG_H_
#define EOPARTICLEDVRP_MESG_H_
#include <core/eoVector_mesg.h>
#include <eoPsoDVRP.h>
void pack (const eoParticleDVRP & _v)
{
cout<<endl<<"packing particle " <<" Node "<< getNodeRank() << " " << _v.fitness() << " " << _v.best() << endl;
if (_v.invalid())
{
pack((unsigned)0);
}
else
{
pack((unsigned)1);
pack (_v.fitness ());
cout << _v.fitness() << endl;
pack (_v.best());
cout << _v.best() << endl;
}
unsigned len = _v.size();
pack (len);
cout<<"len "<<len<<endl;
for (unsigned i = 0 ; i < len; i ++)
{ pack (_v [i]);
cout<<"_v[i] "<<_v[i]<<endl;
}
for (unsigned i = 0 ; i < len; i ++)
pack (_v.bestPositions[i]);
for (unsigned i = 0 ; i < len; i ++)
pack (_v.velocities[i]);
for(unsigned i=0; i < len ; i++)
{pack(_v.planifiedCustomers[i].id);
pack(_v.planifiedCustomers[i].pRouting.route);
pack(_v.planifiedCustomers[i].pRouting.routePosition);
pack(_v.planifiedCustomers[i].pRouting.is_served);
pack(_v.planifiedCustomers[i].pRouting.serviceTime);
pack(_v.planifiedCustomers[i].bestRouting.route);
pack(_v.planifiedCustomers[i].bestRouting.routePosition);
pack(_v.planifiedCustomers[i].bestRouting.is_served);
pack(_v.planifiedCustomers[i].bestRouting.serviceTime);
pack(_v.planifiedCustomers[i].velocity);
}
unsigned pSizeTours,pSingleTour;
pSizeTours= _v.pRoutes.size();
pack(pSizeTours);
for(unsigned i = 0; i < pSizeTours; i++)
{
pSingleTour = _v.pRoutes[i].size();
pack(pSingleTour);
for(unsigned j = 0; j < pSingleTour; j++)
pack(_v.pRoutes[i][j]);
}
unsigned bestSizeTours, bestSingleTour;
bestSizeTours = _v.bestRoutes.size();
pack(bestSizeTours);
for(unsigned i = 0; i < bestSizeTours; i++)
{
bestSingleTour = _v.bestRoutes[i].size();
pack(bestSingleTour);
for(unsigned j = 0; j < bestSingleTour; j++)
pack(_v.bestRoutes[i][j]);
}
pack(_v.pLength);
pack(_v.bestLength);
for(unsigned i=0; i < len ; i++)
pack(_v.firstTimeServiceCurrentPosition[i]);
for(unsigned i=0; i < len ; i++)
pack(_v.firstTimeServiceBestPosition[i]);
}
void unpack (eoParticleDVRP & _v)
{
unsigned valid;
unpack(valid);
if (! valid)
{
_v.invalidate();
_v.invalidateBest();
}
else
{
double fit;
unpack (fit);
cout<<"fit "<<fit<<endl;
_v.fitness (fit);
unpack(fit);
cout<<"fit "<<fit<<endl;
_v.best(fit);
}
unsigned len;
unpack (len);
_v.resize (len);
cout<<"len "<<len<<endl;
for (unsigned i = 0 ; i < len; i ++)
{unpack (_v [i]);
cout<<"_v[i] "<<_v[i]<<endl;
}
_v.bestPositions.resize(len);
for (unsigned i = 0 ; i < len; i ++)
unpack (_v.bestPositions[i]);
_v.velocities.resize (len);
for (unsigned i = 0 ; i < len; i ++)
unpack (_v.velocities[i]);
_v.planifiedCustomers.resize(len);
for(unsigned i=0; i < len ; i++)
{
unpack(_v.planifiedCustomers[i].id);
cout<<"_v[i] "<<_v.planifiedCustomers[i].id<<endl;
unpack(_v.planifiedCustomers[i].pRouting.route);
unpack(_v.planifiedCustomers[i].pRouting.routePosition);
unpack(_v.planifiedCustomers[i].pRouting.is_served);
unpack(_v.planifiedCustomers[i].pRouting.serviceTime);
unpack(_v.planifiedCustomers[i].bestRouting.route);
unpack(_v.planifiedCustomers[i].bestRouting.routePosition);
unpack(_v.planifiedCustomers[i].bestRouting.is_served);
unpack(_v.planifiedCustomers[i].bestRouting.serviceTime);
unpack(_v.planifiedCustomers[i].velocity);
}
unsigned pSizeTours, pSingleTour;
unpack(pSizeTours);
_v.pRoutes.resize(pSizeTours);
for(unsigned i = 0; i < pSizeTours; i++)
{
unpack(pSingleTour);
_v.pRoutes[i].resize(pSingleTour);
for(unsigned j = 0; j < pSingleTour; j++)
{ unpack(_v.pRoutes[i][j]);
cout<<_v.pRoutes[i][j]<< " ";
}
cout<<endl;
}
unsigned bestSizeTours,bestSingleTour;
unpack(bestSizeTours);
_v.bestRoutes.resize(bestSizeTours);
for(unsigned i = 0; i < bestSizeTours; i++)
{
unpack(bestSingleTour);
_v.bestRoutes[i].resize(bestSingleTour);
for(unsigned j = 0; j < bestSingleTour; j++)
unpack(_v.bestRoutes[i][j]);
}
unpack(_v.pLength);
unpack(_v.bestLength);
_v.firstTimeServiceCurrentPosition.resize(len);
for(unsigned i=0; i < len ; i++)
unpack(_v.firstTimeServiceCurrentPosition[i]);
_v.firstTimeServiceBestPosition.resize(len);
for(unsigned i=0; i < len ; i++)
unpack(_v.firstTimeServiceBestPosition[i]);
}
#endif /*EOPARTICLEDVRP_MESG_H_*/

View file

@ -0,0 +1,777 @@
/*
* Copyright (C) DOLPHIN Project-Team, Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOEASYPSODVRP_H_
#define EOEASYPSODVRP_H_
#include <eo>
#include "eoPsoDVRPflight.h"
#include "eoPsoDVRPvelocity.h"
#include "eoPsoDVRPEvalFunc.h"
#include "eoPsoDVRPEncodeSwarm.h"
#include "eoDVRPSecondsElapsedContinue.h"
#include "eoPsoDVRPInit.h"
#include <eoPopEvalFunc.h>
#include "eoGlobal.h"
template<class POT>
class eoPeoEasyPsoDVRP:public eoPSO < POT >
{
public :
/* eoPeoEasyPsoDVRP(eoPsoDVRPEncodeSwarm<POT> & _encoding,
// eoEvalFunc< POT > &_eval,
eoPsoDVRPEvalFunc<POT> &_evalDvrp,
eoPsoDVRPvelocity < POT > &_velocity,
eoFlight < POT > &_move,
eoContinue <POT> &_continuator,
eoParticleBestInit <POT> &_initBest
):
encoding(_encoding),
eval (_eval),
loopEval(_eval),
popEval(loopEval),
velocity (_velocity),
move (_move),
continuator(_continuator),
initBest(_initBest)
{}
*/
eoPeoEasyPsoDVRP(eoPsoDVRPEncodeSwarm<POT> & _encoding,
eoEvalFunc < POT > &_eval,
eoPopEvalFunc < POT > &_popEval,
eoPsoDVRPvelocity < POT > &_velocity,
eoFlight < POT > &_move,
eoContinue <POT> &_continuator,
eoGenContinue <POT> &_genContinuator,
eoParticleBestInit <POT> &_initBest
):
encoding(_encoding),
eval (_eval),
loopEval(_eval),
popEval(loopEval),
velocity (_velocity),
move (_move),
continuator(_continuator),
genContinuator(_genContinuator),
initBest(_initBest)
{}
void operator()(eoPop < POT> &_pop)
{
double _TIME_STEP = TIME_STEP;
try
{
eoPop<POT> empty_pop;
do{
encoding.initParticleToItsBest(_pop);
if(_TIME_STEP < TIME_CUTOFF * TIME_DAY){
if(_TIME_STEP==0)
loadNewCustomers (TIME_DAY,TIME_CUTOFF * TIME_DAY);
else
loadNewCustomers(_TIME_STEP, TIME_SLICE);
PrintLastCustomers();
encoding(_pop,_TIME_STEP,0);
popEval(empty_pop, _pop);
initBest.apply(_pop);
velocity.getTopology().setup(_pop);
}
genContinuator.totalGenerations(genContinuator.totalGenerations());
do
{
velocity.apply(_pop);
move.apply(_pop);
popEval(empty_pop,_pop);
velocity.updateNeighborhood(_pop);
}
while (genContinuator(_pop));
encoding.commitOrders(_pop,_TIME_STEP,TIME_SLICE);
velocity.getTopology().setup(_pop);
_TIME_STEP += TIME_SLICE ;
cout<<_TIME_STEP<< " "<<endl;
}while (continuator(_pop));
closeTours(_pop);
velocity.getTopology().setup(_pop);
//_TIME_STEP += TIME_SLICE ;
//cout<<endl<<getNodeRank() << " "<<_TIME_STEP<< " "<<endl;
//}while(_TIME_STEP < TIME_DAY);
}
catch (std::exception & e)
{
std::string s = e.what ();
s.append (" in eoEasyPSO");
throw std::runtime_error (s);
}
}
private:
eoPsoDVRPEncodeSwarm <POT> & encoding;
eoEvalFunc < POT > &eval;
eoPopLoopEval<POT> loopEval;
eoPopEvalFunc<POT>& popEval;
eoPsoDVRPvelocity < POT > &velocity;
eoFlight < POT > &move;
eoContinue< POT > &continuator;
eoGenContinue < POT > & genContinuator;
eoParticleBestInit <POT> &initBest;
class eoDummyEval : public eoEvalFunc<POT>
{
public:
void operator()(POT & _po)
{}
}dummyEval;
};
void print(eoPop <eoParticleDVRP> &pop,std::ostream &_os)
{
for (size_t i =0, size = pop.size(); i< size ; ++i)
{
_os <<endl<<'\t'<<"---------------------- The Particle ["<<i<<"]----------------------"<< endl;
pop[i].printCurrentPosition(_os);
pop[i].printRoutesOn(_os);
pop[i].printBestPosition(_os);
pop[i].printBestRoutesOn(_os);
}
};
void printRoutes(eoPop <eoParticleDVRP> &pop,std::ostream &_os)
{
for (size_t i =0, size = pop.size(); i< size ; ++i)
{
_os<<endl<<'\t'<<"---------------------- The Particle ["<<i<<"]----------------------"<< endl;
_os<<endl<<"The current fitness of the particule : "<< pop[i].best()<<endl;
pop[i].printRoutesOn(_os);
}
}
void printBestRoutes(eoPop <eoParticleDVRP> &pop, std::ostream &_os)
{
for (size_t i =0, size = pop.size(); i< size ; ++i)
{
_os <<endl<<'\t'<<"---------------------- The Particle ["<<i<<"]----------------------"<< endl;
_os<<endl<<"The best fitness of the particule : "<< pop[i].best()<<endl;
pop[i].printBestRoutesOn(_os);
}
}
void printBestParticle(eoDVRPStarTopology<eoParticleDVRP> &topology, unsigned _seed, std::ostream &_os)
{
_os <<endl<<'\t'<<"---------------------- THE BEST PARTICLE OF SWARM ----------------------"<< endl;
_os<<endl<<"Seed "<<_seed<<endl;
topology.best().printCurrentPosition(_os);
topology.best().printRoutesOn(_os);
topology.best().printBestPosition(_os);
topology.best().printBestRoutesOn(_os);
topology.best().printfirstBestTimeService(_os);
_os<<endl<<"********************************************************************************************"<<endl;
}
void printVelocities(eoPop <eoParticleDVRP> &pop, std::ostream &_os)
{
for (size_t i =0, size = pop.size(); i<size ; ++i)
{
_os<<endl<<'\t'<<"----------------------The Velocity of Particule ["<< i <<"]----------------------"<< endl;
pop[i].printVelocities(_os);
}
};
void closeTours(eoParticleDVRP & _po)
{
for(size_t i = 0 , size = _po.pRoutes.size(); i < size; ++i)
_po.pRoutes[i].push_back(0);
for(size_t i = 0 , size = _po.bestRoutes.size(); i < size; ++i)
_po.bestRoutes[i].push_back(0);
}
void closeTours(eoPop <eoParticleDVRP> & _pop)
{
for(size_t i = 0 , size = _pop.size(); i < size; ++i)
closeTours(_pop[i]);
}
void resetSwarmToBestParticule(eoPop<eoParticleDVRP>& _pop, eoParticleDVRP _po )
{
for(size_t i = 0 , size = _pop.size() ; i < size ; i++)
_pop[i] = _po ;
}
void HillClimbingSearch( eoParticleDVRP & _po, unsigned sizeNeighboor = 1 )
{
Routes neighborhoodSolution ;
double depotTimeWindow = clients[0].durationService;
double dueTime ;
bool validNeighborSolution ;
neighborhoodSolution = _po.pRoutes ;
validNeighborSolution = false;
for( size_t tr = 0; tr < neighborhoodSolution.size(); tr++)
{
if(_po.serviceIsProgressCurrentPosition(tr))
{
unsigned lastServedCustomer = _po.IndexLastServedCustomerCurrentPosition(tr) ;
unsigned positionLastCustomer = _po.planifiedCustomers[lastServedCustomer].pRouting.routePosition -1;
swapCustomers(neighborhoodSolution[tr],positionLastCustomer);
dueTime = getTimeOfService(neighborhoodSolution[tr], _po.planifiedCustomers[lastServedCustomer].id,_po.planifiedCustomers[lastServedCustomer].pRouting.serviceTime)
+ distance(dist, neighborhoodSolution[tr].back(),0);
}else
{
swapCustomers(neighborhoodSolution[tr], 0 );
dueTime = getTimeOfService(neighborhoodSolution[tr], 0 , _po.firstTimeServiceCurrentPosition[tr]) + distance(dist, neighborhoodSolution[tr].back(),0);
}
if (dueTime <= depotTimeWindow)
{ validNeighborSolution = true ;
break ;
}
}
if(validNeighborSolution)
{
double neighboorFitness = computTourLength(neighborhoodSolution);
// std::cout<< " _po.fitness() " << _po.fitness() << " neighboorFitness "<< neighboorFitness << endl ;
if( neighboorFitness < _po.fitness() )
{
_po.pRoutes = neighborhoodSolution;
_po.reDesign() ;
_po.fitness(neighboorFitness);
}
}
}
void HillClimbingSearch(eoPop<eoParticleDVRP>& _pop, unsigned sizeNeighboor = 1 )
{
for(size_t i = 0, size = _pop.size(); i < size ; i ++ )
HillClimbingSearch(_pop[i], sizeNeighboor) ;
}
bool TwoOptimalAlgorithm (eoParticleDVRP & _po)
{
unsigned lastServedCustomerPosition;
bool twoOptFeasible, changehappen = false ;
double dueTime, depotTimeWindow = clients[0].durationService;
for (size_t tr = 0, size = _po.pRoutes.size() ; tr < size ; tr++)
{
Route routeOpt = _po.pRoutes[tr];
twoOptFeasible =false;
if(_po.serviceIsProgressCurrentPosition(tr))
{
unsigned lastServedCustomer = _po.IndexLastServedCustomerCurrentPosition(tr) ;
lastServedCustomerPosition = _po.planifiedCustomers[lastServedCustomer].pRouting.routePosition -1;
if (twoOptOnRoute(routeOpt,lastServedCustomerPosition))
{
dueTime = getTimeOfService(routeOpt, _po.planifiedCustomers[lastServedCustomer].id,_po.planifiedCustomers[lastServedCustomer].pRouting.serviceTime)
+ distance(dist, routeOpt.back(),0);
twoOptFeasible = true;
}
}
else
{
lastServedCustomerPosition = 0;
if (twoOptOnRoute(routeOpt,lastServedCustomerPosition))
{
dueTime = getTimeOfService(routeOpt, 0 , _po.firstTimeServiceCurrentPosition[tr]) + distance(dist, routeOpt.back(),0);
twoOptFeasible = true;
}
}
if (twoOptFeasible && dueTime <= depotTimeWindow)
{_po.pRoutes[tr] = routeOpt;
changehappen = true;
}
}
if (changehappen)
{
_po.reDesign() ;
_po.invalidate();
return true;
}
return false;
}
void TwoOptimalAlgorithm (eoPop<eoParticleDVRP> & _pop)
{
for(size_t i = 0, size = _pop.size(); i < size ; i++)
TwoOptimalAlgorithm(_pop[i]);
}
bool ThreeOptimalAlgorithm (eoParticleDVRP & _po)
{
unsigned lastServedCustomerPosition;
bool threeOptFeasible, changehappen = false ;
double dueTime, depotTimeWindow = clients[0].durationService;
for (size_t tr = 0, size = _po.pRoutes.size() ; tr < size ; tr++)
{
Route routeOpt = _po.pRoutes[tr];
threeOptFeasible =false;
if(_po.serviceIsProgressCurrentPosition(tr))
{
unsigned lastServedCustomer = _po.IndexLastServedCustomerCurrentPosition(tr) ;
lastServedCustomerPosition = _po.planifiedCustomers[lastServedCustomer].pRouting.routePosition -1;
if (threeOptOnRoute(routeOpt,lastServedCustomerPosition))
{
dueTime = getTimeOfService(routeOpt, _po.planifiedCustomers[lastServedCustomer].id,_po.planifiedCustomers[lastServedCustomer].pRouting.serviceTime)
+ distance(dist, routeOpt.back(),0);
threeOptFeasible = true;
}
}
else
{
lastServedCustomerPosition = 0;
if (threeOptOnRoute(routeOpt,lastServedCustomerPosition))
{
dueTime = getTimeOfService(routeOpt, 0 , _po.firstTimeServiceCurrentPosition[tr]) + distance(dist, routeOpt.back(),0);
threeOptFeasible = true;
}
}
if (threeOptFeasible && dueTime <= depotTimeWindow)
{_po.pRoutes[tr] = routeOpt;
changehappen = true;
}
}
if (changehappen)
{
_po.reDesign() ;
_po.invalidate();
return true;
}
return false;
}
void ThreeOptimalAlgorithm (eoPop<eoParticleDVRP> & _pop)
{
for(size_t i = 0, size = _pop.size(); i < size ; i++)
ThreeOptimalAlgorithm(_pop[i]);
}
void VariableNeighborhoodSearch(eoParticleDVRP & _po, unsigned neighborSize)
{
Routes neighborhoodSolution ;
double dueTime, depotTimeWindow = clients[0].durationService;
bool validNeighborSolution ;
neighborhoodSolution = _po.pRoutes ;
validNeighborSolution = false;
unsigned neighborhoodIndex = 1;
for( size_t tr = 0; tr < neighborhoodSolution.size(); tr++)
{
if(_po.serviceIsProgressCurrentPosition(tr))
{
unsigned lastServedCustomer = _po.IndexLastServedCustomerCurrentPosition(tr) ;
unsigned positionLastCustomer = _po.planifiedCustomers[lastServedCustomer].pRouting.routePosition -1;
for(size_t k = 0 ; k <= neighborhoodIndex ; k++)
swapCustomers(neighborhoodSolution[tr],positionLastCustomer);
dueTime = getTimeOfService(neighborhoodSolution[tr], _po.planifiedCustomers[lastServedCustomer].id,_po.planifiedCustomers[lastServedCustomer].pRouting.serviceTime)
+ distance(dist, neighborhoodSolution[tr].back(),0);
}else
{
for(size_t k = 0 ; k <= neighborhoodIndex ; k++)
swapCustomers(neighborhoodSolution[tr], 0);
dueTime = getTimeOfService(neighborhoodSolution[tr], 0 , _po.firstTimeServiceCurrentPosition[tr]) + distance(dist, neighborhoodSolution[tr].back(),0);
}
if (dueTime <= depotTimeWindow)
{
double neighboorFitness = computTourLength(neighborhoodSolution);
if( neighboorFitness < _po.fitness() )
{
_po.pRoutes = neighborhoodSolution;
_po.reDesign() ;
_po.fitness(neighboorFitness);
if(TwoOptimalAlgorithm(_po))
{
_po.computCurrentTourLength();
_po.fitness(_po.toursLength());
neighborhoodIndex = 1;
continue ;
}
}
}
neighborhoodIndex = (neighborhoodIndex + 1) % neighborSize ;
}
}
void VariableNeighborhoodSearch(eoPop<eoParticleDVRP>& _pop, unsigned neighborSize)
{
for(size_t i = 0, size = _pop.size(); i < size ; i++)
VariableNeighborhoodSearch(_pop[i], neighborSize);
}
double avragePopFitness(eoPop<eoParticleDVRP>& _pop)
{
double average = 0.0;
for(size_t i = 0, size = _pop.size(); i < size ; i ++)
{
average += _pop[i].best();
}
return (average/_pop.size());
}
bool AllCustomersAttributed(eoDVRPStarTopology<eoParticleDVRP> &topology)
{
size_t i = 0;
while (i < topology.best().size())
{
if(!topology.best().planifiedCustomers[i].bestRouting.is_served)
return false;
i++;
}
return true;
}
#endif /*EOEASYPSODVRP_H_*/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,211 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef _eoPsoDVRP_h
#define _eoPsoDVRP_h
#include "eoPsoDVRPutils.h"
using eo::rng;
typedef struct record1 {
int route;
int routePosition;
bool is_served;
double serviceTime;
} routingInfo;
typedef struct record2 {
unsigned id;
routingInfo pRouting;
routingInfo bestRouting;
int velocity;
}particleRouting;
//using namespace eoParticuleDVRPUtils; eoMinimizingFitness
class eoParticleDVRP: public eoVectorParticle <double,int,int> {
public:
eoParticleDVRP();
virtual ~eoParticleDVRP ();
eoParticleDVRP(const eoParticleDVRP& _orig);
void copy(const eoParticleDVRP & _po);
eoParticleDVRP& operator= (const eoParticleDVRP& _orig);
virtual std::string className () const ;
double toursLength ();
void toursLength (const double _pLength);
double bestToursLength();
void bestToursLength (const double _bestLength);
bool clean ();
bool cleanCurrentRoutes ();
bool cleanBestRoutes ();
void printRoutesOn(std::ostream& _os) const;
void printBestRoutesOn(std::ostream& _os) const;
void printOn(std::ostream& _os) const;
void printBestOn(std::ostream& _os) const;
void printVelocities(std::ostream& _os);
void printfirstTimeService(std::ostream& _os);
void printfirstBestTimeService(std::ostream& _os);
void printCurrentPosition(std::ostream& _os)const;
void printBestPosition(std::ostream& _os)const;
void computToursLength();
void computCurrentTourLength();
void computBestTourLength();
void setVelocities();
void setCurrentPositions ();
void setBestPositions();
void encodingCurrentPositionCheapestInsertion(double _tstep, double _tslice);
void encodingCurrentPositionNearestInsertion(double _tstep, double _tslice);
void encodingCurrentPositionGeneralizedInsertion(double _tstep, double _tslice);
void encodingCurrentPositionRandomInsertion(double _tstep, double _tslice);
void encodingBestPosition(double _tstep, double _tslice);
routingInfo & currentRoutingCustomer(unsigned id_customer);
routingInfo & bestRoutingCustomer(unsigned id_customer);
void commitOrdersCurrentPosition (double _nextTstep, double _timeSlice);
void commitOrdersBestPosition (double _nextTstep, double _timeSlice);
bool isServedCustomerInCurrentPosition (unsigned id_customer);
bool isServedCustomerInBestPosition (unsigned id_customer);
void normalizeVelocities();
void eraseRoute(unsigned _tour);
void checkCurrentPosition();
void checkBestPosition();
bool serviceIsProgressCurrentPosition(unsigned _tour);
bool serviceIsProgressBestPosition(unsigned _tour);
unsigned IndexLastServedCustomerCurrentPosition(unsigned _tour);
unsigned IndexLastServedCustomerBestPosition(unsigned _tour);
double timeEndServiceCurrentPosition(unsigned id_customer);
double timeEndServiceBestPosition(unsigned id_customer);
void cleanParticle();
void copyBestToCurrent();
void lastPositionOnRoutes(std::vector<unsigned> & _positions);
void reDesign ();
void checkAll(std::ostream& _os);
//private:
std::vector<particleRouting> planifiedCustomers;
double pLength , bestLength;
Routes pRoutes, bestRoutes;
std::vector<double> firstTimeServiceCurrentPosition;
std::vector<double> firstTimeServiceBestPosition;
};
#endif

View file

@ -0,0 +1,214 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and exper10ienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOPSODVRPENCODESWARM_H_
#define EOPSODVRPENCODESWARM_H_
#include"eoPsoDVRPutils.h"
template < class POT >
class eoPsoDVRPEncodeSwarm
{
public:
eoPsoDVRPEncodeSwarm(){}
void operator()(eoPop<POT> & _pop, double _tstep, double _tslice)
{
/*
vector<unsigned> temp = newCustomers;
if (_insertionMethode == "Hybrid")
{
int i =0 ;
int size = (int)(_pop.size()) / 3;
while(i < size)
{
if (_rebuild =="Rebuild")
_pop[i].cleanParticle();
_pop[i].encodingCurrentPositionRandomInsertion(_tstep, _tslice);
if(_rebuild == "Rebuild")
newCustomers = temp;
i++ ;
}
size = (int)(_pop.size()) * (3/4);
while (i < size)
{
if (_rebuild =="Rebuild")
_pop[i].cleanParticle();
_pop[i].encodingCurrentPositionNearestInsertion(_tstep, _tslice);
if(_rebuild == "Rebuild")
newCustomers = temp;
i++ ;
}
size = (int)(_pop.size());
while( i < size)
{
if (_rebuild =="Rebuild")
_pop[i].cleanParticle();
_pop[i].encodingCurrentPositionCheapestInsertion(_tstep, _tslice);
/*if(_rebuild == "Rebuild")
newCustomers = temp;
i++;
}
}
else
{
*/
for (size_t i =0, size = _pop.size() ; i<size ; ++i)
_pop[i].encodingCurrentPositionRandomInsertion(_tstep, _tslice);
/* {
if (_rebuild =="Rebuild")
_pop[i].cleanParticle();
if(_insertionMethode == "Rand")
_pop[i].encodingCurrentPositionRandomInsertion(_tstep, _tslice);
if(_insertionMethode == "Nearest")//
*/
// _pop[i].encodingCurrentPositionNearestInsertion(_tstep, _tslice);
/*
if(_insertionMethode == "Cheapest")*/
// _pop[i].encodingCurrentPositionCheapestInsertion(_tstep, _tslice);
/* if(_rebuild == "Rebuild")
newCustomers = temp;
}
}*/
}
void commitOrders(eoPop<POT> & _pop, double _tstep, double _tslice)
{
for (size_t i =0, size = _pop.size(); i<size ; ++i)
{
_pop[i].commitOrdersCurrentPosition(_tstep, _tslice);
_pop[i].commitOrdersBestPosition(_tstep, _tslice);
}
}
void initParticleToItsBest(eoPop<POT> & _pop){
for (size_t i =0, size = _pop.size() ; i<size ; ++i)
{
_pop[i].copyBestToCurrent();
for (size_t k = 0 , size = _pop[i].size(); k < size ; k++ )
_pop[i].planifiedCustomers[k].pRouting = _pop[i].planifiedCustomers[k].bestRouting;
_pop[i].pRoutes = _pop[i].bestRoutes;
_pop[i].pLength = _pop[i].bestLength;
_pop[i].firstTimeServiceCurrentPosition = _pop[i].firstTimeServiceBestPosition;
_pop[i].fitness(_pop[i].bestLength);
}
}
};
#endif /*EOPSODVRPENCODESWARM_H_*/

View file

@ -0,0 +1,101 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOPSODVRPEVALFUNC_H_
#define EOPSODVRPEVALFUNC_H_
// General includes
#include <stdexcept>
#include <fstream>
#include "eoEvalFunc.h"
#include "eoPsoDVRP.h"
template <class POT>
class eoPsoDVRPEvalFunc : public eoEvalFunc<POT> {
public:
/**
* \brief Constructor: nothing to do here.
*/
eoPsoDVRPEvalFunc () {}
/**
* \brief Computes the (penalized) fitness
* \param _eo The individual to be evaluated.
*/
void operator () (POT& _po) {
if ( _po.invalid ())
{
_po.toursLength( computTourLength(_po.pRoutes));
_po.fitness( _po.toursLength());
}
if (_po.invalidBest ())
{
_po.bestToursLength( computTourLength(_po.bestRoutes));
_po.best( _po.bestToursLength());
}
}
void operator() (eoPop <POT> &_pop){
for (size_t i=0, size = _pop.size(); i < size; ++i)
operator()(_pop[i]);
}
};
#endif /*EOPSODVRPEVALFUNC_H_*/

View file

@ -0,0 +1,270 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOPSODVRPINIT_H_
#define EOPSODVRPINIT_H_
#include <eo>
#include "eoPsoDVRPEvalFunc.h"
#include "eoDVRPStarTopology.h"
#include "eoPsoDVRPutils.h"
template <class POT>
class eoNothingInit: public eoInit<POT>
{
public:
eoNothingInit(){}
virtual void operator()(POT& _po) {
_po.resize(0);
_po.invalidate ();
}
};
class eoInitialSettings
{
public:
eoInitialSettings( string _benchmarkFile, const double TIME_CUT_OFF, const unsigned NBR_SLICES): benchmarkFile(_benchmarkFile)
{TIME_CUTOFF = TIME_CUT_OFF;
NBRSLICES = NBR_SLICES;
operator()();
}
void operator() () {
loadMatrixCustomers(benchmarkFile);
computeDistances();
SetFleetCapacity(benchmarkFile);
FindTimeDay(benchmarkFile);
TIME_STEP = TIME_ADVANCE = 0.0;
TIME_SLICE = TIME_DAY/NBRSLICES;
}
void SetFleetCapacity(string filename){
istringstream iss;
string line;
ifstream filein (filename.c_str());
IsReadable(filein);
do
getline(filein,line);
while(line.find("NUM_VEHICLES")== string::npos);
iss.str(line);
iss>>line>>FLEET_VEHICLES;
iss.clear();
do
getline(filein,line);
while(line.find("CAPACITIES")== string::npos);
iss.str(line);
iss>>line>> VEHICULE_CAPACITY;
iss.clear();
filein.close();
}
void FindTimeDay(string filename){
ifstream file (filename.c_str());
string line;
unsigned int customer;
double time;
istringstream iss;
do
getline(file,line);
while(line.find("DEPOT_TIME_WINDOW_SECTION")== string::npos);
getline(file,line);
iss.str(line);
iss>>customer>>customer>>TIME_DAY;
iss.clear();
file.close();
}
private:
string benchmarkFile;
};
/*
template < class POT >
class eoParticleInit : public eoInit<POT>
{
public :
eoParticleInit(){}
void operator()(POT & _po) {
//_po. eoVectorParticle<eoMinimizingFitness,int,int>::operator = _po.bestPositions;
for (size_t i = 0 , size = _po.size(); i < size ; i++ )
_po.planifiedCustomers[i].pRouting = _po.planifiedCustomers[i].bestRouting;
_po.pRoutes = _po.bestRoutes;
_po.pLength = _po.bestLength;
_po.firstTimeServiceCurrentPosition = _po.firstTimeServiceBestPosition;
_po.fitness(_po.bestLength);
}
void operator () (eoPop<POT> &_pop) {
for (size_t i = 0, size = _pop.size(); i < size ; i++)
{
operator()(_pop[i]);
}
}
};
*/
template < class POT >
class eoDVRBestPositionInit: public eoParticleBestInit <POT> // First initializer of swarm
{
public:
eoDVRBestPositionInit () {}
void operator () (POT & _po)
{
_po.bestPositions = _po ;
_po.bestLength = _po.pLength ;
_po.bestRoutes =_po.pRoutes;
//il faut une <20>valuation avant sinon le invalidate best sera faux
_po.best(_po.fitness());
if ( !std::equal( _po.bestPositions.begin(), _po.bestPositions.end(), _po.begin() ) )
std::cerr << "The copy was not performed correctly when initializeBestPosition"<<endl;
for (size_t i=0 , size = _po.planifiedCustomers.size(); i < size ; ++i)
{ _po.planifiedCustomers[i].bestRouting.route = _po.planifiedCustomers[i].pRouting.route ;
_po.planifiedCustomers[i].bestRouting.routePosition = _po.planifiedCustomers[i].pRouting.routePosition ;
_po.planifiedCustomers[i].bestRouting.is_served= _po.planifiedCustomers[i].pRouting.is_served;
_po.planifiedCustomers[i].bestRouting.serviceTime= _po.planifiedCustomers[i].pRouting.serviceTime;
}
_po.firstTimeServiceBestPosition = _po.firstTimeServiceCurrentPosition ;
}
};
#endif /*EOPSODVRPINIT_H_*/

View file

@ -0,0 +1,516 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOPSODVRPFLIGHT_H_
#define EOPSODVRPFLIGHT_H_
#include "eoPsoDVRP.h"
#include "eoPsoDVRPutils.h"
#include "eoGlobal.h"
template < class POT >
class eoPsoDVRPMove:public eoFlight < POT >
{
public:
typedef typename POT::AtomType PositionType;
eoPsoDVRPMove() {}
void operator () (POT & _po)
{
POT _poSave = _po ;
deleteCustomersToMove(_po);
if (_po.pRoutes.size() != 0)
{
for (unsigned customer = 0, size = _po.size() ; customer < size; customer++)
if ( ! (_po.planifiedCustomers[customer].pRouting.is_served))
{
unsigned xLimit = _po.pRoutes.size() -1 ;
PositionType customer_route = _po[customer] -1 ;
PositionType newTour = boundTour((customer_route + _po.velocities[customer]), xLimit); //
repositionCustomer(customer,newTour,_po);
}
}
else
{
_po = _poSave;
for (unsigned customer = 0, size = _po.size() ; customer < size; customer++)
if ( ! (_po.planifiedCustomers[customer].pRouting.is_served))
{
unsigned xLimit = _po.pRoutes.size() -1;
PositionType customer_route = _po[customer] -1 ;
PositionType newTour = boundTour((customer_route + _po.velocities[customer]), xLimit);
repositionCustomerInFirst(customer,newTour,_po);
}
}
_po.invalidate();
}
bool deleteCustomersToMove(POT & _po)
{
for(size_t i = 0; i < _po.size() ; i ++)
{
if( ! _po.planifiedCustomers[i].pRouting.is_served )
{
unsigned route = _po.planifiedCustomers[i].pRouting.route - 1 ;
unsigned position = _po.planifiedCustomers[i].pRouting.routePosition - 1 ;
_po.pRoutes[route].erase(_po.pRoutes[route].begin() + position);
if (_po.pRoutes[route].size()== 1)
_po.eraseRoute(route);
else
for(size_t j = position, sizetr = _po.pRoutes[route].size(); j < sizetr; j++)
for(size_t k = 0 , sizeP = _po.size() ; k < sizeP; k ++)
{
if (_po.planifiedCustomers[k].id == _po.pRoutes[route][j] )
_po.planifiedCustomers[k].pRouting.routePosition -- ;
}
}
}
}
/*
eoRealVectorBounds bounds(po.size(),0,xlimit);
if (bounds.isMinBounded(i))
newTour=std::max(newTour,bounds.minimum(i));
if (bounds.isMaxBounded(i))
newTour=std::min(newTour,bounds.maximum(i));
*/
PositionType boundTour(PositionType tour, unsigned limit)
{
if(limit == 0)
return(0);
else
if (tour <0)
return(((-tour) % limit)) ;
else
if (tour > limit)
return ((tour % limit));
else
return (tour);
}
void repositionCustomer(unsigned _customer, unsigned _tour, POT& _po)
{
Route newRoute;
double dueTime ;
bool commitCustomer ;
unsigned positionNewCustomer;
double depotTimeWindow = clients[0].durationService;
unsigned customer_id = _po.planifiedCustomers[_customer].id;
commitCustomer = false ;
for (size_t j = 0 ; j < _po.pRoutes.size() ; j++ )
{
if(_po.serviceIsProgressCurrentPosition(_tour))
{
unsigned lastServedCustomer =_po.IndexLastServedCustomerCurrentPosition(_tour) ;
unsigned positionLastCustomer = _po.planifiedCustomers[lastServedCustomer].pRouting.routePosition ;
positionNewCustomer = randPosition(positionLastCustomer, _po.pRoutes[_tour].size());
dueTime = getTimeOfService(_po.pRoutes[_tour], _po.planifiedCustomers[lastServedCustomer].id, _po.planifiedCustomers[lastServedCustomer].pRouting.serviceTime, customer_id, positionNewCustomer)
+ distance (dist, _po.pRoutes[_tour].back(),0);
}
else
{
positionNewCustomer = randPosition(1, _po.pRoutes[_tour].size());
dueTime = getTimeOfService(_po.pRoutes[_tour],_po.firstTimeServiceCurrentPosition[_tour], customer_id, positionNewCustomer)+ distance (dist, _po.pRoutes[_tour].back(),0);
}
double demandTour = getCapacityUsed(_po.pRoutes[_tour]) + clients[customer_id].demand;
if (dueTime <= depotTimeWindow && demandTour <= VEHICULE_CAPACITY )
{
_po.pRoutes[_tour].insert(_po.pRoutes[_tour].begin() + positionNewCustomer, customer_id );
_po.planifiedCustomers[_customer].pRouting.route = _po[_customer] = _tour+1;
_po.planifiedCustomers[_customer].pRouting.routePosition = positionNewCustomer +1 ;
for(size_t i = positionNewCustomer +1 , size = _po.pRoutes[_tour].size() ; i < size; i++)
{
for (size_t j = 0 , sizeP = _po.size() ; j < sizeP ; j++)
{
if(_po.planifiedCustomers[j].id == _po.pRoutes[_tour][i])
{
_po.planifiedCustomers[j].pRouting.routePosition ++;
break ;
}
}
}
commitCustomer = true ;
break;
}
_tour = ( _tour + 1 ) % _po.pRoutes.size();
}
if (!commitCustomer)
if (_po.pRoutes.size() < FLEET_VEHICLES)
{
Route newRoute = emptyRoute();
newRoute.push_back(customer_id);
_po.pRoutes.push_back(newRoute);
_po.firstTimeServiceCurrentPosition.push_back(TIME_STEP);// + TIME_SLICE);
_po.planifiedCustomers[_customer].pRouting.route = _po[_customer] = _po.pRoutes.size();
_po.planifiedCustomers[_customer].pRouting.routePosition = _po.pRoutes.back().size() ;
}
else
_po.planifiedCustomers[_customer].pRouting.route =_po[_customer] = _po.planifiedCustomers[_customer].pRouting.routePosition = -1;
}
void repositionCustomerInFirst(unsigned _customer, unsigned _tour, POT& _po)
{
Route newRoute;
double dueTime ;
bool commitCustomer ;
unsigned positionNewCustomer;
double depotTimeWindow = clients[0].durationService;
unsigned customer_id = _po.planifiedCustomers[_customer].id;
unsigned route = _po[_customer] -1 ;
unsigned position = _po.planifiedCustomers[_customer].pRouting.routePosition -1;
_po.pRoutes[route].erase(_po.pRoutes[route].begin() + position);
for ( unsigned i = position, size = _po.pRoutes[route].size(); i < size; i++) ///en premier
{ unsigned upcustomer = _po.pRoutes[route][i];
for (size_t j = 0, Psize = _po.planifiedCustomers.size(); j < Psize ; j++)
if (_po.planifiedCustomers[j].id == upcustomer)
{ _po.planifiedCustomers[j].pRouting.routePosition --;
break;
}
}
if(_po.pRoutes[route].size() == 1 )//&& _po.pRoutes[route].size() >1) //empty tour, only the depot
{ _po.eraseRoute(route);
unsigned xLimit = _po.pRoutes.size() -1 ;
_tour = boundTour(_tour,xLimit);
}
commitCustomer = false ;
for (size_t j = 0 ; j < _po.pRoutes.size() ; j++ )
{
if(_po.serviceIsProgressCurrentPosition(_tour))
{
unsigned lastServedCustomer =_po.IndexLastServedCustomerCurrentPosition(_tour) ;
unsigned positionLastCustomer = _po.planifiedCustomers[lastServedCustomer].pRouting.routePosition ;
positionNewCustomer = randPosition(positionLastCustomer, _po.pRoutes[_tour].size());
dueTime = getTimeOfService(_po.pRoutes[_tour], _po.planifiedCustomers[lastServedCustomer].id, _po.planifiedCustomers[lastServedCustomer].pRouting.serviceTime, customer_id, positionNewCustomer)
+ distance (dist, _po.pRoutes[_tour].back(),0);
}
else
{
positionNewCustomer = randPosition(1, _po.pRoutes[_tour].size());
dueTime = getTimeOfService(_po.pRoutes[_tour],_po.firstTimeServiceCurrentPosition[_tour], customer_id, positionNewCustomer)+ distance (dist, _po.pRoutes[_tour].back(),0);
}
double demandTour = getCapacityUsed(_po.pRoutes[_tour]) + clients[customer_id].demand;
if (dueTime <= depotTimeWindow && demandTour <= VEHICULE_CAPACITY )
{
_po.pRoutes[_tour].insert(_po.pRoutes[_tour].begin() + positionNewCustomer, customer_id );
_po.planifiedCustomers[_customer].pRouting.route = _po[_customer] = _tour+1;
_po.planifiedCustomers[_customer].pRouting.routePosition = positionNewCustomer +1 ;
for(size_t i = positionNewCustomer +1 , size = _po.pRoutes[_tour].size() ; i < size; i++)
{
for (size_t j = 0 , sizeP = _po.size() ; j < sizeP ; j++)
{
if(_po.planifiedCustomers[j].id == _po.pRoutes[_tour][i])
{
_po.planifiedCustomers[j].pRouting.routePosition ++;
break ;
}
}
}
commitCustomer = true ;
break;
}
_tour = ( _tour + 1 ) % _po.pRoutes.size();
}
if (!commitCustomer)
if (_po.pRoutes.size() < FLEET_VEHICLES)
{
Route newRoute = emptyRoute();
newRoute.push_back(customer_id);
_po.pRoutes.push_back(newRoute);
_po.firstTimeServiceCurrentPosition.push_back(TIME_STEP );//+ TIME_SLICE);
_po.planifiedCustomers[_customer].pRouting.route = _po[_customer] = _po.pRoutes.size();
_po.planifiedCustomers[_customer].pRouting.routePosition = _po.pRoutes.back().size() ;
}
else
_po.planifiedCustomers[_customer].pRouting.route =_po[_customer] = _po.planifiedCustomers[_customer].pRouting.routePosition = -1;
}
};
#endif /*EOPSODVRPFLIGHT_H_*/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,201 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef eoPsoDVRPUTILS_H_
#define eoPsoDVRPUTILS_H_
// General includes
#include <vector>
#include <utility>
#include <fstream>
#include <iostream>
#include <sstream>
#include <math.h>
#include <assert.h>
#include <stdlib.h>
#include <eo>
#include "eoEventScheduler.h"
#include "eoGlobal.h"
using namespace std;
typedef std::vector<unsigned> Route;
typedef std::vector< Route > Routes;
typedef struct record {
unsigned id; /**< Client ID number. */
double availTime; /**<Client's time available.*/
double x; /**< Client's 'x' position in the map. */
double y; /**< Client's 'y' position in the map. */
double demand; /**< Client's demand of delivered product. */
double durationService; /**< Client's service time (time needed to serve the product). */
} ClientDataT;
typedef std::vector <ClientDataT> setCustumers;
extern setCustumers clients; // The matrix relative to the customers
extern std::vector<unsigned> newCustomers;
typedef std::vector <std::vector <double> > lengthMatrix ; /**< Distance matrix. */
extern lengthMatrix dist; // The matrix of distances between the customers*/
template<typename T> std::string to_string( const T & Value );
void computeDistances (); // Distance calculation
double computTourLength(Route _route);
double computTourLength(Routes _mRoute);
void getInformation (unsigned _custumer, double& _availTime, double& _durationService); // Obtain certain information about the customer
double distance (const lengthMatrix _dist, unsigned _from, unsigned _to); // Calculate the distance between two customers
bool findClient (unsigned id); // Test if the customer exists
void loadMatrixCustomers (const string _fileName); // Load the benchmark file and fill the customers matrix
void loadNewCustomers(double _timeStep, double _timeSlice);
void PrintCustumers(); //Print the Customers matrix and also distance matrix
void PrintLastCustomers(); // Print the Customers who are comming in the last time slice
void printRoute (const Route& _route);
void printRoutes (const Routes& _routes, std::ostream &_os);
const setCustumers SetKnowClients(); // Return the Customers matrix
const lengthMatrix distanceMatrix(); //Return the distance matrix
double getTimeOfService (Route _route, double _startTime, unsigned _newCustomer_id, unsigned _newPosition);
double getTimeOfService (Route _route, unsigned _lastServedCustomer, double _serviceTime, unsigned _newCustomer_id, unsigned _newPosition);
double getTimeOfService(const Route _route, unsigned _lastServedCustomer_id, double dispo);
double startServiceTime (double _nextTimeStep, double _dispoTime);
double getCapacityUsed (Route _route);
Route emptyRoute();
unsigned randTour(unsigned maxTour);
int randVelocity (int _sizeTour);
unsigned randPosition (unsigned _lastPosition, unsigned _sizeTour);
void checkDistances(const Routes _matrix);
void checkCharge(const Routes _matrix);
void visualization (const Routes _matrix , unsigned _seed, ofstream & _os);
double computTourLength(Routes _routes);
void cheapestInsertionAlgorithm (Route _route, unsigned indexTour,
unsigned lastServedCustomer_id, unsigned lastServedCustomerPosition,
double serviceTime, unsigned customer_id, unsigned & cheapestTour,
double & cheapestTourCost, unsigned & positionCheapestTour, bool & commitCustomer);
void cheapestInsertionAlgorithm (Route _route, unsigned indexTour,
double _startTime, unsigned customer_id, unsigned & cheapestTour,double & cheapestTourCost,
unsigned & positionCheapestTour, bool & commitCustomer) ;
void nearestInsertionAlgorithm (Route _route, unsigned indexTour,
unsigned lastServedCustomer_id, unsigned lastServedCustomerPosition,
double serviceTime, unsigned customer_id, unsigned & nearestTour,
double & nearestTourCost, unsigned & positionNearestTour, bool & commitCustomer);
void nearestInsertionAlgorithm (Route _route, unsigned indexTour,
double _startTime, unsigned customer_id, unsigned & nearestTour,double & nearestTourCost,
unsigned & positionNearestTour, bool & commitCustomer);
void generalizedInsertionTypeOneAlgorithm (Route _route, Route& _Genroute, unsigned indexTour, unsigned lastServedCustomer_id,
unsigned lastServedCustomerPosition, double serviceTime, unsigned customer_id,
unsigned & generalizedTour, unsigned & positionGeneralizedTour, double & generalizedTourCost, bool & commitCustomer);
void generalizedInsertionTypeOneAlgorithm (Route _route, Route & _GenRoute, unsigned indexTour, double _startTime, unsigned customer_id, unsigned & generalizedTour,
unsigned & positionGeneralizedTour, double & generalizedTourCost, bool & commitCustomer);
void InsertionTypeOne(Route& _route, unsigned positionGeneralizedTour, unsigned customer_id, std::vector<unsigned> vertices);
void swapCustomers(Route & _route, unsigned _lastCustomerPosition);
bool twoOptOnRoute( Route & _route , unsigned from);
double GainCost(Route _route, unsigned _from, unsigned _to);
double GainCost(Route _route, unsigned _from, unsigned _to, unsigned _end);
void threeMoveRoute(Route & _route, unsigned _from, unsigned _to, unsigned _end);
bool threeOptOnRoute( Route & _route , unsigned _lastServedCustomerPosition);
#endif /*eoPsoDVRPUTILS_H_*/

View file

@ -0,0 +1,175 @@
/*
* Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord-Europe, 2007-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* (c) Mostepha Redouane Khouadjia <mr.khouadjia@ed.univ-lille1.fr>, 2008
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef EOPSODVRPVELOCITY_H_
#define EOPSODVRPVELOCITY_H_
#include"eoPsoDVRP.h"
template < class POT >
class eoPsoDVRPvelocity:public eoVelocity < POT >
{
public:
typedef typename POT::ParticleVelocityType VelocityType;
eoPsoDVRPvelocity( eoDVRPStarTopology<POT> & _topology,
const double & _w,
const double & _c1,
const double & _c2): topology(_topology),
omega(_w),c1(_c1),c2(_c2){}
void updateNeighborhood(POT & _po,unsigned _indice)
{
topology.updateNeighborhood(_po,_indice);
}
void updateNeighborhood(eoPop<POT> & _pop,unsigned _indice = 0)
{
for (size_t i =0, size = _pop.size() ; i < size; i++)
topology.updateNeighborhood(_pop[i],_indice);
}
eoTopology<POT> & getTopology ()
{
return topology;
}
void operator()(POT & _po,unsigned _indice) {
VelocityType newVelocity;
if(_po.size()!=_po.velocities.size() || _po.bestPositions.size()!= _po.velocities.size())
std::cerr<<"The size of the particle is different to the velocity size...!"<<endl;
if (_po.pRoutes.size() == 0 || _po.bestRoutes.size() ==0)
std::cerr<<" The current position tours, or the best position tours are empty ....!!!!"<<endl;
int Vlimit = _po.pRoutes.size()-1;
for (unsigned j = 0, size = _po.velocities.size(); j < size ; j++)
{
newVelocity= static_cast<int> (omega * _po.velocities[j] + c1 * (_po.bestPositions[j] - _po[j]) + c2 * (topology.best(_indice).bestPositions[j] - _po[j]));
_po.velocities[j]= _po.planifiedCustomers[j].velocity = randVelocity(_po.pRoutes.size()-1) ;//boundVelocity(newVelocity, Vlimit);
}
_po.normalizeVelocities();
}
/* eoRealVectorBounds bounds(_po.size(),-Vlimit,Vlimit);
bounds.adjust_size(_po.size());*/
/* if (bounds.isMinBounded(j))
newVelocity=std::max(newVelocity,bounds.minimum(j));
if (bounds.isMaxBounded(j))
newVelocity=std::min(newVelocity,bounds.maximum(j));*/
VelocityType boundVelocity(VelocityType velocity, int limit)
{
if(limit == 0)
return 0;
else
if(velocity < -limit)
return (velocity % -limit);
else
if (velocity > limit)
return (velocity % limit);
else
return velocity;
}
private:
eoDVRPStarTopology<POT> & topology;
const double & omega; // social/cognitive coefficient
const double & c1; // social/cognitive coefficient
const double & c2; // social/cognitive coefficient
};
#endif /*EOPSODVRPVELOCITY_H_*/

Some files were not shown because too many files have changed in this diff Show more