一連の傾向線に一連の重みを割り当てようとしています。重みは配列にあり、傾向線は配列にあります。私はすべての順列で終わりたいと思っています。つまり、配列内の各トレンドラインにそれぞれの重みが割り当てられます。私のコードでは、現在この出力を取得しています:
output: 1 combination per line:
1.00, 1.00, 1.00, 1.00 
1.50, 1.50, 1.50, 1.50 
2.00, 2.00, 2.00, 2.00, 
しかし、私が取得しようとしているのは、重複を除くすべての順列です。つまり、重み/トレンドラインのさまざまな可能な組み合わせをすべて取得したいのです。
output: 1 combination per line:
1.00, 1.00, 1.00, 1.00
1.50, 1.00, 1.00, 1.00, 
2.50, 1.00, 1.00, 1.00, 
1.00, 1.50, 1.00, 1.00, 
1.50, 1.50, 1.00, 1.00, 
2.50, 1.50, 1.00, 1.00, 
....etc
編集:
私の質問は、次のコードを変更して、トレンドラインと重みのさまざまな組み合わせをすべて生成できるようにする方法です。たとえば、2 つの傾向線と 3 つの重み (1、2、3) がある場合、すべての組み合わせは次のようになります。
1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3
コードは次のとおりです。
#define TRENDLINE_COUNT 4
#define WEIGHT_COUNT 3
void hhour(void)
{   
    int trendLine[TRENDLINE_COUNT];
    double weight[] = { 1, 1.5, 2 };
    FILE *myFile = fopen("s:\\data\\testdump\\ww.txt", WRITE);
    fprintf(myFile, "output: 1 combination per line :\n"    );
    for (int weightIndex = 0; wei`enter code here`ghtIndex < WEIGHT_COUNT; weightIndex++)
    {
        double currentWeight = weight[weightIndex];
        double cumulativeTrendValue = 0;
        for (int trendLineIndex = 0; trendLineIndex < TRENDLINE_COUNT; trendLineIndex++)
        {
            cumulativeTrendValue += trendLine[trendLineIndex] * currentWeight;
            fprintf(myFile, "%.02lf, ", currentWeight);
        }
        fprintf(myFile, "\n");
        // do something with cumulativeTrendValue
    }
    fclose(myFile);
}