.. currentmodule:: larch

===========================================================
25: MTC Private Auto - Motorized Nested Mode Choice
===========================================================

.. testsetup:: *

	import larch
	import larch.examples
	import pandas
	pandas.set_option('display.max_columns',999)
	pandas.set_option('expand_frame_repr',False)
	pandas.set_option('precision',4)
	larch._doctest_mode_ = True
	
.. testcode::
	
	m = larch.example(17)

Model 25's nesting structure groups motorized and shared ride alternatives. (`pp. 182 <http://www.caee.utexas.edu/prof/Bhat/COURSES/LM_Draft_060131Final-060630.pdf>`_)

Since private auto is completely contained within motorized, we can use the private nest when we define the motorized nest.


.. testcode::
	
	private_auto = m.graph.new_node(parameter='mu_private', children=[1,2,3], name='Private_Auto')
	motorized = m.graph.new_node(parameter='mu_moto', children=[private_auto,4], name='Motorized')

.. testcode::
	
	m.ordering = (
		("CostbyInc","costbyincome",),
		("TravelTime",".*time.*",".*dist.*", ),
		("Household","hhinc.*","vehbywrk.*",),
		("Zonal","wkcbd.*","wkempden.*",),
		("ASCs","ASC.*",),
	)
	
.. doctest::
	:options: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_NDIFF

	>>> m.load_data()
	>>> m.maximize_loglike(method='bhhh')
	┣ ...Optimization terminated successfully...
	>>> m.loglike()
	-3427.166...
	
	>>> print(m.pfo()[['value']])
                                     value
	Category   Parameter
	CostbyInc  costbyincome        -0.0363
	TravelTime motorized_time      -0.0106
	           nonmotorized_time   -0.0471
	           motorized_ovtbydist -0.0995
	Household  hhinc#4             -0.0022
	           hhinc#5             -0.0090
	           hhinc#6             -0.0061
	           vehbywrk_BIKE       -0.6885
	           vehbywrk_SR         -0.3218
	           vehbywrk_TRANSIT    -0.4628
	           vehbywrk_WALK       -0.7052
	Zonal      wkcbd_BIKE           0.5003
	           wkcbd_SR2            0.2753
	           wkcbd_SR3            1.0253
	           wkcbd_TRANSIT        0.7310
	           wkcbd_WALK           0.1416
	           wkempden_BIKE        0.0014
	           wkempden_SR2         0.0016
	           wkempden_SR3         0.0024
	           wkempden_TRANSIT     0.0019
	           wkempden_WALK        0.0022
	ASCs       ASC_BIKE            -1.3790
	           ASC_SR2             -1.6337
	           ASC_SR3             -3.1469
	           ASC_TRANSIT         -0.4069
	           ASC_WALK             0.3391
	Other      mu_moto              0.5322
	           mu_private           0.9236