1

アプリケーションにロジックを記述する必要があります (少なくとも私にとっては挑戦的です)。次の機能を実行するビジネスロジックを作成する必要があります

Total current consumption = current from A elements + current from B elements.
A and B are different types of devices

ここで、電流(A+B)を供給するのに必要な電池を「X」としましょう。

また、各 X は総消費電流に寄与する可能性があるため、バッテリーの消費電流を含む最初のステップと同じように、総消費電流を再度計算する必要があります。

すなわち

`Total current consumed : A + B + X"`  
where X" is the current consumption of the battery 

もう一度、必要なバッテリーを計算する必要があります。これをYとしましょう

すなわち

A + B + X" を供給するには、Y 個のバッテリーが必要です。

Now check whether X == Y ?
If same, then return Y and exit 
else add more X to the sum (A + B  + X") till X == Y

疑似コードの初期セットを手伝ってくれる人はいますか? どんな種類の提案も大歓迎です

Yes the end result this logic should return is number of batteries required. However it should return this result only after computing the total current consumption recursively till X == Y, where 
A : total current consumption of some active elements in a system.
B : total current consumption of some passive elements in a system

Total current consumption is A + B
to supply current of (A+B) amperes i require 'X' no. of batteries.
However each battery also adds some delta amount of current to the total value i.e 
A + B + X"
if the batteries required to supply this delta is still 'X', then return X as the end result, else add more batteries --> calculate current --> no of batteries required ---> check again and so on ...
4

3 に答える 3

0

私は次の行に沿って何かをします:

double CurrentFromEachBattery=100.0;
double CurrentNeededPerBattery=10.0;

int NumberOfBatteriesRequired(double activeCurrent, double passiveCurrent)
{
    int batteries=0;
    double currCurrent=0.0;
    double neededCurrent=activeCurrent+passiveCurrent;

    while( currCurrent < neededCurrent )
    {
        int newBatt = Math.Ceiling((neededCurrent - currCurrent) / CurrentFromEachBattery);
        neededCurrent += newBatt * CurrentNeededPerBattery;
        currCurrent += newBatt * CurrentFromEachBattery;
        batteries += newBatt;
    }

    return batteries;
}
于 2010-03-04T19:18:59.037 に答える
0

質問はあまり明確ではありません(コメントで他の人が指摘したように)ので、計算のより具体的または具体的な例を書くことができれば便利です。とにかく、フィードバック付きの計算があり、計算が変化しなくなるポイントに到達する必要があるようです。

数学では、これは固定小数点を使用して記述できます。与えられた関数f (あなたの計算) に対して、修正点はx = f(x)のような値です (つまり、値を再計算すると変化しなくなります)。これが実装に役立つかどうかはわかりませんが、問題について考えるときに使用できる便利な概念であることは間違いありません。

特定の関数の固定小数点を計算するメソッドの例を次に示します (C# 3.0Func<T, T>デリゲートを使用)。メソッドは汎用的で、値を比較できる必要があります。

static T FixedPoint<T>(T initial, Func<T, T> calculateNext) 
    where T : IComparable<T> {
  T state = initial;
  T previous = default(T);
  do {
    previous = state;
    state = calculateNext(state);
  } while (previous.CompareTo(state) != 0);
  return state;
}

ウィキペディアには、 cos関数の固定小数点を計算する例があり(右側の 2 番目のグラフを参照)、次のように実装できます。

double val = FixedPoint(-1.0, f => Math.Cos(f));
Console.WriteLine(val);

これは、計算の安定点が見つかるまで実行されるループを説明する非常に一般的な方法です。しかし、あなたの質問はあまり明確ではないので、これはあなたが探しているものではないかもしれません...

于 2010-03-04T19:10:37.843 に答える