Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strategy Priority v0.1.68 #220

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ActionStrategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@ As this is an enhancement to the traditional understanding of higher order funct
```typescript
export interface ActionStrategyParameters {
topic: string;
data?: unknown;
data?: Record<string, unknown>;
initialNode: ActionNode;
priority?: number;
}
export interface ActionStrategy {
topic: string;
data?: unknown;
data?: Record<string, unknown>;
currentNode: ActionNode;
actionList: Array<string>;
lastActionNode: ActionNode;
puntedStrategy?: ActionStrategy[];
stubs?: OwnershipTicketStub[];
priority?: number;
step?: number;
}
```
* topic - The topic string or the beginning sentence of a Stratimux dialog paragraph. Also stores itself temporarily upon strategy completion on the Axium as **lastStrategy**. We suggest using this field to determine when your strategies of concluding during testing, or when to dispatch some other strategy.
Expand All @@ -110,6 +113,8 @@ export interface ActionStrategy {
* lastActionNode - Primarily functions to clear ownership upon each successive action from the strategy. Likewise can be used to determine the current decision, or preposition of the current ActionNode at runtime.
* puntedStrategy - This allows for strategies to be successively chained into one another by first in, first Out principle upon each strategy conclusion.
* initialNode via ActionStrategyParameters - The initial node that is the head that is ran by the strategyBegin consumer function.
* priority - This will assign a default priority to each action issued from a strategy, but allows for actions to have their own atomically.
* step - Mainly for trouble shooting purposes, but likewise may be used via some analytics for insight.

## Consumer Functions
```typescript
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ When in doubt simplify.
* [Unified Turing Machine](https://github.com/Phuire-Research/Stratimux/blob/main/The-Unified-Turing-Machine.md) - The governing concept for this entire framework.

## Change Log ![Tests](https://github.com/Phuire-Research/Stratimux/actions/workflows/node.js.yml/badge.svg)
### Strategy Priority v0.1.68 5/15/2024
* Added priority to strategies, this priority will be assigned to each step issued by such.
* With this change you may now have strategies jump all lines upon creation, ensuring some change prior to other action's taking effect.
* Unless a ActionNode or incoming Action created by createActionNode has its own priority, then that takes precedents. But does not effect the Strategy's overall priority.
### **BREAKING** v0.1.67 5/13/2024
* Revamped the Action Creator Functions to follow behind the current creator with an **options** parameter design choice.
* Note pure action creators will not provide an option for payload
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stratimux",
"license": "GPL-3.0",
"version": "0.1.67",
"version": "0.1.68",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
1 change: 0 additions & 1 deletion src/concepts/axium/axium.principle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const axiumPrinciple: PrincipleFunction = (
forEachConcept(concepts, (concept, s) => {
newConcepts[Number(s)] = concept;
});

axiumState.addConceptQue.forEach((concept, _index) => {
concept.semaphore = axiumState.conceptCounter;
if (concept.mode !== undefined) {
Expand Down
61 changes: 54 additions & 7 deletions src/model/actionStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export interface ActionStrategyParameters {
topic: string;
data?: Record<string, unknown>;
initialNode: ActionNode;
priority?: number;
}
export interface ActionStrategy {
topic: string;
Expand All @@ -184,6 +185,8 @@ export interface ActionStrategy {
actionList: Array<string>;
puntedStrategy?: ActionStrategy[];
stubs?: OwnershipTicketStub[];
priority?: number;
step?: number;
}

export type ActionStrategyTopic = string;
Expand Down Expand Up @@ -220,6 +223,7 @@ export function createStrategy(
): ActionStrategy {
const data: Record<string, unknown> | undefined = params.data;
const currentNode: ActionNode = params.initialNode;
const priority = params.priority;
currentNode.lastActionNode = {
// This logically determines that all ActionNodes will have a Action associated.
action: createAction(nullActionType),
Expand All @@ -233,11 +237,19 @@ export function createStrategy(
data,
currentNode,
actionList,
priority,
step: 0
};
}

export const strategyBegin = (strategy: ActionStrategy, data?: Record<string, unknown>): Action => {
const currentNode = strategy.currentNode;
let priority;
if (currentNode.priority) {
priority = currentNode.priority;
} else if (strategy.priority) {
priority = strategy.priority;
}
strategy.currentNode.action = createAction(
currentNode.actionType,
{
Expand All @@ -246,7 +258,7 @@ export const strategyBegin = (strategy: ActionStrategy, data?: Record<string, un
agreement: currentNode.agreement,
semaphore: currentNode.semaphore,
conceptSemaphore: currentNode.conceptSemaphore,
priority: currentNode.priority
priority
}
);
strategy.currentNode.action.strategy = {
Expand All @@ -255,6 +267,8 @@ export const strategyBegin = (strategy: ActionStrategy, data?: Record<string, un
data: data ? data : strategy.data,
currentNode: strategy.currentNode,
actionList: strategy.actionList,
priority: strategy.priority,
step: strategy.step ? strategy.step + 1 : 1
};
if (strategy.currentNode.action !== null) {
return strategy.currentNode.action;
Expand All @@ -279,6 +293,12 @@ export const strategySuccess = (_strategy: ActionStrategy, data?: Record<string,
);
if (strategy.currentNode.successNode !== null) {
const nextNode = strategy.currentNode.successNode;
let priority;
if (nextNode.priority) {
priority = nextNode.priority;
} else if (strategy.priority) {
priority = strategy.priority;
}
nextAction = createAction(
nextNode.actionType,
{
Expand All @@ -287,7 +307,7 @@ export const strategySuccess = (_strategy: ActionStrategy, data?: Record<string,
agreement: nextNode.agreement,
semaphore: nextNode.semaphore,
conceptSemaphore: nextNode.conceptSemaphore,
priority: nextNode.priority
priority
}
);
nextNode.action = nextAction;
Expand All @@ -298,6 +318,7 @@ export const strategySuccess = (_strategy: ActionStrategy, data?: Record<string,
data: data ? data : strategy.data,
currentNode: nextNode,
actionList: [...strategy.actionList, actionListEntry],
step: strategy.step ? strategy.step + 1 : 1
};
return nextAction;
} else {
Expand All @@ -324,12 +345,15 @@ export const strategySuccess = (_strategy: ActionStrategy, data?: Record<string,
successNode: null,
failureNode: null,
lastActionNode: strategy.currentNode,
priority: strategy.priority
};
conclude.action = createAction(conclude.actionType);
conclude.action.priority = strategy.priority;
conclude.action.strategy = {
...strategy,
currentNode: conclude,
data: data ? data : strategy.data
data: data ? data : strategy.data,
step: strategy.step ? strategy.step + 1 : 1
};
return conclude.action;
}
Expand All @@ -352,6 +376,12 @@ export function strategyFailed(_strategy: ActionStrategy, data?: Record<string,
strategy.currentNode.failureNode !== null
) {
const nextNode = strategy.currentNode.failureNode;
let priority;
if (nextNode.priority) {
priority = nextNode.priority;
} else if (strategy.priority) {
priority = strategy.priority;
}
nextAction = createAction(
nextNode.actionType,
{
Expand All @@ -360,7 +390,7 @@ export function strategyFailed(_strategy: ActionStrategy, data?: Record<string,
agreement: nextNode.agreement,
semaphore: nextNode.semaphore,
conceptSemaphore: nextNode.conceptSemaphore,
priority: nextNode.priority
priority
}
);
nextNode.action = nextAction;
Expand All @@ -373,6 +403,7 @@ export function strategyFailed(_strategy: ActionStrategy, data?: Record<string,
data: strategy.data,
currentNode: nextNode,
actionList: strategy.actionList,
step: strategy.step ? strategy.step + 1 : 1
};
return nextAction;
} else {
Expand All @@ -399,12 +430,15 @@ export function strategyFailed(_strategy: ActionStrategy, data?: Record<string,
successNode: null,
failureNode: null,
lastActionNode: strategy.currentNode,
priority: strategy.priority
};
conclude.action = createAction(conclude.actionType);
conclude.action.priority = strategy.priority;
conclude.action.strategy = {
...strategy,
currentNode: conclude,
data: data ? data : strategy.data
data: data ? data : strategy.data,
step: strategy.step ? strategy.step + 1 : 1
};
return conclude.action;
}
Expand Down Expand Up @@ -436,6 +470,12 @@ export const strategyDecide = (
decisionNodes[decideKey] !== null
) {
const nextNode = decisionNodes[decideKey];
let priority;
if (nextNode.priority) {
priority = nextNode.priority;
} else if (strategy.priority) {
priority = strategy.priority;
}
nextAction = createAction(
nextNode.actionType,
{
Expand All @@ -444,7 +484,7 @@ export const strategyDecide = (
agreement: nextNode.agreement,
semaphore: nextNode.semaphore,
conceptSemaphore: nextNode.conceptSemaphore,
priority: nextNode.priority
priority
}
);
nextNode.action = nextAction;
Expand All @@ -456,6 +496,7 @@ export const strategyDecide = (
data: data ? data : strategy.data,
currentNode: nextNode,
actionList: strategy.actionList,
step: strategy.step ? strategy.step + 1 : 1
};
return nextAction;
}
Expand All @@ -482,12 +523,15 @@ export const strategyDecide = (
successNode: null,
failureNode: null,
lastActionNode: strategy.currentNode,
priority: strategy.priority
};
conclude.action = createAction(conclude.actionType);
conclude.action.priority = strategy.priority;
conclude.action.strategy = {
...strategy,
currentNode: conclude,
data: data ? data : strategy.data
data: data ? data : strategy.data,
step: strategy.step ? strategy.step + 1 : 1
};
return conclude.action;
};
Expand Down Expand Up @@ -529,6 +573,7 @@ export const strategyBackTrack = (_strategy: ActionStrategy): Action => {
...newNode.action.strategy.actionList,
strategy.actionList[strategy.actionList.length - 1],
];
strategy.step = strategy.step ? strategy.step + 1 : 1;
}
return newNode.action as Action;
} else {
Expand Down Expand Up @@ -571,6 +616,8 @@ export const strategyRecurse =
];
currentNode.action = action;
strategy.currentNode = currentNode;

strategy.step = strategy.step ? strategy.step + 1 : 1;
action.strategy = strategy;
return action;
};
Expand Down
26 changes: 21 additions & 5 deletions src/model/axium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,25 @@ export const blockingMethodSubscription = (concepts: Concepts, tail: Action[], a
strategyTopic: action.strategy.topic,
strategyData: action.strategy.data,
});
tail.push(appendToDialog);
if (isPriorityValid(action)) {
handlePriority(getAxiumState(concepts), action);
const state = getAxiumState(concepts);
handlePriority(state, action);
appendToDialog.priority = action.priority;
handlePriority(state, appendToDialog);
} else {
tail.push(appendToDialog);
tail.push(action);
}
} else if (
action.strategy &&
// Logical Determination: axiumBadType
action.semaphore[3] !== 1
) {
if (isPriorityValid(action)) {
handlePriority(getAxiumState(concepts), action);
} else {
tail.push(action);
}
tail.push(action);
}
};
Expand All @@ -70,10 +78,13 @@ export const defaultMethodSubscription = (concepts: Concepts, tail: Action[], ac
strategyData: action.strategy.data
});
// setTimeout(() => {
tail.push(appendToDialog);
if (isPriorityValid(action)) {
handlePriority(getAxiumState(concepts), action);
const state = getAxiumState(concepts);
handlePriority(state, action);
appendToDialog.priority = action.priority;
handlePriority(state, appendToDialog);
} else {
tail.push(appendToDialog);
tail.push(action);
}
if (async) {
Expand All @@ -87,7 +98,11 @@ export const defaultMethodSubscription = (concepts: Concepts, tail: Action[], ac
// Logical Determination: axiumBadType
action.semaphore[3] !== 1
) {
tail.push(action);
if (isPriorityValid(action)) {
handlePriority(getAxiumState(concepts), action);
} else {
tail.push(action);
}
if (async) {
axiumTimeOut(concepts, () => {
return axiumKick();
Expand Down Expand Up @@ -120,6 +135,7 @@ export function createAxium(
let axiumState = concepts[0].state as AxiumState;
axiumState.cachedSemaphores = createCacheSemaphores(concepts);
forEachConcept(concepts, ((concept, semaphore) => {
axiumState.conceptCounter += 1;
concept.qualities.forEach(quality => {
if (quality.methodCreator) {
[quality.method, quality.subject] = quality.methodCreator(axiumState.concepts$, semaphore);
Expand Down
4 changes: 4 additions & 0 deletions src/test/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { counterAdd, counterAddType } from '../concepts/counter/qualities/add.qu
test('Axium add Concepts Strategy Test', (done) => {
const something = createAction('something');
expect(something.type).toBe('something');
const somethingElse = createAction('somethingElse', {payload: {
name: 'somethingElse'
}});
expect(somethingElse.payload?.name).toBe('somethingElse');
const add = counterAdd();
expect(add.type).toBe(counterAddType);
console.log(add.type);
Expand Down
Loading
Loading