@@ -576,17 +576,26 @@ run_model <- function(aScenarioInfo, aPeriods=NULL, aVerbose=FALSE, agData=NULL)
576
576
while ( LandAllocator_getLandAreaByCriteria(mLandAllocator , constraints $ string [i ], per ) > constraints $ value [i ] ) {
577
577
currValue <- LandAllocator_getLandAreaByCriteria(mLandAllocator , constraints $ string [i ], per )
578
578
message(" Current value: " , currValue , " , Target value:" , constraints $ value [i ])
579
- landConstraintCost <- landConstraintCost + 1e7
579
+ if ( currValue < 2 * constraints $ value [i ] ) {
580
+ # Use smaller increments when we get close to solution
581
+ landConstraintCost <- landConstraintCost + 1e8
582
+ } else if ( currValue > 20 * constraints $ value [i ] ) {
583
+ # Use smaller increments when we get close to solution
584
+ landConstraintCost <- landConstraintCost + 1e10
585
+ } else {
586
+ landConstraintCost <- landConstraintCost + 1e9
587
+ }
588
+
580
589
# Constraint not met. Adjust cost and recalculate
581
590
Sector_initCalc(mLandAllocator , per , aScenarioInfo , landConstraintCost , constraints $ string [i ])
582
591
LandAllocator_initCalc(mLandAllocator , per , aScenarioInfo )
583
592
LandAllocator_calcFinalLandAllocation(mLandAllocator , per , aScenarioInfo )
584
593
585
594
# Check that we are making progress toward meeting constraint
586
- if ( LandAllocator_getLandAreaByCriteria(mLandAllocator , constraints $ string [i ], per ) > 0.999 * currValue ) {
595
+ if ( LandAllocator_getLandAreaByCriteria(mLandAllocator , constraints $ string [i ], per ) > 0.999999 * currValue ) {
587
596
message(" Progress is not being made. New value (" ,
588
597
LandAllocator_getLandAreaByCriteria(mLandAllocator , constraints $ string [i ], per ),
589
- " ) is less than 0.1 % smaller than old value (" , currValue , " )" )
598
+ " ) is less than 0.0001 % smaller than old value (" , currValue , " )" )
590
599
break
591
600
}
592
601
} # End while loop to meet constraint
0 commit comments