added multiple actions for storage unit , and simulation bug fix
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { extractTriggersFromPoint } from "./extractTriggersFromPoint";
|
||||
|
||||
export function determineExecutionOrder(products: productsSchema): PointsScheme[] {
|
||||
export function determineExecutionOrder(products: productsSchema): Action[] {
|
||||
// Create maps for all events and points
|
||||
const eventMap = new Map<string, EventsSchema>();
|
||||
const pointMap = new Map<string, PointsScheme>();
|
||||
const allPoints: PointsScheme[] = [];
|
||||
const spawnActions: Action[] = [];
|
||||
|
||||
// First pass: collect all points
|
||||
// First pass: collect all points and identify spawn actions
|
||||
products.forEach(product => {
|
||||
product.eventDatas.forEach(event => {
|
||||
eventMap.set(event.modelUuid, event);
|
||||
@@ -15,6 +16,11 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
||||
event.points.forEach(point => {
|
||||
pointMap.set(point.uuid, point);
|
||||
allPoints.push(point);
|
||||
|
||||
// Check for spawn actions in conveyors
|
||||
if (point.action.actionType === 'spawn') {
|
||||
spawnActions.push(point.action);
|
||||
}
|
||||
});
|
||||
} else if (event.type === 'vehicle' ||
|
||||
event.type === 'machine' ||
|
||||
@@ -25,6 +31,16 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
||||
) {
|
||||
pointMap.set(event.point.uuid, event.point);
|
||||
allPoints.push(event.point);
|
||||
|
||||
// Check for spawn actions in storage units and other types
|
||||
if (event.type === 'storageUnit') {
|
||||
const storagePoint = event.point as StoragePointSchema;
|
||||
storagePoint.actions.forEach(action => {
|
||||
if (action.actionType === 'retrieve') {
|
||||
spawnActions.push(action);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -33,11 +49,19 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
||||
const graph = new Map<string, string[]>();
|
||||
const reverseGraph = new Map<string, string[]>();
|
||||
const allTriggeredPoints = new Set<string>();
|
||||
const actionMap = new Map<string, Action>(); // Map point UUID to its primary action
|
||||
|
||||
allPoints.forEach(point => {
|
||||
const triggers = extractTriggersFromPoint(point);
|
||||
const dependencies: string[] = [];
|
||||
|
||||
// Store the primary action for this point
|
||||
if ('action' in point) {
|
||||
actionMap.set(point.uuid, point.action);
|
||||
} else if ('actions' in point && point.actions.length > 0) {
|
||||
actionMap.set(point.uuid, point.actions[0]); // Use first action as primary
|
||||
}
|
||||
|
||||
triggers.forEach(trigger => {
|
||||
const targetUuid = trigger.triggeredAsset?.triggeredPoint?.pointUuid;
|
||||
if (targetUuid && pointMap.has(targetUuid)) {
|
||||
@@ -58,15 +82,12 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
||||
const rootPoints = allPoints
|
||||
.filter(point => !allTriggeredPoints.has(point.uuid))
|
||||
.filter(point => {
|
||||
// Only include roots that actually have triggers pointing FROM them
|
||||
const triggers = extractTriggersFromPoint(point);
|
||||
return triggers.some(t => t.triggeredAsset?.triggeredPoint?.pointUuid);
|
||||
});
|
||||
|
||||
// If no root points found but we have triggered points, find the earliest triggers
|
||||
if (rootPoints.length === 0 && allTriggeredPoints.size > 0) {
|
||||
// This handles cases where we have circular dependencies
|
||||
// but still want to include the triggered points
|
||||
const minTriggerCount = Math.min(
|
||||
...Array.from(allTriggeredPoints)
|
||||
.map(uuid => (graph.get(uuid) || []).length)
|
||||
@@ -105,11 +126,18 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
||||
// Start processing from root points
|
||||
rootPoints.forEach(root => visit(root.uuid));
|
||||
|
||||
// Convert UUIDs back to points and filter out untriggered points
|
||||
const triggeredPoints = order
|
||||
.map(uuid => pointMap.get(uuid)!)
|
||||
.filter(point => allTriggeredPoints.has(point.uuid) ||
|
||||
rootPoints.some(root => root.uuid === point.uuid));
|
||||
// Convert UUIDs back to actions
|
||||
const triggeredActions = order
|
||||
.map(uuid => actionMap.get(uuid))
|
||||
.filter((action): action is Action => action !== undefined);
|
||||
|
||||
return triggeredPoints;
|
||||
// Combine triggered actions with ALL spawn actions
|
||||
const allExecutionActions = [...triggeredActions, ...spawnActions];
|
||||
|
||||
// Remove duplicate actions while preserving order
|
||||
const uniqueActions = allExecutionActions.filter((action, index, array) =>
|
||||
array.findIndex(a => a.actionUuid === action.actionUuid) === index
|
||||
);
|
||||
|
||||
return uniqueActions;
|
||||
}
|
||||
@@ -21,12 +21,13 @@ function Simulator() {
|
||||
if (!product) return;
|
||||
|
||||
const executionOrder = determineExecutionOrder([product]);
|
||||
executionOrder.forEach(point => {
|
||||
const action = 'actions' in point ? point.actions[0] : point.action;
|
||||
|
||||
executionOrder.forEach(action => {
|
||||
handleAction(action);
|
||||
});
|
||||
}, [products, isPlaying, isReset, selectedProduct]);
|
||||
|
||||
|
||||
return (
|
||||
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user