本文整理汇总了C#中Stack.CartesianProduct方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.CartesianProduct方法的具体用法?C# Stack.CartesianProduct怎么用?C# Stack.CartesianProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.CartesianProduct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSchedules
/// <summary>
/// Generate schedules by adding a new event to the end of existing ones
/// Create a new system schedule list by adding each of the new Task commands for the Assets onto each of the old schedules
/// </summary>
/// <param name="system"></param>
/// <param name="tasks"></param>
/// <param name="initialStateList"></param>
/// <returns></returns>
public virtual List<SystemSchedule> GenerateSchedules(SystemClass system, Stack<Task> tasks, SystemState initialStateList)
{
log.Info("SIMULATING... ");
// Create empty systemSchedule with initial state set
SystemSchedule emptySchedule = new SystemSchedule(initialStateList);
List<SystemSchedule> systemSchedules = new List<SystemSchedule>();
systemSchedules.Add(emptySchedule);
// if all asset position types are not dynamic types, can pregenerate accesses for the simulation
bool canPregenAccess = true;
foreach (var asset in system.Assets)
{
if(asset.AssetDynamicState != null)
canPregenAccess &= asset.AssetDynamicState.Type != HSFUniverse.DynamicStateType.DYNAMIC_ECI && asset.AssetDynamicState.Type != HSFUniverse.DynamicStateType.DYNAMIC_LLA;
else
canPregenAccess = false;
}
// if accesses can be pregenerated, do it now
Stack<Access> preGeneratedAccesses = new Stack<Access>();
Stack<Stack<Access>> scheduleCombos = new Stack<Stack<Access>>();
if (canPregenAccess)
{
log.Info("Pregenerating Accesses...");
//DWORD startPregenTickCount = GetTickCount();
preGeneratedAccesses = Access.pregenerateAccessesByAsset(system, tasks, _startTime, _endTime, _stepLength);
//DWORD endPregenTickCount = GetTickCount();
//pregenTimeMs = endPregenTickCount - startPregenTickCount;
//writeAccessReport(access_pregen, tasks); - TODO: Finish this code - EAM
log.Info("Done pregenerating accesses");
}
// otherwise generate an exhaustive list of possibilities for assetTaskList
else
{
log.Info("Generating Exhaustive Task Combinations... ");
Stack<Stack<Access>> exhaustive = new Stack<Stack<Access>>();
Stack<Access> allAccesses = new Stack<Access>(tasks.Count);
foreach (var asset in system.Assets)
{
foreach (var task in tasks)
allAccesses.Push(new Access(asset, task));
allAccesses.Push(new Access(asset, null));
exhaustive.Push(allAccesses);
allAccesses.Clear();
}
scheduleCombos = (Stack<Stack<Access>>)exhaustive.CartesianProduct();
log.Info("Done generating exhaustive task combinations");
}
/// TODO: Delete (or never create in the first place) schedules with inconsistent asset tasks (because of asset dependencies)
// Find the next timestep for the simulation
//DWORD startSchedTickCount = GetTickCount();
int i = 1;
List<SystemSchedule> potentialSystemSchedules = new List<SystemSchedule>();
List<SystemSchedule> systemCanPerformList = new List<SystemSchedule>();
for (double currentTime = _startTime; currentTime < _endTime; currentTime += _stepLength)
{
log.Info("Simulation Time " + currentTime);
// if accesses are pregenerated, look up the access information and update assetTaskList
if (canPregenAccess)
scheduleCombos = GenerateExhaustiveSystemSchedules(preGeneratedAccesses, system, currentTime);
// Check if it's necessary to crop the systemSchedule list to a more managable number
if (systemSchedules.Count > _maxNumSchedules)
{
log.Info("Cropping Schedules...");
CropSchedules(systemSchedules, ScheduleEvaluator, emptySchedule);
systemSchedules.Add(emptySchedule);
}
// Generate an exhaustive list of new tasks possible from the combinations of Assets and Tasks
//TODO: Parallelize this.
int k = 0;
foreach (var oldSystemSchedule in systemSchedules)
{
potentialSystemSchedules.Add(new SystemSchedule( new StateHistory(oldSystemSchedule.AllStates)));
foreach (var newAccessStack in scheduleCombos)
{
k++;
if (oldSystemSchedule.CanAddTasks(newAccessStack, currentTime))
{
var CopySchedule = new StateHistory(oldSystemSchedule.AllStates);
potentialSystemSchedules.Add(new SystemSchedule(CopySchedule, newAccessStack, currentTime));
// oldSched = new SystemSchedule(CopySchedule);
}
//.........这里部分代码省略.........
示例2: GenerateExhaustiveSystemSchedules
/// <summary>
/// Return all possible combinations of performing Tasks by Asset at current simulation time
/// </summary>
/// <param name="currentAccessForAllAssets"></param>
/// <param name="system"></param>
/// <param name="currentTime"></param>
/// <returns></returns>
public static Stack<Stack<Access>> GenerateExhaustiveSystemSchedules(Stack<Access> currentAccessForAllAssets, SystemClass system, double currentTime)
{
// A stack of accesses stacked by asset
Stack<Stack<Access>> currentAccessesByAsset = new Stack<Stack<Access>>();
foreach (Asset asset in system.Assets)
currentAccessesByAsset.Push(Access.getCurrentAccessesForAsset(currentAccessForAllAssets, asset, currentTime));
IEnumerable<IEnumerable<Access>> allScheduleCombos = currentAccessesByAsset.CartesianProduct();
Stack<Stack<Access>> allOfThem = new Stack<Stack<Access>>();
foreach (var accessStack in allScheduleCombos)
{
Stack<Access> someOfThem = new Stack<Access>(accessStack);
allOfThem.Push(someOfThem);
}
return allOfThem;
}