<?xml version="1.0" encoding="UTF-8"?>
<scenario>
    <!-- This is the default solution configuration file.  In this configuration file,
         the user-configurable-solver enables specification of solver components and their ordering.
         The available solver components are (See SolverComponentFactory for more info):
             - bisect-all-solver-component
             - log-newton-raphson-solver-component
             - log-newton-raphson-save-deriv-solver-component
             - bisect-one-solver-component
             - bisect-policy-solver-component
	     - log-newton-raphson-backtracking-solver-component
	     - broyden-solver-component

         Each solver component has some default parameters for SolutionInfo objects
         as well as max iterations for that component.  They also have the ability to
         parse a logic string to determine which markets (or SolutionInfo) to include.
         In this syntax (See SolutionInfoFilterFactory for more info), the following operators
         are allowed:
             - ( .. ) Paranthesis to group logic as necessary
             - !( .. ) The logical NOT operator
             - || The logical OR operator
             - && The logical AND operator
         The available operands:
             - all Includes ALL markets
             - solvable If the market has been tagged solvable (see Market::shouldSolve)
             - solvable-nr If the market has been tagged solvable with newton-raphson
                  (see Market::shouldSolveNR)
             - market-type="[type]" If the market is of type [type]
                  (see Market::convert_type_to_string for type names)
             - market-name="[name]" If the Market::getName() equals [name]
             - unsolved If the market is not currently solved to it's tolerance.

         See SolverFactory for available solvers, note that the default solver is 
         BisectionNRSolver and a different solver can be used for each period.
    -->
    <!-- For historical years we need to make sure some markets which are full calibrated in
         terms of both supply and demand are not included into the solution algorithm or else
         they will fail.
      -->
    <user-configurable-solver year="1975" fillout="1">
        <solution-tolerance>0.002</solution-tolerance>
        <solution-floor>0.0001</solution-floor>
        <calibration-tolerance>0.01</calibration-tolerance>
        <max-model-calcs>1000</max-model-calcs>

        <preconditioner-solver-component>
            <solution-info-filter>solvable && !(has-market-flag="fully-calibrated")</solution-info-filter>
            <ftol>1.0e-2</ftol>
            <max-iterations>2</max-iterations>
        </preconditioner-solver-component>

        <bisect-all-solver-component>
            <bracket-interval>0.5</bracket-interval>
            <max-bracket-iterations>20</max-bracket-iterations>
            <max-iterations>10</max-iterations>
            <use-secant-brackets>0</use-secant-brackets>
			<solution-info-filter>unsolved && solvable && !(has-market-flag="fully-calibrated")</solution-info-filter>
        </bisect-all-solver-component>
        <bisect-all-solver-component>
            <bracket-interval>0.05</bracket-interval>
            <max-bracket-iterations>20</max-bracket-iterations>
            <max-iterations>10</max-iterations>
            <use-secant-brackets>1</use-secant-brackets>
			<solution-info-filter>unsolved && solvable && market-matches="_water withdrawals"</solution-info-filter>
        </bisect-all-solver-component>

        <broyden-solver-component>
            <max-iterations>20</max-iterations>
            <ftol>5.0e-4</ftol>
            <linear-price/>
            <solution-info-filter>solvable-nr && !(has-market-flag="fully-calibrated")</solution-info-filter>
        </broyden-solver-component>
    </user-configurable-solver>
    <user-configurable-solver year="2020" fillout="1">
        <solution-tolerance>0.001</solution-tolerance>
        <solution-floor>0.0001</solution-floor>
        <calibration-tolerance>0.01</calibration-tolerance>
        <max-model-calcs>2500</max-model-calcs>

        <preconditioner-solver-component>
            <solution-info-filter>solvable</solution-info-filter>
            <ftol>1.0e-2</ftol>
            <max-iterations>2</max-iterations>
        </preconditioner-solver-component>

        <bisect-all-solver-component>
            <bracket-interval>0.05</bracket-interval>
            <max-bracket-iterations>20</max-bracket-iterations>
            <max-iterations>10</max-iterations>
            <use-secant-brackets>0</use-secant-brackets>
            <solution-info-filter>unsolved && solvable && price-greater-than="0"</solution-info-filter>
        </bisect-all-solver-component>
        <bisect-all-solver-component>
            <bracket-interval>0.05</bracket-interval>
            <max-bracket-iterations>20</max-bracket-iterations>
            <max-iterations>10</max-iterations>
            <use-secant-brackets>1</use-secant-brackets>
			<solution-info-filter>unsolved && solvable && market-matches="_water withdrawals"</solution-info-filter>
        </bisect-all-solver-component>
        
        <broyden-solver-component>
            <max-iterations>10</max-iterations>
            <ftol>5.0e-4</ftol>
            <linear-price/>
            <solution-info-filter>solvable-nr</solution-info-filter>
        </broyden-solver-component>

    </user-configurable-solver>
    <!-- The SolutionInfoParamParser object allows us to specify the following solution algorithm
         parameters with varying granularity.
         The parameters which can be parsed:
             - solution-tolerance
             - solution-floor
             - bracket-interval
             - max-price-change
             - delta-price
         
         These values can be read by "market-type" or "good" for a given "period" and "region".
         Should a region attribute not be provided, it is assumed to be applied for ALL regions for market-type only.
         If multiple parameters could apply to a single market they are resolved with the following
         priority:
             1) Matches good name and region name
             2) Matches market type and region name
             3) Matches market type with the global region
             4) Default values from the Solver/SolverComponent
    -->
    <solution-info-param-parser>
        <!-- applies to all regions since region attribute is not included -->
        <max-price-change fillout="1" market-type="Trial-Value" period="1">10</max-price-change>
    </solution-info-param-parser>
</scenario>
