@@ -11,16 +11,16 @@ current region. For simplicity, it also accepts a `NamedTuple` of keyword argume
1111which is converted into a function that always returns the same keyword arguments
1212for an region.
1313=#
14- @kwdef struct Sweep{Regions <: AbstractVector , RegionKwargs <: Function } <: AI.AbstractAlgorithm
14+ @kwdef struct Sweep{Regions <: Vector , RegionKwargs <: Function } <: AI.Algorithm
1515 regions:: Regions
1616 region_kwargs:: RegionKwargs
1717 iteration:: Int = 0
1818end
19- function Sweep (regions:: AbstractVector , region_kwargs:: NamedTuple , iteration:: Int = 0 )
19+ function Sweep (regions:: Vector , region_kwargs:: NamedTuple , iteration:: Int = 0 )
2020 function region_kwargs_fn (
21- problem:: AI.AbstractProblem ,
22- algorithm:: AI.AbstractAlgorithm ,
23- state:: AI.AbstractState ,
21+ problem:: AI.Problem ,
22+ algorithm:: AI.Algorithm ,
23+ state:: AI.State ,
2424 )
2525 return region_kwargs
2626 end
3030maxiter (algorithm:: Sweep ) = length (algorithm. regions)
3131
3232function AI. step! (
33- problem:: AI.AbstractProblem , algorithm:: Sweep , state:: AI.AbstractState
33+ problem:: AI.Problem , algorithm:: Sweep , state:: AI.State
3434 )
3535 extract! (problem, algorithm, state)
3636 update! (problem, algorithm, state)
@@ -39,82 +39,82 @@ function AI.step!(
3939end
4040
4141function extract! (
42- problem:: AI.AbstractProblem , algorithm:: Sweep , state:: AI.AbstractState
42+ problem:: AI.Problem , algorithm:: Sweep , state:: AI.State
4343 )
4444 # Extraction step goes here.
4545 return state
4646end
4747function update! (
48- problem:: AI.AbstractProblem , algorithm:: Sweep , state:: AI.AbstractState
48+ problem:: AI.Problem , algorithm:: Sweep , state:: AI.State
4949 )
5050 # Update step goes here.
5151 return state
5252end
5353function insert! (
54- problem:: AI.AbstractProblem , algorithm:: Sweep , state:: AI.AbstractState
54+ problem:: AI.Problem , algorithm:: Sweep , state:: AI.State
5555 )
5656 # Insert step goes here.
5757 return state
5858end
5959
6060# TODO : Use a proper stopping criterion.
6161function AI. is_finished (
62- problem:: AI.AbstractProblem , algorithm:: Sweep , state:: AI.AbstractState
62+ problem:: AI.Problem , algorithm:: Sweep , state:: AI.State
6363 )
6464 state. iteration == 0 && return false
6565 return state. iteration >= length (algorithm. regions)
6666end
6767
6868#=
69- Sweeping(sweeps::AbstractVector {<:Sweep})
69+ Sweeping(sweeps::Vector {<:Sweep})
7070
7171The sweeping algorithm, which just stores a list of sweeps defined above.
7272=#
73- struct Sweeping{Sweeps <: AbstractVector {<:Sweep} } <: AI.AbstractAlgorithm
73+ struct Sweeping{Sweeps <: Vector {<:Sweep} } <: AI.Algorithm
7474 sweeps:: Sweeps
7575end
7676
7777maxiter (algorithm:: Sweeping ) = length (algorithm. sweeps)
7878
7979function AI. step! (
80- problem:: AI.AbstractProblem , algorithm:: Sweeping , state:: AI.AbstractState
80+ problem:: AI.Problem , algorithm:: Sweeping , state:: AI.State
8181 )
8282 # Perform the current sweep.
8383 sweep = algorithm. sweeps[state. iteration]
8484 x = state. iterate
85- region_state = AI. State (x, 0 )
85+ region_state = AI. initialize_state (problem, sweep, x )
8686 AI. solve! (problem, sweep, region_state)
8787 state. iterate = region_state. iterate
8888 return state
8989end
9090
9191# TODO : Use a proper stopping criterion.
9292function AI. is_finished (
93- problem:: AI.AbstractProblem , algorithm:: Sweeping , state:: AI.AbstractState
93+ problem:: AI.Problem , algorithm:: Sweeping , state:: AI.State
9494 )
9595 state. iteration == 0 && return false
9696 return state. iteration >= length (algorithm. sweeps)
9797end
9898
9999# Sweeping by region.
100- struct ByRegion{Algorithm <: Sweeping } <: AI.AbstractAlgorithm
100+ struct ByRegion{Algorithm <: Sweeping } <: AI.Algorithm
101101 parent:: Algorithm
102102end
103103function AI. initialize_state (
104- problem:: AI.AbstractProblem , algorithm:: ByRegion , x
104+ problem:: AI.Problem , algorithm:: ByRegion , x
105105 )
106106 return AI. State (x, (; sweep = 1 , region = 0 ))
107107end
108108function AI. is_finished (
109- problem:: AI.AbstractProblem , algorithm:: ByRegion , state:: AI.AbstractState
109+ problem:: AI.Problem , algorithm:: ByRegion , state:: AI.State
110110 )
111111 sweep_iteration = state. iteration. sweep
112112 region_iteration = state. iteration. region
113113 return sweep_iteration ≥ maxiter (algorithm. parent) &&
114114 region_iteration ≥ maxiter (algorithm. parent. sweeps[sweep_iteration])
115115end
116116function AI. increment! (
117- problem:: AI.AbstractProblem , algorithm:: ByRegion , state:: AI.AbstractState
117+ problem:: AI.Problem , algorithm:: ByRegion , state:: AI.State
118118 )
119119 sweep_iteration = state. iteration. sweep
120120 region_iteration = state. iteration. region
@@ -127,7 +127,7 @@ function AI.increment!(
127127 state. iteration = (; sweep = sweep_iteration, region = region_iteration)
128128 return state
129129end
130- function AI. step! (problem:: AI.AbstractProblem , algorithm:: ByRegion , state:: AI.AbstractState )
130+ function AI. step! (problem:: AI.Problem , algorithm:: ByRegion , state:: AI.State )
131131 sweep = algorithm. parent. sweeps[state. iteration. sweep]
132132 sweep_state = AI. State (state. iterate, state. iteration. region)
133133 AI. step! (problem, sweep, sweep_state)
0 commit comments