-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimization_Algorithm_Factory.h
More file actions
79 lines (63 loc) · 3.19 KB
/
Optimization_Algorithm_Factory.h
File metadata and controls
79 lines (63 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by simonepanzeri on 02/12/2021.
//
#ifndef DEV_FDAPDE_OPTIMIZATION_ALGORITHM_FACTORY_H
#define DEV_FDAPDE_OPTIMIZATION_ALGORITHM_FACTORY_H
#include "FdaPDE.h"
//template<typename T, typename... Args>
//std::shared_ptr<T> make_shared(Args&&... args)
//{
// return std::make_shared<T>(new T(std::forward<Args>(args)...));
//}
//! @brief A Factory class: a class for the choice of the step mehod for the optimization algorithm.
template<UInt ORDER, UInt mydim, UInt ndim>
class MinimizationAlgorithm_factory
{
public:
//! A method that builds a pointer to the right object for the step choice, taking as parameters a string and others objects needed for constructor.
static std::shared_ptr<MinimizationAlgorithm<ORDER, mydim, ndim>>
createStepSolver(const DataProblem<ORDER, mydim, ndim>& dp,
const FunctionalProblem<ORDER, mydim, ndim>& fp,
const std::string& d, const std::string& s)
{
if(s == "Fixed_Step") return std::make_shared<FixedStep<ORDER, mydim, ndim>>(dp, fp, d);
else if(s == "Backtracking_Method") return std::make_shared<BacktrackingMethod<ORDER, mydim, ndim>>(dp, fp, d);
else if(s == "Wolfe_Method") return std::make_shared<WolfeMethod<ORDER, mydim, ndim>>(dp, fp, d);
else{
//Rprintf("Unknown step option - using fixed step\n");
return std::make_shared<FixedStep<ORDER, mydim, ndim>>(dp, fp, std::move(d));
}
}
};
//! ####################################################################################################################
//! ######################################## SPACE-TIME PROBLEM ########################################################
//! ####################################################################################################################
template<UInt ORDER, UInt mydim, UInt ndim>
class MinimizationAlgorithm_factory_time{
public:
//! A method that builds a pointer to the right object for the step choice, taking as parameters a string and others objects needed for constructor.
static std::shared_ptr<MinimizationAlgorithm_time<ORDER, mydim, ndim>>
createStepSolver(const DataProblem_time<ORDER, mydim, ndim>& dp,
const FunctionalProblem_time<ORDER, mydim, ndim>& fp,
const std::string& d, const std::string& s)
{
if(s == "Fixed_Step") {
std::cout << "Fixed_Step" << std::endl;
return std::make_shared<FixedStep_time<ORDER, mydim, ndim>>(dp, fp, d);
}
else if(s == "Backtracking_Method") {
std::cout << "Backtracking_Method" << std::endl;
return std::make_shared<BacktrackingMethod_time<ORDER, mydim, ndim>>(dp, fp, d);
}
else if(s == "Wolfe_Method") {
std::cout << "Wolfe_Method" << std::endl;
return std::make_shared<WolfeMethod_time<ORDER, mydim, ndim>>(dp, fp, d);
}
else{
std::cout << "Unknown step option - using fixed step" << std::endl;
//Rprintf("Unknown step option - using fixed step\n");
return std::make_shared<FixedStep_time<ORDER, mydim, ndim>>(dp, fp, std::move(d));
}
}
};
#endif //DEV_FDAPDE_OPTIMIZATION_ALGORITHM_FACTORY_H