알고리즘 최적화. - 페이지 9

 
Andrey Dik :
응, 그랬어
그러나 여러 틱이 밀리초에 올 때 같은 시간에 같은 기호에 틱이 있는 경우가 많습니다.
이것은 내가 논리에 갇힌 곳입니다.

실용적인 목적을 위해 아마도 최악의 선택을 할 필요가 있을 것입니다

 

StartN부터 EndN까지의 숫자가 있습니다.

각각에서 CountN의 조합을 만들어야 합니다.

나는 조합 3의 숫자 수에 대해 다음과 같은 스크립트를 작성했습니다.

 input int       StartN = 0 ;
input int       EndN   = 1 ;
input int       CountN = 5 ;

void OnStart ()
{
   string str = "" ;
  
   //уровень 0
   for ( int i = StartN; i <= EndN; i++)
  {
     //str = StringSubstr (str, 0, 0);
     //str += (string)i;
    str = ( string )i;
    
     //уровень 1
     for ( int k = StartN; k <= EndN; k++)
    {
      str = StringSubstr (str, 0 , 1 );
      str += ( string )k;
      
       //уровень 2
       for ( int l = StartN; l <= EndN; l++)
      {
        str = StringSubstr (str, 0 , 2 );
        str += ( string )l;
        
         Print (str);
      }
    }
  }
}

생성:

2020.07.12 21:48:47.763 sProbCandlComb XAUUSD..,H4: 111

2020.07.12 21:48:47.763 sProbCandlComb XAUUSD..,H4: 110

2020.07.12 21:48:47.763 sProbCandlComb XAUUSD..,H4: 101

2020.07.12 21:48:47.762 sProbCandlComb XAUUSD..,H4: 100

2020.07.12 21:48:47.762 sProbCandlComb XAUUSD..,H4:011

2020.07.12 21:48:47.762 sProbCandlComb XAUUSD..,H4: 010

2020.07.12 21:48:47.762 sProbCandlComb XAUUSD..,H4: 001

2020.07.12 21:48:47.762 sProbCandlComb XAUUSD..,H4: 000

나는 무언가를 무디게 만들었습니다. 주어진 수의 CountN과 함께 작동하도록 하는 방법은 무엇입니까?

 

숫자의 이진 표현...

 
Aliaksandr Hryshyn :

숫자의 이진 표현...

그게 요점이 아니라 0에서 1까지의 매개변수를 사용했습니다.

취하다 [0;2]

그리고 얻다:

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 222

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 221

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 220

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 212

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 211

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 210

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 202

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 201

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 200

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 122

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 121

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 120

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 112

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 111

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 110

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 102

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 101

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 100

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 022

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 021

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 020

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 012

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4:011

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 010

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 002

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 001

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 000

 
Andrey Dik :

StartN부터 EndN까지의 숫자가 있습니다.

각각에서 CountN의 조합을 만들어야 합니다.

나는 무언가를 무디게 만들었습니다. 주어진 수의 CountN과 함께 작동하도록 하는 방법은 무엇입니까?

예전에 해본적 있는거 같은데 여기가 쓰레드임

https://www.mql5.com/ru/forum/335077

 
Andrey Dik :

그게 요점이 아니라 0에서 1까지의 매개변수를 사용했습니다.

취하다 [0;2]

그리고 얻다:

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 222

2020.07.12 22:16:57.703 sProbCandlComb XAUUSD..,H4: 221

...

따라서 작업은 주 주기의 수를 다른 숫자 체계로 변환하고 StartN에 대한 수정을 추가하는 것으로 축소됩니다.

 
Aliaksandr Hryshyn :

따라서 작업은 주 주기의 수를 다른 숫자 체계로 변환하고 StartN에 대한 수정을 추가하는 것으로 축소됩니다.

코드를 가질 수 있습니까?

 
Igor Makanu :

예전에 해본적 있는거 같은데 여기가

https://www.mql5.com/ru/forum/335077

모든 것이 코드로 잘 되는 것은 아니지만 일반적으로 필요한 것은 수정하여 여기에 게시하겠습니다.

이제 코드는 전체 길이에 대한 조합을 생성하지 않습니다.

 
Igor Makanu :

예전에 해본적 있는거 같은데 여기가 쓰레드임

https://www.mql5.com/ru/forum/335077

필요한 것을 달성할 수 없었습니다. 이해할 수 없는 목적을 위해 코드에 너무 많은 루프가 있습니다.

내 솔루션은 다음과 같습니다

 #property script_show_inputs

//--- input parameters
input int       StartN = 0 ;
input int       EndN   = 1 ;
input int       CountN = 3 ;

void OnStart ()
{
   string base [];
  
   //алгоритм сочетаний без повторений
  CombinationGenerator (StartN, EndN, CountN, base);

   //выведем полученные комбинации в принт
   for ( int i = 0 ; i < ArraySize (base); i++) Print (base [i]);
}

string CreateString ( int &base [])
{
   string s = "" ;
   for ( int i = 0 ; i < ArraySize (base); i++) s += ( string )base [i];

   return s;
}

//Алгоритм сочетаний без повторений
void CombinationGenerator ( int startN, int endN, int rowLen, string &base [])
{
   ArrayResize (base, ( int ) pow (EndN - StartN + 1 , CountN));
   int comb [];
   ArrayResize (comb, CountN);
   ArrayInitialize (comb, StartN);
   string str = "" ;
   int pos = 0 ;
  base [pos] = CreateString (comb);

   bool flag = true ;

   while (flag && ! IsStopped ())
  {
     for ( int l = 0 ; l < CountN; l++)
    {
       if (comb [l] + 1 <= EndN)
      {
        comb [l] += 1 ;

        pos++;
        base [pos] = CreateString (comb);
         break ;
      }
       else
      {
         if (l == CountN - 1 ) flag = false ;
        comb [l] = StartN;
      }
    }
  }
}

나는 이 코드가 가능한 가장 적은 수의 반복을 가지고 있다고 생각합니다.

행 3의 숫자가 있는 숫자 [0;1] 값에 대한 결과:

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 111

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 011

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 101

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 001

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 110

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 010

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 100

2020.07.13 01:21:41.037 sProbCandlComb EURUSD..,M5: 000

행 4의 숫자가 있는 숫자 [0;2] 값에 대한 결과:

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2222

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1222

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0222

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2122

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1122

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0122

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2022

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1022

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0022

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2212

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1212

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0212

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2112

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1112

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0112

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2012

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1012

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0012

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2202

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1202

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0202

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2102

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1102

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0102

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2002

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1002

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0002

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2221

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1221

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0221

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2121

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1121

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0121

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2021

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1021

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0021

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2211

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1211

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0211

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2111

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1111

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0111

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2011

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1011

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0011

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2201

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1201

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0201

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2101

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1101

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0101

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2001

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1001

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0001

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2220

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1220

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0220

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2120

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1120

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0120

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2020

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1020

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0020

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2210

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1210

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0210

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2110

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1110

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0110

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2010

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1010

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0010

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2200

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1200

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0200

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2100

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1100

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0100

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 2000

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 1000

2020.07.13 01:22:50.851 sProbCandlComb EURUSD..,M5: 0000

알고리즘의 논리는 간단하고 미적분학의 규칙과 동일합니다. 숫자에 1을 더하고 숫자가 지정된 숫자보다 큰 것으로 판명되면 최소값을 할당하고 다음 숫자인 경우 다음 숫자로 이동합니다. "0"이 아닌 경우 첫 번째 숫자로 돌아갑니다.

사실, 내 방전은 오른쪽에서가 아니라 왼쪽에서 nuipoh입니다.

0000

0001

0010

0011

0100

0101

....

등.


아마도 재귀를 사용하면 더 아름다운 코드를 얻을 수 있지만 더 빠르지는 않을 것입니다.

 
Andrey Dik :

당신은 조합이 아니라 반복이없는 순열을 가지고 있습니다.

그리고 내 예시는 반복 없는 조합