I am exploring a general optimization framework to solve problems characterized by the following structure. Any literature references, search terms, or algorithmic strategies would be greatly appreciated. I aim to unify several algorithms I devised into a more general formulation to gain more control over the optimization criteria.
Given Data
For any optimization instance, the inputs are:
- A set of state numbers, $State$, commonly ranging in size from 2 to 35.
- A tree parentage relationship $Tree \subseteq State \times State$, which forms a rooted tree where every state, except the root, has a single parent. States can have any number of children.
- A directed graph $G = (V,E)$, specifically a control flow graph derived from source code. This graph is not always fully connected. Let $preds(v) = \{ p \mid (p,v) \in E \}$ denote the predecessors of a vertex $v$. The number of vertices $|V|$ is typically a few hundred.
- A partial assignment $Asg_{partial} \subseteq V \hookrightarrow State$, indicating that certain vertices are mandatorily assigned to specific states.
Derived Functions
From $Tree$, we derive:
- $transit_2(s_1, s_2) : State \times State \rightarrow \mathscr{P}(State)$, a symmetric function that returns the set of all states on the tree path from $s_1$ to $s_2$. It is equivalent to $transit_2(s_1, anc) \cup transit_2(s_2, anc)$, where $anc$ is the lowest common ancestor of $s_1$ and $s_2$.
- $transit_{\mathscr{P}}(S) : \mathscr{P}(State) \rightarrow \mathscr{P}(State)$, which extends $transit_2$ to a set of states. It represents the union of all tree nodes on all paths to their mutual common ancestor for the given set of states.
Optimization Goal
The goal is to extend $Asg_{partial}$ to a total function $Asg$, assigning states to all vertices while respecting the constraints set by $Asg_{partial}$. For any vertex $v$ pre-specified by $Asg_{partial}$, it must hold that $Asg(v) = Asg_{partial}(v)$. For all other vertices, $Asg$ should be chosen to minimize:
$TotalScore(Asg) = \sum_{v \in V} score_{Asg}(v)$
where
$score_{Asg}(v) = |transit_{\mathscr{P}}(Asg(v) \cup \bigcup_{p \in preds(v)} Asg(p))|$
This score represents the number of tree states that must be transited by all predecessors of $v$, in combination, en route to $v$.
Important Notes
This is distinct from minimizing the sum of the individual edge scores $\sum_{p \in preds(v)} |transit_2(Asg(p), Asg(v))|$ because the score function for a vertex depends on all its predecessors collectively. For example, if $Asg$ assigns $v$ to the same state $s$ as both its predecessors $p_1$ and $p_2$, then:
$score_{Asg}(v) = |\{s\}| = 1$
while treating the edges independently would yield:
$|\{s\}| + |\{s\}| = 2$
Alternative Conception
You could also think of the problem as embedding $G$ into $Tree$: that is, associating a set $V_{State} \subseteq V$ with each $State$. Then the score for each vertex $v$ would be the total cardinality of all $Tree$ nodes traversed by the predecessor edges incident to $v$, which we want to minimize globally by placing vertices and their predecessors as close as possible.
Additional Context
In my actual instances, vertices are numbered, and sequentially adjacent numbers frequently share the same state. My algorithms exploit this to consider states of groups of vertices at a time rather than every vertex independently. This detail is omitted above for simplicity, and because I was interested in more generalized approaches to the problem.
Per the first answer given below, it makes sense to clarify that the algorithm needs to be deterministic, and if possible, run in polynomial time. (The latter might be difficult without making use of the extra structure mentioned in the previous paragraph. This extra structure also gives an initial $Asg$: each vertex is assigned to the state of the next lower-numbered vertex whose state is dictated by $Asg_{partial}$.)
Requests
I welcome all algorithmic strategies, literature recommendations, and insights. Thank you for your time and assistance!