本文整理汇总了C#中Decision类的典型用法代码示例。如果您正苦于以下问题:C# Decision类的具体用法?C# Decision怎么用?C# Decision使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Decision类属于命名空间,在下文中一共展示了Decision类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
SolverContext context = SolverContext.GetContext();
Model model = context.CreateModel();
// ------------
// Parameters
Set city = new Set(Domain.IntegerNonnegative, "city");
Parameter dist = new Parameter(Domain.Real, "dist", city, city);
var arcs = from p1 in data
from p2 in data
select new Arc { City1 = p1.Name, City2 = p2.Name, Distance = p1.Distance(p2) };
dist.SetBinding(arcs, "Distance", "City1", "City2");
model.AddParameters(dist);
// ------------
// Decisions
Decision assign = new Decision(Domain.IntegerRange(0, 1), "assign", city, city);
Decision rank = new Decision(Domain.RealNonnegative, "rank", city);
model.AddDecisions(assign, rank);
// ------------
// Goal: minimize the length of the tour.
Goal goal = model.AddGoal("TourLength", GoalKind.Minimize,
Model.Sum(Model.ForEach(city, i => Model.ForEachWhere(city, j => dist[i, j] * assign[i, j], j => i != j))));
// ------------
// Enter and leave each city only once.
int N = data.Length;
model.AddConstraint("assign1",
Model.ForEach(city, i => Model.Sum(Model.ForEachWhere(city, j => assign[i, j],
j => i != j)) == 1));
model.AddConstraint("assign2",
Model.ForEach(city, j => Model.Sum(Model.ForEachWhere(city, i => assign[i, j], i => i != j)) == 1));
// Forbid subtours (Miller, Tucker, Zemlin - 1960...)
model.AddConstraint("no_subtours",
Model.ForEach(city,
i => Model.ForEachWhere(city,
j => rank[i] + 1 <= rank[j] + N * (1 - assign[i, j]),
j => Model.And(i != j, i >= 1, j >= 1)
)
)
);
Solution solution = context.Solve();
// Retrieve solution information.
Console.WriteLine("Cost = {0}", goal.ToDouble());
Console.WriteLine("Tour:");
var tour = from p in assign.GetValues() where (double)p[0] > 0.9 select p[2];
foreach (var i in tour.ToArray())
{
Console.Write(i + " -> ");
}
Console.WriteLine();
Console.WriteLine("Press enter to continue...");
Console.ReadLine();
}
示例2: Decide
public override Decision Decide(IEntityRecord opponent)
{
Decision trick = Decision.Undecided;
Outcome outcome = Outcome.Unknown;
int retries = 0;
int maxRetries = 5;
while (outcome == Outcome.Unknown || outcome == Outcome.Loss) {
// pick any hand and use it to see how opponent would react
// > note that it must have some amount of influence to be considered a real decision
trick = Decision.Next(1);
Decision reaction = new Decision();
foreach (Behavior behavior in opponent.GetComponents().OfType<Behavior>()) {
reaction += behavior.React(Record, trick);
}
outcome = trick.DetermineOutcome(reaction);
if (retries++ > maxRetries) {
break;
}
}
// > note that we do not use Decision.Counter on the reaction that resulted in a win, because
// it was actually the trick hand that caused the win
return Decision.Distribute(
trick.MostInfluencedHand, Influence);
}
示例3: Score
/// <summary>
/// Sprawdza, czy decyzja jest zwycieska
/// </summary>
/// <param name="mine"></param>
/// <param name="opponet"></param>
/// <returns></returns>
public static int Score(this Decision mine, Decision opponet)
{
if (mine == opponet)
return 0;
switch (mine)
{
case Decision.Rock:
if (opponet == Decision.Paper)
return -1;
else return 1;
case Decision.Paper:
if (opponet == Decision.Scissor)
return -1;
else
return 1;
case Decision.Scissor:
if (opponet == Decision.Rock)
return -1;
else
return 1;
default:
return 0;
}
}
示例4: d2d
public static double[] d2d(Decision[] d)
{
var result = new double[d.Length];
for (int i = 0; i < d.Length; i++)
result[i] = d[i].ToDouble();
return result;
}
示例5: Main
static void Main(string[] args)
{
//4.1)
SimpleActivity greaterThan100Activity = new SimpleActivity(()=>Console.WriteLine("Value is greater than 100."));
//4.2)
SimpleActivity lessThan100Activity = new SimpleActivity(()=>Console.WriteLine("Value is less than 100."));
//3.)
Decision<int> greaterOrLess100Decision = new Decision<int>(multipliedValue => multipliedValue > 100, greaterThan100Activity, lessThan100Activity);
//2.)
InputOutputActivity<int,int> mutiplyBy10Activity = new InputOutputActivity<int, int>(inputValue => inputValue * 10, greaterOrLess100Decision);
//1.)
OutputActivity<int> getInputValueActivity = new OutputActivity<int>(()=>
{
Console.Write("Please type in value:");
var input = Console.ReadLine();
return Convert.ToInt32(input);
}, mutiplyBy10Activity);
WorkflowEngine engine = new WorkflowEngine();
engine.WorkflowProgressChanged += (arg1, arg2, arg3, arg4) => Console.WriteLine("Step:{0}\r\nContext:{1}\r\nSuccess:{2}\r\nException message:{3}", arg1, arg2, arg3, arg4 != null ? arg4.Message : string.Empty);
engine.WorkflowCompleted += (arg1, arg2) => Console.WriteLine("Completed:\r\nSucceeded:{0}\r\nException message:{1}", arg1, arg2 != null ? arg2.Message : string.Empty);
engine.Run(getInputValueActivity);
Console.ReadLine();
engine.Dispose();
}
示例6: WinByPointsPrediction
public WinByPointsPrediction(Decision by, Boxer winner, PlayerPrediction playerPrediction)
{
By = by;
Winner = winner;
Type = "WinByPointsPrediction";
PlayerPrediction = playerPrediction;
}
示例7: DecisionTree
/// <summary>
/// Initializes a new instance of the <see cref="DecisionTree"/> class.
/// </summary>
/// <param name="_decisions">_decisions.</param>
/// <param name="_actions">_actions.</param>
/// <param name="_callback">_callback.</param>
public DecisionTree(Decision[] _decisions, TreeAction[] _actions, Action<TreeAction> _callback)
{
decisions = _decisions;
actions = _actions;
callback = _callback;
doneEvent = new ManualResetEvent(true);
}
示例8: Transfer
public bool Transfer(Guid competitionId, Decision decision)
{
var competition = this.repository.Get(competitionId);
if (competition == null) return false;
if (!this.stateService.CanUpdateResult(competition)) return false;
competition.RegisterWin(decision.Winner);
competition.RegisterLoss(decision.Looser);
return this.repository.Update(competition);
}
示例9: GetNewer
/// <summary>
/// Gets the decision that has occured later in time.
/// </summary>
public static Decision GetNewer(Decision a, Decision b)
{
if (a == null)
return b;
if (b == null)
return a;
return a.time > b.time ? a : b;
}
示例10: Start
//public GameObject gameLogic;
// Use this for initialization
void Start () {
gameState = FindObjectOfType<PersistantState>();
currentDecision = gameState.Decisions[gameState.Stage];
textDay.text = string.Format("Day {0}", gameState.Stage + 1);
textQuery.text = currentDecision.query;
buttonAlternative1.GetComponentInChildren<Text>().text = currentDecision.alternatives[0];
buttonAlternative1.onClick.AddListener(delegate { onClick(0); });
buttonAlternative2.GetComponentInChildren<Text>().text = currentDecision.alternatives[1];
buttonAlternative2.onClick.AddListener(delegate { onClick(1); });
}
示例11: React
public override Decision React(IEntityRecord opponent, Decision decision)
{
Decision counter = Decision.Win(decision, Influence);
Hand choices =
counter.MostInfluencedHand |
decision.MostInfluencedHand;
return Decision.Next(
choices, Influence * 2);
}
示例12: BuildDecisions
public Decision[,] BuildDecisions()
{
for (int i = 0; i < Decisions.GetLength(0); i++)
{
for (int j = 0; j < Decisions.GetLength(1); j++)
{
Decisions[i, j] = new Decision(domain, "_" + i + "Decision" + j);
}
}
return Decisions;
}
示例13: React
public override Decision React(IEntityRecord opponent, Decision decision)
{
Decision reaction = Decision.Undecided;
History opponentHistory = opponent.GetComponent<History>();
if (opponentHistory != null) {
reaction = opponentHistory.PreviousDecision;
}
return Decision.Distribute(
reaction.MostInfluencedHand, Influence);
}
示例14: MakeDecision
public bool MakeDecision(Guid sessionId, Decision decision)
{
var session = Get(sessionId);
if (session == null) return false;
if (session.IsClosed) return false;
var operationChecker = new OperationChecker(this.competitionRepository);
var gateway = new DecisionGateway(this.competitionRepository, operationChecker);
session.RegisterDecision(decision, gateway);
this.unitOfWork.Commit();
return true;
}
示例15: RegisterDecision
public void RegisterDecision(Decision decision, IDecisionGateway gateway)
{
if (this.IsClosed) return;
var duel = decision.Duel;
AssertScheduleContainsDuel(duel);
AssertDecisionIsNotRegisteredYet(duel);
this.Outcomes.Add(new Outcome(decision));
this.Schedule.Remove(duel);
gateway.Transfer(this.CompetitionId, decision);
}