本文整理汇总了C#中Solution.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.Add方法的具体用法?C# Solution.Add怎么用?C# Solution.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solution
的用法示例。
在下文中一共展示了Solution.Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetrieveSolution
/// <summary>
/// metóda pre získanie výsledku zo simplexovej tabuľky
/// </summary>
/// <param name="myVariablesCount">počet premenných</param>
/// <returns>riešenie</returns>
public Solution RetrieveSolution(int myVariablesCount)
{
Solution result = new Solution();
for (int i = 0; i < myVariablesCount; i++)
{
foreach (Equation item in myConditions)
{
if (Math.Abs(item.LeftSide[i] - 1) < 0.000005)
{
result.Add(item.RightSide); //vytiahne tie, pri kt. je hodnota 1 (riešenie)
break;
}
}
}
return result;
}
示例2: generateSolution
//Generate a Solution object from some selected word positions
private static Solution generateSolution(Dictionary<string, int> selectedPositions,
Dictionary<string, List<Tuple<double, WordPosition>>> wordsPositions)
{
//Get the word positions that are selected
Solution solution = new Solution();
foreach (KeyValuePair<string, int> kvp in selectedPositions)
{
string word = kvp.Key;
int positionIdx = kvp.Value;
WordPosition position = wordsPositions[word][positionIdx].Item2;
solution.Add(word, position);
}
return solution;
}
示例3: CountLowerBound
/// <summary>
/// metóda pre výpočet dolnej medze
/// </summary>
/// <param name="function">kriteriálna funkcia</param>
/// <param name="solution">riešenie bez zaokrúhlenia</param>
/// <returns>dolná medza daného uzla</returns>
public double CountLowerBound(Equation function, Solution solution)
{
double lowerBoundFromRounding = 0;
Solution roundedSolution = new Solution();
foreach (double i in solution)
{
roundedSolution.Add(Math.Round(i));
}
foreach (double i in solution)
{
foreach (double j in function.LeftSide)
{
if (solution.IndexOf(i)==function.LeftSide.IndexOf(j))
{
lowerBoundFromRounding += j * i;
}
}
}
return lowerBoundFromRounding;
}
示例4: solve
private Solution solve(char[,] chars, string[] words)
{
Solution solution = new Solution();
//Find the first solution for each word
foreach(string word in words)
{
bool foundWord = false;
//Loop through each character in the wordsearch, looking for this word
for (int i = 0; i < chars.GetLength(0); i++) //Col
{
for(int j = 0; j < chars.GetLength(1); j++) //Row
{
//If this character is the same as the starting character of the word then the word could start here
if (word[0] == chars[i, j])
{
//Calculate the indices it would finish at in each direction
int finishUp = j - word.Length + 1;
int finishDown = j + word.Length - 1;
int finishLeft = i - word.Length + 1;
int finishRight = i + word.Length - 1;
//Calculate whether the word could fit in each direction
bool canGoUp = finishUp >= 0;
bool canGoDown = finishDown < chars.GetLength(1);
bool canGoLeft = finishLeft >= 0;
bool canGoRight = finishRight < chars.GetLength(0);
//Check if there is a potential solution here in each direction
//Up
if (canGoUp)
{
bool found = true;
for (int k = 1; k < word.Length; k++)
{
if (word[k] != chars[i, j - k])
{
found = false;
break;
}
}
if (found)
{
foundWord = true;
solution.Add(word, i, j, i, finishUp);
break;
}
}
//Down
if (canGoDown)
{
bool found = true;
for (int k = 1; k < word.Length; k++)
{
if (word[k] != chars[i, j + k])
{
found = false;
break;
}
}
if (found)
{
foundWord = true;
solution.Add(word, i, j, i, finishDown);
break;
}
}
//Left
if (canGoLeft)
{
bool found = true;
for (int k = 1; k < word.Length; k++)
{
if (word[k] != chars[i - k, j])
{
found = false;
break;
}
}
if (found)
{
foundWord = true;
solution.Add(word, i, j, finishLeft, j);
break;
}
}
//Right
if (canGoRight)
{
bool found = true;
for (int k = 1; k < word.Length; k++)
{
if (word[k] != chars[i + k, j])
{
found = false;
break;
//.........这里部分代码省略.........
示例5: doSolve
//.........这里部分代码省略.........
bestPositions[k] = Tuple.Create(score, new WordPosition(i, j, finishLeft, j));
}
}
//Right
if(canGoRight)
{
double score = 0;
for (int l = 0; l < word.Length; l++)
{
int thisCharIdx = word[l] - 'A';
score += wordsearch[i + l][j][thisCharIdx];
}
//If this score is better than the current best then this becomes the new best (or if there isn't currently a best)
if (bestPositions[k] == null || bestPositions[k].Item1 < score)
{
bestPositions[k] = Tuple.Create(score, new WordPosition(i, j, finishRight, j));
}
}
//Up & Left
if(canGoUp && canGoLeft)
{
double score = 0;
for (int l = 0; l < word.Length; l++)
{
int thisCharIdx = word[l] - 'A';
score += wordsearch[i - l][j - l][thisCharIdx];
}
//If this score is better than the current best then this becomes the new best (or if there isn't currently a best)
if (bestPositions[k] == null || bestPositions[k].Item1 < score)
{
bestPositions[k] = Tuple.Create(score, new WordPosition(i, j, finishLeft, finishUp));
}
}
//Up & Right
if(canGoUp && canGoRight)
{
double score = 0;
for (int l = 0; l < word.Length; l++)
{
int thisCharIdx = word[l] - 'A';
score += wordsearch[i + l][j - l][thisCharIdx];
}
//If this score is better than the current best then this becomes the new best (or if there isn't currently a best)
if (bestPositions[k] == null || bestPositions[k].Item1 < score)
{
bestPositions[k] = Tuple.Create(score, new WordPosition(i, j, finishRight, finishUp));
}
}
//Down & Right
if(canGoDown && canGoRight)
{
double score = 0;
for (int l = 0; l < word.Length; l++)
{
int thisCharIdx = word[l] - 'A';
score += wordsearch[i + l][j + l][thisCharIdx];
}
//If this score is better than the current best then this becomes the new best (or if there isn't currently a best)
if (bestPositions[k] == null || bestPositions[k].Item1 < score)
{
bestPositions[k] = Tuple.Create(score, new WordPosition(i, j, finishRight, finishDown));
}
}
//Down & Left
if(canGoDown && canGoLeft)
{
double score = 0;
for (int l = 0; l < word.Length; l++)
{
int thisCharIdx = word[l] - 'A';
score += wordsearch[i - l][j + l][thisCharIdx];
}
//If this score is better than the current best then this becomes the new best (or if there isn't currently a best)
if (bestPositions[k] == null || bestPositions[k].Item1 < score)
{
bestPositions[k] = Tuple.Create(score, new WordPosition(i, j, finishLeft, finishDown));
}
}
}
}
}
//Combine all of the best word positions into a solution
Solution solution = new Solution();
for(int i = 0; i < bestPositions.Length; i++)
{
solution.Add(words[i], bestPositions[i].Item2);
}
return solution;
}