9 #include "../resource.h" 14 TclObject*
create(
int argc,
const char*
const*argv) {
35 delete[] coefficients;
43 if(coefficients != NULL){
44 delete[] coefficients;
47 coefficients =
new double[coef_number];
48 initialized =
new bool[coef_number];
59 if(size!= coef_number - 1){
60 std::cerr <<
"Incorrect size of predictors array!\n";
62 double result = coefficients[size];
63 for(
int i = 0; i < size; i++){
64 result += predictors[i] * coefficients[i];
68 std::cerr <<
"The model is not correctly initalized.\n" ;
70 std::cerr <<
"Aborting simulation";
76 double * load =
new double[coef_number];
77 for(
int i = 0; i < coef_number; i++){
80 return estimate(coef_number,load);
86 std::cout <<
"Linear model: "<< name_ <<
"\n";
88 std::cout <<
"Coefficients:\n";
89 for(
int i = 0; i < coef_number ; i++){
90 std::cout << i <<
": " << coefficients[i] <<
"\n";
93 std::cout <<
"Model not initalized properly\n";
98 if(strcmp(coef,
"Intercept") != 0){
100 coefficients[type]=value;
101 initialized[type]=
true;
103 coefficients[coef_number-1]= value;
104 initialized[coef_number-1]=
true;
110 if(strcmp(coef,
"Intercept") != 0){
112 coefficients[i]=value;
115 coefficients[coef_number-1]= value;
116 initialized[coef_number-1]=
true;
122 for(
int i = 0; i < coef_number-1; i++){
123 result = result && initialized[i];
132 if (strcmp(argv[1],
"print") == 0) {
138 if (strcmp(argv[1],
"set-name") == 0) {
141 }
else if (strcmp(argv[1],
"set-coef-number") == 0) {
142 setCoefNumber(atoi(argv[2]));
148 else if (argc == 4) {
149 if (strcmp(argv[1],
"set-coefficient") == 0) {
150 setCoefficient(argv[2],atof(argv[3]));
152 }
else if (strcmp(argv[1],
"set-coefficient-numeric") == 0) {
153 setCoefficientNumeric(argv[2],atof(argv[3]));
TclObject * create(int argc, const char *const *argv)
virtual int command(int argc, const char *const *argv)
virtual void addComponent(DcResource *component)
static res_type translateType(const char *t)
void setCoefficientNumeric(const char *coef, double value)
void setCoefficient(const char *coef, double value)
LinearPModelClass class_powermodel
void setCoefNumber(int number)
virtual double getMaxPower()
virtual double estimate(int size, double *predictors)