MQL5におけるOOPに関する質問 - ページ 95

 
Maxim Kuznetsov:

GAというのは、どちらかというと「流行語大賞」のようなものです。グレイズコードはどうして収束に役立つのですか? あくまで理論的に...です。

シャッフル

私は何も言いませんが、長い間、インターネットに書かれていることをすべて信じていたわけではありません。

Grayのコードに変換するコードはこちらです。

//+------------------------------------------------------------------+
uint IntToGrey(const uint value) // https://e-maxx.ru/algo/gray_code
  {  return(value ^ (value >> 1)); }
//+------------------------------------------------------------------+
uint GreyToInt(const uint value) // https://e-maxx.ru/algo/gray_code
  {
   uint n = 0;
   for(uint g = value; g != 0; g >>= 1)
     {
      n ^= g;
     }
   return(n);
  }
//+------------------------------------------------------------------+
 
また、このことが遺伝的アルゴリズムに どのような影響を与えるのでしょうか?遺伝的アルゴリズムは、純粋に遺伝的なものであれば、値には反応しないはずです。何らかの追加的な平均化や勾配降下が行われた場合、影響を受ける可能性があります。しかし、この場合は、直接的に問題を解決した方がよいのです。つまり、配列を通してパラメータをフィルタリングし、配列をシャッフルするのです。プロパティウィンドウから最適化されたパラメータの値は、配列要素のインデックスであり、配列からの値がExpert Advisor自体で使用されます。そうすれば、オプティマイザーを騙すことができる。ただし、平均化または勾配降下により収束した場合のみ。でも、純粋な遺伝的アルゴリズムだとしたら、どんないいことがあるのか想像がつきません。何が言いたいの?脚はどこから生えているのか?
 

このコードがあります。

class A
{
private:
   const int _a;
public:
   A(const int a): _a(a) { Print(_a); }
};
//+------------------------------------------------------------------+
class B
{
private:
   const A a;
public:
   B(const int b): a(b) {}
};
//+------------------------------------------------------------------+
void OnStart()
{
   B b(3);// 3
}
//+------------------------------------------------------------------+

はすべてOKですが、Aオブジェクトの配列が必要です。つまり、次のようなものが必要です。

class B
{
private:
   const A a[2];
public:
   B(const int b): a[0](b),a[1](b) {}  //'[' - member(s) initialization expected
                                       // 'a' - explicit initializer for arrays not allowed
};

ポインタを使用せずにオブジェクトの配列のコンストラクタを呼び出す方法はありますか?

 
Igor Makanu:

このコードがあります。

はすべてOKですが、Aオブジェクトの配列が必要です。つまり、次のようなものが必要です。

ポインタを使用せずにオブジェクトの配列のコンストラクタを呼び出す方法はありますか?

いいえ、松葉杖を通してだけです。
 

このコードで可能でしょうか。

//+------------------------------------------------------------------+
struct LIST;
struct MyStruct
{
   double            d_data;
   int               i_data;
   MyStruct() {}
   MyStruct(const int i_v, const double d_v): d_data(d_v), i_data(i_v) {}
   LIST              operator+(MyStruct &value)
   {
      LIST result;
      ArrayResize(result.arr, 2, 10);
      result.arr[0] = this;
      result.arr[1] = value;
      return(result);
   }
   MyStruct          operator*(const double mult)
   {
      MyStruct result = this;
      result.d_data *= mult;
      return(result);
   }
};
//+------------------------------------------------------------------+
struct LIST
{
   MyStruct          arr[];
   LIST              operator+(MyStruct &value)
   {
      int last = ArraySize(this.arr);
      ArrayResize(this.arr, last + 1, 10);
      this.arr[last] = value;
      return(this);
   }
};
//+------------------------------------------------------------------+
void OnStart()
{
   MyStruct a(1, 1.11), b(2, 2.22), c(3, 3.33);
   LIST x = a + b + c * 2;
   ArrayPrint(x.arr);
//    [d_data] [i_data]
//[0]  1.11000        1
//[1]  2.22000        2
//[2]  6.66000        3
}
//+------------------------------------------------------------------+

for LIST to make template / template ?

一回目はダメでしたね((

 
Igor Makanu:

このコードで可能でしょうか。

for LIST to make template / template ?

一回目はうまくいかなかった((.

これを削除します。

UPD:うーん...。よくぞ言ってくれた))))

UPD: ヤムを手に入れる)))

//+------------------------------------------------------------------+
template<typename T>
struct LIST
{
   T          arr[];
   LIST<T>              operator+(T &value)
   {
      int last = ArraySize(arr);
      ArrayResize(arr, last + 1, 10);
      arr[last] = value;
      return(this);
   }
};
//+------------------------------------------------------------------+
struct MyStruct
{
   double            d_data;
   int               i_data;
   MyStruct() {}
   MyStruct(const int i_v, const double d_v): d_data(d_v), i_data(i_v) {}
   LIST<MyStruct>              operator+(MyStruct &value)
   {
      LIST<MyStruct> result;
      ArrayResize(result.arr, 2, 10);
      result.arr[0] = this;
      result.arr[1] = value;
      return(result);
   }
   MyStruct          operator*(const double mult)
   {
      MyStruct result = this;
      result.d_data *= mult;
      return(result);
   }
};
//+------------------------------------------------------------------+
void OnStart()
{
   MyStruct a(1, 1.11), b(2, 2.22), c(3, 3.33);
   LIST<MyStruct> x = a + b + c * 2;
   ArrayPrint(x.arr);
//    [d_data] [i_data]
//[0]  1.11000        1
//[1]  2.22000        2
//[2]  6.66000        3
}
 
Vladimir Simakov:

これを削除します。

UPD:うーん...。よくぞ言ってくれた))))

UPD: ヤムヤムキャッチ)))

ありがとうございます。- 効いてる効いてる

コードは最小限の、それは動作します - 私は構造体の配列をしたい、リストは常に便利ではありませんが、すべてが動作し、それはこのコードを使用して非標準の状況をシミュレートすることができることは明らかであるが、コード十数行

 

このコードが他人のプライベートフィールドにアクセス してもコンパイラーエラーにならない理由。

class A
{
private:
   int _value;
public:
  void set(const int value)      { _value = value;    }
  int  get()                     { return(_value);    }
  void set(A &a, const int value){ a._value = value;  }
};

void OnStart()
{
  A x,y;
  x.set(10);
  y.set(20);
  Print("x = ",x.get());   // 10
  Print("y = ",y.get());   // 20
  y.set(x,777);
  Print("x = ",x.get());   // 777
  Print("y = ",y.get());   // 20
}
//+------------------------------------------------------------------+
 
は、それ自身のプライベートフィールド
 
Andrei Trukhanovich:
これは、それ自身のプライベートフィールドです。

OK、ありがとうございます

しかし、親クラスの中の派生クラスが 同じようにプライベートフィールドを変更した場合、それは「合法」なのでしょうか?

i.e. 同様の方法で

class B: private A
{
        A a;
        void setA(A &obj, const int value) { a.set(obj,value); }
}
....
A x;
B y;
y.(x.55)
理由: