Deviation Ratio Multiplier

Define the target, define the model's result from the last iteration and move the leaver by that deviation ratio and try again.

Here's a simple example which is not fully templated but is a good start

view simTotEU[rr,dts,rfts->reu,th][]
view RESDTotEnrUseWAdj[rr,rfts,th][]

! variables to change
creview bulbPerDwellExo[rr,dts,bt,th][]
creview useExoBulbPerDwell[][]
view bulbsPerDwell[rr,dts,bt,th][]

creview minorApplPRExog[rr,dts,minat,th][]
creview useExoMinApplPenRate[][]
view minorApplPR[rr,dts,minat,th][]

creview majorApplPenRateExo[rr,mac,th][]
creview useExoMajApplPenRate[][]
view majorApplPenRate[rr,mac,th][]

integer $trackStartYr
integer $trackEndYr
getobjinfo (bulbPerDwellExo[rr,dts,bt,th][1], $trackStartYr; info=sequenceStart, dim=time)
getobjinfo (bulbPerDwellExo[rr,dts,bt,th][1], $trackEndYr; info=sequenceEnd, dim=time)

integer $lastScnYr
getobjinfo (bulbPerDwellExo[rr,dts,bt,th][1], $lastScnYr; info=sequenceEnd, dim=time)

keep varTarget[upperDims,time]

say ("Iteration: ", $fbViewIteration)
if ($fbViewIteration == 1)
	! ** BEGIN USER MUST ADJUST HERE **
	! NOTE I did 2 extracts so that I didn't shrink time out in case there is only 1 tracking year
	varTarget[upperDims,time] = extract (extract (RESDTotEnrUseWAdj[rr,rfts,th]; \
		resFuelTypeSim:electricity, shrink=on); \
		time:$trackStartYr..$trackEndYr)
	! **END
endif 

! ** BEGIN USER MUST ADJUST HERE **
local varResultLI[upperDims,tsTrack] = extract (extract (sum (simTotEU[rr,dts,rfts->reu,th]; \
	dim1=rftsCOreu@resFuelTypeSim, dim2=dwellingTypeSim); \
	resFuelTypeSim:electricity, shrink=on); \
	time:$trackStartYr..$trackEndYr)
! **END

local devRatio[tsTrack] = varTarget[tsTrack] - varResultLI[tsTrack]  / varTarget[tsTrack]
!table (devRatio[tsTrack], varTarget[tsTrack], varResultLI[tsTrack]; overlay=on)
!display (devRatio[tsTrack])


! ** BEGIN USER MUST ADJUST HERE **  ! NOTE sometimes it's different between the first and subsequent iterations
local crevarResultLI_var1[upperDims,time]
local crevarResultLI_var2[upperDims,time]
local crevarResultLI_var3[upperDims,time]
if ($fbViewIteration == 1)
	crevarResultLI_var1[upperDims,time] = bulbsPerDwell[rr,dts,bt,th][1]
	crevarResultLI_var2[upperDims,time] = minorApplPR[rr,dts,minat,th][1]
	crevarResultLI_var3[upperDims,time] = majorApplPenRate[rr,mac,th][1]
else
	crevarResultLI_var1[upperDims,time] = bulbsPerDwell[rr,dts,bt,th][2]
	crevarResultLI_var2[upperDims,time] = minorApplPR[rr,dts,minat,th][2]
	crevarResultLI_var3[upperDims,time] = majorApplPenRate[rr,mac,th][2]
endif
! **END

local numNotConv[] = sum (boolgt (abs (devRatio[tsTrack]), $fbViewTolerance); dim=all)
integer $numNotConv
getobjinfo(numNotConv[], $numNotConv; info=dataElement)
if ($numNotConv == 0) or ($fbViewIteration == $fbViewMaxIters)
	mumble ("   numNotConv = ", $numNotConv, " at iteration ",$fbViewIteration, " stopping due to ")
	if ($numNotConv == 0)
		say ("convergence")
	else
		say ("maximum iterations")
	endif		
	
	! Set the outputs
! ** BEGIN USER MUST ADJUST HERE **  ! NOTE sometimes it's different between the first and subsequent iterations
	bulbPerDwellExo[rr,dts,bt,th][2] = crevarResultLI_var1[upperDims,time]
	useExoBulbPerDwell[][2] = 1

	minorApplPRExog[rr,dts,minat,th][2] = crevarResultLI_var2[upperDims,time]
	useExoMinApplPenRate[][2] = 1

	majorApplPenRateExo[rr,mac,th][2] = crevarResultLI_var3[upperDims,time]
	useExoMajApplPenRate[][2] = 1
! **END

	quit(0)
else
	say ("   numNotConv = ", $numNotConv, " at iteration ",$fbViewIteration, " continuing")
endif

! USER NOTE - this code implies a positive relationship between the variable you are changing and the result
!  for example, move up the input variable and expect the output to also move up.
local multiplier[ts] = extend (min (max (devRatio[tsTrack], -0.5), 0.5) + 1.0; dim=time, end=$lastScnYr)

! ** BEGIN USER MUST ADJUST HERE **  ! NOTE sometimes it's different between the first and subsequent iterations
bulbPerDwellExo[rr,dts,bt,th][2] = crevarResultLI_var1[upperDims,time] * multiplier[ts]
useExoBulbPerDwell[][2] = 1

minorApplPRExog[rr,dts,minat,th][2] = crevarResultLI_var2[upperDims,time] * multiplier[ts]
useExoMinApplPenRate[][2] = 1

majorApplPenRateExo[rr,mac,th][2] = crevarResultLI_var3[upperDims,time] * multiplier[ts]
useExoMajApplPenRate[][2] = 1
! **END

quit(1)