SlideShare a Scribd company logo
1 of 14
Download to read offline
SPADE
Javi Palanca
Goals
Simulate different pick-up
strategies for a taxi fleet
Based on agents (SPADE)
Using Agreement
Technologies
Free sandbox
code: https://github.com/javipalanca/taxi_simulator
doc: https://taxi-simulator.readthedocs.io
Taxi Simulator
Agents
TaxiAgent PassengerAgent
CoordinatorAgent
TAXI_WAITING	
TAXI_WAITING_FOR_APPROVAL	
TAXI_MOVING_TO_PASSENGER	
TAXI_IN_PASSENGER_PLACE	
TAXI_MOVING_TO_DESTINY	
PASSENGER_WAITING	
PASSENGER_ASSIGNED	
PASSENGER_IN_TAXI	
PASSENGER_IN_DEST
Request Protocol
TaxiAgent
PassengerAgent CoordinatorAgent
REQUEST_PERFORMATIVE
REQUEST_PERFORMATIVE
PROPOSE_PERFORMATIVE
CANCEL_PERFORMATIVE
ACCEPT_PERFORMATIVE
REFUSE_PERFORMATIVE
GOTO TRAVEL_PROTOCOL pick_up_passenger()
CANCEL_PERFORMATIVE
Strategy Pattern
TaxiAgent
PassengerAgent
CoordinatorAgent
TaxiStrategyBehaviour
PassengerStrategyBehaviour
CoordinatorStrategyBehaviour
def	send_proposal(self,	passenger_id,	content=None)						
def	cancel_proposal(self,	passenger_id,	content=None)					
def	pick_up_passenger(self,	passenger_id,	origin,	dest)		
def	send_request(self,	content=None)	
def	accept_taxi(self,	taxi_aid)							
def	refuse_taxi(self,	taxi_aid)							
def	timeout_receive(self,	timeout=5)			
REQUEST_PROTOCOL
_process(self)
_process(self)
_process(self)
Install
$ pip install --user virtualenv
# Create virtual environment with python 2.7
$ virtualenv --python=`which python2.7` taxi_demo
$ cd taxi_demo/
$ source bin/activate
(taxi-demo)$
# Install taxi simulator
(taxi-demo)$ pip install taxi_simulator
# Run taxi simulator
(taxi-demo)$ taxi_simulator --help
Usage(taxi-demo)$ taxi_simulator --help
Usage: taxi_simulator [OPTIONS]
Console script for taxi_simulator.
Options:
-t, --taxi TEXT Taxi strategy class (default:
AcceptAlwaysStrategyBehaviour).
-p, --passenger TEXT Passenger strategy class (default:
AcceptFirstRequestTaxiBehaviour).
-c, --coordinator TEXT Coordinator strategy class (default:
DelegateRequestTaxiBehaviour).
--port INTEGER Web interface port (default: 9000).
-nt, --num-taxis INTEGER Number of initial taxis to create (default:
0).
-np, --num-passengers INTEGER Number of initial passengers to create
(default: 0).
--name TEXT Coordinator agent name (default:
coordinator).
--passwd TEXT Coordinator agent password (default:
coordinator_passwd).
-bp, --backend-port INTEGER Backend port (default: 5000).
-v, --verbose Show verbose debug.
--help Show this message and exit.
Run
(taxi-demo)$ taxi_simulator --port 9999
INFO:root:XMPP server running.
INFO:root:Running SPADE platform.
INFO:root:Creating 0 taxis and 0 passengers.
INFO:CoordinatorAgent:Coordinator agent running
INFO:CoordinatorAgent:Web interface running at http://127.0.0.1:9999/app
INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Open http://127.0.0.1:9999/app
Default Strategies: Coordinator
class	DelegateRequestTaxiBehaviour(CoordinatorStrategyBehaviour):	
				def	_process(self):	
								msg	=	self._receive(block=True)	
								msg.removeReceiver(coordinator_aid)	
								for	taxi	in	self.myAgent.taxi_agents.values():	
												msg.addReceiver(taxi.getAID())	
												self.myAgent.send(msg)	
												self.logger.debug("Coordinator	sent	request	to	taxi	{}".format(taxi.getName()))
Default Strategies: Taxi
class	AcceptAlwaysStrategyBehaviour(TaxiStrategyBehaviour):	
				def	_process(self):	
								msg	=	self._receive(block=True)	
								content	=	json.loads(msg.getContent())	
								performative	=	msg.getPerformative()	
								self.logger.debug("Taxi	{}	received	request	protocol	from	passenger	{}.".format(self.myAgent.agent_id,	
																																																																																								content["passenger_id"]))	
								if	performative	==	REQUEST_PERFORMATIVE:	
												if	self.myAgent.status	==	TAXI_WAITING:	
																self.send_proposal(content["passenger_id"],	{})	
																self.myAgent.status	=	TAXI_WAITING_FOR_APPROVAL	
																self.logger.debug("Taxi	{}	sent	proposal	to	passenger	{}.".format(self.myAgent.agent_id,	
																																																																																		content["passenger_id"]))	
								elif	performative	==	ACCEPT_PERFORMATIVE:	
												if	self.myAgent.status	==	TAXI_WAITING_FOR_APPROVAL:	
																self.logger.debug("Taxi	{}	got	accept	from	{}".format(self.myAgent.agent_id,	
																																																																						content["passenger_id"]))	
																self.pick_up_passenger(content["passenger_id"],	content["origin"],	content["dest"])	
												else:	
																self.cancel_proposal(content["passenger_id"],	{})	
								elif	performative	==	REFUSE_PERFORMATIVE:	
												self.logger.debug("Taxi	{}	got	refusal	from	{}".format(self.myAgent.agent_id,	
																																																																			content["passenger_id"]))	
												self.myAgent.status	=	TAXI_WAITING
Default Strategies: Passenger
class	AcceptFirstRequestTaxiBehaviour(PassengerStrategyBehaviour):	
				def	_process(self):	
								if	self.myAgent.status	==	PASSENGER_WAITING:	
												self.send_request(content={})	
								msg	=	self.timeout_receive(timeout=5)	
								if	msg:	
												performative	=	msg.getPerformative()	
												if	performative	==	PROPOSE_PERFORMATIVE:	
																taxi_aid	=	msg.getSender()	
																if	self.myAgent.status	==	PASSENGER_WAITING:	
																				self.logger.debug("Passenger	{}	received	proposal	from	{}".format(self.myAgent.agent_id,	
																																																																																						taxi_aid.getName()))	
																				self.accept_taxi(taxi_aid)	
																else:	
																				self.refuse_taxi(taxi_aid)	
												elif	performative	==	CANCEL_PERFORMATIVE:	
																self.myAgent.status	=	PASSENGER_WAITING
Utils
def	build_aid(agent_id):	
				return	aid(name=agent_id	+	"@127.0.0.1",	addresses=["xmpp://"	+	agent_id	+	"@127.0.0.1"])	
coordinator_aid	=	build_aid("coordinator")	
def	random_position():	
			...	
			return	[lat,	lon]	
def	are_close(coord1,	coord2,	tolerance=10):	
				return	vincenty(coord1,	coord2).meters	<	tolerance	
def	request_path(ori,	dest):	
				...	
				return	path,	distance,	duration	
from	geopy	import	vincenty	
vincenty(coord1,	coord2).meters
Exercices
from	taxi_simulator.coordinator	import	CoordinatorStrategyBehaviour	
from	taxi_simulator.passenger	import	PassengerStrategyBehaviour	
from	taxi_simulator.taxi	import	TaxiStrategyBehaviour	
################################################################	
#																																																														#	
#																					Coordinator	Strategy																					#	
#																																																														#	
################################################################	
class	MyCoordinatorStrategy(CoordinatorStrategyBehaviour):	
				def	_process(self):	
							#	Your	code	here	
################################################################	
#																																																														#	
#																									Taxi	Strategy																								#	
#																																																														#	
################################################################	
class	MyTaxiStrategy(TaxiStrategyBehaviour):	
				def	_process(self):	
							#	Your	code	here	
################################################################	
#																																																														#	
#																							Passenger	Strategy																					#	
#																																																														#	
################################################################	
class	MyPassengerStrategy(PassengerStrategyBehaviour):	
				def	_process(self):	
							#	Your	code	here	
1. Closest taxi strategy 



2. Dynamic closest taxi

strategy

(cancelling ongoing taxis)
my_strategies.py
(taxi-demo)$ taxi_simulator --port 9999 --coordinator my_strategies.MyCoordinatorStrategy
--taxi my_strategies.MyTaxiStrategy --passenger my_strategies.MyPassengerStrategy

More Related Content

Similar to Taxi Simulator

Similar to Taxi Simulator (20)

STEP Annual Conference 2018 - Merry Scott, Liftshare Smart Parking and Scoping
STEP Annual Conference 2018 - Merry Scott, Liftshare Smart Parking and Scoping STEP Annual Conference 2018 - Merry Scott, Liftshare Smart Parking and Scoping
STEP Annual Conference 2018 - Merry Scott, Liftshare Smart Parking and Scoping
 
Automatic car parking system with and without password report
Automatic car parking system with and without password reportAutomatic car parking system with and without password report
Automatic car parking system with and without password report
 
On demand taxi service mobile app platform
On demand taxi service mobile  app platformOn demand taxi service mobile  app platform
On demand taxi service mobile app platform
 
LSCM ASSIGNMENT 2.docx
LSCM ASSIGNMENT 2.docxLSCM ASSIGNMENT 2.docx
LSCM ASSIGNMENT 2.docx
 
Travel api integration
Travel api integrationTravel api integration
Travel api integration
 
Custom PHP Web Development Company
Custom PHP Web Development CompanyCustom PHP Web Development Company
Custom PHP Web Development Company
 
WordPress Web Development | ManekTech
WordPress Web Development | ManekTechWordPress Web Development | ManekTech
WordPress Web Development | ManekTech
 
Angularjs Web Application Development
 Angularjs Web Application Development Angularjs Web Application Development
Angularjs Web Application Development
 
Opensource Technology
Opensource TechnologyOpensource Technology
Opensource Technology
 
Hands-On Lab: Quickly and Easily Monitor Applications using CA Application Pe...
Hands-On Lab: Quickly and Easily Monitor Applications using CA Application Pe...Hands-On Lab: Quickly and Easily Monitor Applications using CA Application Pe...
Hands-On Lab: Quickly and Easily Monitor Applications using CA Application Pe...
 
Psa car easy apps
Psa car easy appsPsa car easy apps
Psa car easy apps
 
Car Parking Management Software At Watermelon Parking.pptx
Car Parking Management Software At Watermelon Parking.pptxCar Parking Management Software At Watermelon Parking.pptx
Car Parking Management Software At Watermelon Parking.pptx
 
Mobile based app
Mobile based appMobile based app
Mobile based app
 
Intelligent Parking Management System.pptx
Intelligent Parking Management System.pptxIntelligent Parking Management System.pptx
Intelligent Parking Management System.pptx
 
The Role Of Artificial Intelligence in Taxi Booking App Development
The Role Of Artificial Intelligence in Taxi Booking App DevelopmentThe Role Of Artificial Intelligence in Taxi Booking App Development
The Role Of Artificial Intelligence in Taxi Booking App Development
 
Dev summer2016 - Automation code as Production code
Dev summer2016 - Automation code as Production codeDev summer2016 - Automation code as Production code
Dev summer2016 - Automation code as Production code
 
Automated Car Parking Solutions
Automated Car Parking SolutionsAutomated Car Parking Solutions
Automated Car Parking Solutions
 
[WSO2 Integration Summit Bern 2019] API-led Integration
[WSO2 Integration Summit Bern 2019] API-led Integration[WSO2 Integration Summit Bern 2019] API-led Integration
[WSO2 Integration Summit Bern 2019] API-led Integration
 
hSenid Mobile presentation at TADHack
hSenid Mobile presentation at TADHackhSenid Mobile presentation at TADHack
hSenid Mobile presentation at TADHack
 
5 years Business Plan for EParivahan.com
5 years Business Plan for EParivahan.com5 years Business Plan for EParivahan.com
5 years Business Plan for EParivahan.com
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

Taxi Simulator