This is my thoughts on a detailed algorithm for the PolicyEngineComputation.
NOTE: The current algorithm places the importance of running of all resources over the running of a resource on a given node.
Required Objects
node {
char *id;
int weight;
};
color {
int id;
node *candidate_nodes;
node chosen_node;
};
placement_constraint {
resource res_lh;
resource res_rh;
node node_rh;
enum contype operation;
};
resource {
char *id;
xmlNodePtr xml;
int priority;
int *candidate_colors;
int color;
gboolean provisional;
node *allowed_nodes;
placement_constraint *positive;
placement_constraint *negative;
};
Phase 1 : Unpack
- Unpack Nodes into a GSList
- Sort GSList by node.id
- Unpack Resources into GSList
- Filter inactive nodes out of resource.candiate_nodes
- Sort Resources by resource.priority
- Unpack Constraints
- Process Constraints
Duplicate and invert binary constraints (A != B --> A != B, B != A)
- Anything else?
- Attach constraints to resource.positive or resource.negative depending on type
- Further filter resource.allowed_nodes based on any resource_to_node type constraints
Phase 2 : Color
- Set initial color
- Set color.candidate_nodes = all active nodes
- Set resource.color = color (all resources)
- Set resource.provisional = TRUE (all resources)
- Take (next) highest resource
- if resource.provisional == FALSE, repeat
- For resource.negative,
if resource.negative.res_rh.provisional == FALSE
Remove resource.negative.res_rh.color from resource.candiate_colors
- Choose a color (this may need modification pending further napkin drawings)
- For resource.candidate_colors
If resource.candidate_color.candidate_nodes & resource.allowed_nodes != NULL
resource.candidate_color.candidate_nodes &= resource.allowed_nodes
- merge node weights
- resource.color = resource.candidate_color
- resource.provisional = FALSE
- If resource.provisional = TRUE
- Create new color
- color.candidate_nodes = resource.allowed_nodes
- resource.color = color
- resource.provisional = FALSE
- For resource.positive,
- resource.positive.res_rh.color = resource.color
- resource.positive.res_rh.provisional = FALSE
- For resources,
If resource.provisional = FALSE
Add current color to resource.candidate_colors
- For resource.negative,
if resource.negative.res_rh.provisional == FALSE
Remove resource.color from resource.negative.res_rh.candidate_colors
- Goto step 5
Phase 3 : Choose Nodes
For colors,
- If color(n) ^ color(n+1) == NULL
- Sort color.candidate_nodes by weight
- color.chosen_node = highest wieghted node
Else if color(n) & !color(n+1) != NULL
Sort (color(n) & !color(n+1)) by weight
- color.chosen_node = highest wieghted node
- Else
Sort (color(n+1) & !color(n)) by weight
- color.chosen_node = highest wieghted node
Phase 4 : Create Transition Graph
Phase 5 : Profit