 .. currentmodule:: larch

==================================================================
28: MTC Motorized - Shared Ride - Non-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 28's nesting structure groups motorized, shared ride, and non-motorized. (`pp. 185 <http://www.caee.utexas.edu/prof/Bhat/COURSES/LM_Draft_060131Final-060630.pdf>`_)

.. testcode::
	
	shared = m.graph.new_node(parameter='mu_shared', children=[2,3], name='Shared')
	motorized = m.graph.new_node(parameter='mu_moto', children=[1,shared,4], name='Motorized')
	nonmotorized= m.graph.new_node(parameter='mu_nonmoto', children=[5,6], name='Nonmotorized')


.. 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('slsqp')
	┣ ...Optimization terminated successfully...
	>>> m.loglike()
	-3439.942...

.. doctest::
	:options: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_NDIFF +SKIP

	>>> print(m.pfo()[['value','initvalue','nullvalue','minimum','maximum','holdfast']])
	                                 value  initvalue  nullvalue  minimum  maximum  holdfast
	Category   Parameter
	CostbyInc  costbyincome        -0.0334        0.0        0.0     -inf      inf         0
	TravelTime motorized_time      -0.0149        0.0        0.0     -inf      inf         0
	           nonmotorized_time   -0.0460        0.0        0.0     -inf      inf         0
	           motorized_ovtbydist -0.1148        0.0        0.0     -inf      inf         0
	Household  hhinc#4             -0.0040        0.0        0.0     -inf      inf         0
	           hhinc#5             -0.0102        0.0        0.0     -inf      inf         0
	           hhinc#6             -0.0064        0.0        0.0     -inf      inf         0
	           vehbywrk_BIKE       -0.7353        0.0        0.0     -inf      inf         0
	           vehbywrk_SR         -0.2250        0.0        0.0     -inf      inf         0
	           vehbywrk_TRANSIT    -0.7031        0.0        0.0     -inf      inf         0
	           vehbywrk_WALK       -0.7652        0.0        0.0     -inf      inf         0
	Zonal      wkcbd_BIKE           0.4154        0.0        0.0     -inf      inf         0
	           wkcbd_SR2            0.2930        0.0        0.0     -inf      inf         0
	           wkcbd_SR3            0.4723        0.0        0.0     -inf      inf         0
	           wkcbd_TRANSIT        0.9307        0.0        0.0     -inf      inf         0
	           wkcbd_WALK           0.1232        0.0        0.0     -inf      inf         0
	           wkempden_BIKE        0.0017        0.0        0.0     -inf      inf         0
	           wkempden_SR2         0.0014        0.0        0.0     -inf      inf         0
	           wkempden_SR3         0.0014        0.0        0.0     -inf      inf         0
	           wkempden_TRANSIT     0.0023        0.0        0.0     -inf      inf         0
	           wkempden_WALK        0.0022        0.0        0.0     -inf      inf         0
	ASCs       ASC_BIKE            -1.1942        0.0        0.0     -inf      inf         0
	           ASC_SR2             -1.2392        0.0        0.0     -inf      inf         0
	           ASC_SR3             -1.6208        0.0        0.0     -inf      inf         0
	           ASC_TRANSIT         -0.4004        0.0        0.0     -inf      inf         0
	           ASC_WALK             0.3468        0.0        0.0     -inf      inf         0
	Other      mu_moto              0.7281        1.0        1.0    0.001      1.0         0
	           mu_nonmoto           0.7659        1.0        1.0    0.001      1.0         0
	           mu_shared            0.2406        1.0        1.0    0.001      1.0         0