本文整理汇总了C#中System.Collections.Set.Choose方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Choose方法的具体用法?C# Set.Choose怎么用?C# Set.Choose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Set
的用法示例。
在下文中一共展示了Set.Choose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChooseAction
private CompoundTerm ChooseAction(Sequence<Action> actions, IState iState)
{
TransitionProperties tp;
int targetId = -1;
List<double> MaxV = bdt.ReturnValue(true);
List<double> MinV = bdt.ReturnValue(false);
List<Set<int>> abstractMap = bdt.ReturnLeaves();
Sequence<Pair<int, Action>> cumulActSum = Sequence<Pair<int, Action>>.EmptySequence;
double epsilon = 0.1;
Dictionary<int, int> sumTarget = new Dictionary<int, int>();
Action maxAct = null;
int targetAbsId = -1;
int sum = 0;
UpdateRequirementMaps(actions, iState);
Set<Action> newStateActs = new Set<Action>();
Set<Action> oldActs = new Set<Action>(actions.Head);
foreach (Action a in actions)
{
int tState = this.modelProgram.GetTargetState(iState, a, null, out tp).GetHashCode();
targetAbsId = findAbstractId(tState, abstractMap);
if (targetAbsId == -1)
{
newStateActs = newStateActs.Add(a);
}
else
{
sum = sum + (int)(MaxV[targetAbsId] * Math.Pow(10.0, 9.0));
Pair<int, Action> np = new Pair<int, Action>(sum, a);
sumTarget.Add(sum, targetAbsId);
cumulActSum = cumulActSum.AddLast(np);
}
}
if (!newStateActs.IsEmpty)
{
maxAct = newStateActs.Choose();
System.Console.WriteLine("new action in new state " + maxAct.ToString());
return maxAct;
}
else
{
Random rndNumbers = new Random();
int rndNumber = rndNumbers.Next(sum);
System.Console.WriteLine(sum + " " + rndNumber);
foreach (Pair<int, Action> np in cumulActSum)
{
System.Console.WriteLine(np.First + " " + np.Second.ToString());
if (rndNumber <= np.First)
{
maxAct = np.Second;
targetId = sumTarget[np.First];
break;
}
targetId = sumTarget[np.First];
maxAct = np.Second;
}
System.Console.WriteLine("old action in old state " + maxAct.ToString());
}
// Adaptive Refinement
if (MaxV[targetId] - MinV[targetId] > epsilon)
{
if (i < requirementProperties.Count)
{
string s1 = requirementProperties[i++];
bdt = bdt.Refine(s1, requireEnabledStateMap[s1]);
bdt.PrintTree(0);
}
}
return maxAct;
}
示例2: LibraryModelProgram
//.........这里部分代码省略.........
finishActionMethod = InsertActionMethodFinish(method, finishActionLabel, aInfoMap);
}
if (startActionLabel != null)
{
InsertActionMethodStart(method, startActionLabel, finishActionMethod, aInfoMap);
}
}
}
catch (ModelProgramUserException e)
{
string msg = "method " + methodInfo.Name + ", " + e.Message;
throw new ModelProgramUserException(msg);
}
}
// to do: collect transition properties
// Collect state invariants
//StatePredicate sp1 = StatePredicate.GetPredicates(t, GetStateInvariantMethodNames(t));
//if (null != sp1)
// stateInvariants.Add(t, sp1);
// Collect accepting state conditions
StatePredicate sp2 = StatePredicate.GetAcceptingStateCondition(t);
if (null != sp2)
acceptingStateConditions.Add(t, sp2);
// Collect state invariants
StatePredicate sp3 = StatePredicate.GetStateInvariant(t);
if (null != sp3)
stateInvariants.Add(t, sp3);
//collect state filters
StatePredicate sp4 = StatePredicate.GetStateFilter(t);
if (null != sp4)
stateFilters.Add(t, sp4);
}
}
catch (ModelProgramUserException e)
{
string msg = "In class " + t.Name + ", " + e.Message;
throw new ModelProgramUserException(msg);
}
}
if (modelIsEmpty)
throw new ModelProgramUserException("No classes found in model namespace " + modelName + ". Did you misspell?");
#endregion
// todo: Collect "sorts" for each type. Walk type tree of state variables and
// action arguments to do this.
Symbol[] aSymbols = new Symbol[aInfoMap.Keys.Count];
int j = 0;
foreach (Symbol a in aInfoMap.Keys)
aSymbols[j++] = a;
Field[] sFields = stateVars.ToArray();
StateVariable[] sVars = new StateVariable[sFields.Length];
string[] lNames = new string[sVars.Length];
ValueArray<string> locNames;
for (int i = 0; i < sVars.Length; i++)
{
sVars[i] = sFields[i].stateVariable;
lNames[i] = sFields[i].stateVariable.Name;
}
locNames = new ValueArray<string>(lNames);
string nameExt = "";
if (featureNames != null && featureNames.Count > 0)
{
nameExt += "[";
for (int i = 0; i < featureNames.Count; i++)
{
nameExt += featureNames.Choose(i);
if (i < featureNames.Count - 1)
nameExt += ",";
}
nameExt += "]";
}
this.name = modelName + nameExt;
// this.generator = generator;
this.stateFields = sFields;
this.locationNames = locNames;
this.stateVariables = sVars;
this.actionSymbols = new Set<Symbol>(aSymbols);
this.actionInfoMap = aInfoMap;
this.finishActionSymbols = LibraryModelProgram.CreateStartFinishMap(aInfoMap);
this.modelAssembly = modAssembly;
this.context = context;
this.currentState = GetInitialState();
this.stateChangedPredicate = false;
this.acceptingStateConditions = acceptingStateConditions;
this.stateInvariants = stateInvariants;
this.stateFilters = stateFilters;
}
示例3: ChooseAction
private CompoundTerm ChooseAction(Sequence<Action> actions, IState iState)
{
Action maxAct = actions.Head;
int sState = iState.GetHashCode();
int tState;
IExtendedState iestate = (IExtendedState)iState;
int c = iestate.LocationValuesCount;
foreach (Action a in actions)
foreach (string s in this.modelProgram.GetEnablingConditionDescriptions(iState, a, false))
{
Term t = Term.Parse(s);
Sequence<Term> vars = (t.Arguments[0].Arguments);
Map<Variable, Term> subst = ConstructSubst(a,vars);
System.Console.WriteLine(a.ToString() + sState + " enabled string " + t.Arguments[1].Substitute(subst));
}
/*
for (int i = 0; i < c; i++)
{
System.Console.WriteLine("name: "+iestate.GetLocationName(i) + " value : "+
iestate.GetLocationValue(i) + " hash" +
iestate.GetLocationValue(i).GetHashCode());
CompoundValue t = (CompoundValue)iestate.GetLocationValue(i);
foreach (CompoundValue t1 in t.FieldValues())
{
System.Console.WriteLine(" field " + t1.ToString());
}
}
*/
TransitionProperties tp;
int sum = 0;
Sequence<Pair<int, Action>> cumulActSum = Sequence<Pair<int,Action>>.EmptySequence;
Set<int> coveredActs = findCoveredActs(sState,actions);
if(!cov.ContainsKey(sState))
cov[sState] = 0.0;
Set<Action> newStateActs = new Set<Action>();
Set<Action> newActs = new Set<Action>();
Set<Action> oldActs = new Set<Action>(actions.Head);
foreach (Action a in actions)
{
tState = this.modelProgram.GetTargetState(iState, a, null, out tp).GetHashCode();
if (!v.ContainsKey(tState))
{
newStateActs = newStateActs.Add(a);
}
else if (!coveredActs.Contains(a.GetHashCode()))
{
newActs = newActs.Add(a);
}
else
{
// one greedy approach
/*
if (v.ContainsKey(tState) && v[tState] > maxv)
{
maxv = v[tState];
oldActs = new Set<Action>(a);
}
else if (v.ContainsKey(tState) && v[tState] == maxv)
{
oldActs = oldActs.Add(a);
}*/
// probabilistic greedy approach
if (v.ContainsKey(tState))
{
sum = sum + (int)(v[tState]* Math.Pow(10.0,9.0));
Pair<int, Action> np = new Pair<int, Action>(sum, a);
cumulActSum = cumulActSum.AddLast(np);
}
}
}
if (!newStateActs.IsEmpty)
{
maxAct = newStateActs.Choose();
System.Console.WriteLine("new action in new state " + maxAct.ToString());
}
else if (!newActs.IsEmpty)
{
maxAct = newActs.Choose();
System.Console.WriteLine("new action in old state " + maxAct.ToString());
}
else
{
//maxAct = oldActs.Choose();
Random rndNumbers = new Random();
int rndNumber = rndNumbers.Next(sum);
System.Console.WriteLine(sum + " " + rndNumber);
foreach (Pair<int, Action> np in cumulActSum)
{
System.Console.WriteLine(np.First + " " + np.Second.ToString());
if (rndNumber <= np.First)
{
maxAct = np.Second;
break;
}
maxAct = np.Second;
}
//.........这里部分代码省略.........