| 742 | |
| 743 | template<class View, class Val, class Degree, class StateIdx> |
| 744 | Actor* |
| 745 | LayeredGraph<View,Val,Degree,StateIdx>::copy(Space& home) { |
| 746 | // Eliminate an assigned prefix |
| 747 | { |
| 748 | int k=0; |
| 749 | while (layers[k].size == 1) { |
| 750 | assert(layers[k].support[0].n_edges == 1); |
| 751 | n_states -= layers[k].n_states; |
| 752 | k++; |
| 753 | } |
| 754 | if (k > 0) { |
| 755 | /* |
| 756 | * The state information is always available: either the propagator |
| 757 | * has been created (hence, also the state information has been |
| 758 | * created), or the first variable become assigned and hence |
| 759 | * an advisor must have been run (which then has created the state |
| 760 | * information). |
| 761 | */ |
| 762 | // Eliminate assigned layers |
| 763 | n -= k; layers += k; |
| 764 | // Eliminate edges |
| 765 | n_edges -= static_cast<unsigned int>(k); |
| 766 | // Update advisor indices |
| 767 | for (Advisors<Index> as(c); as(); ++as) |
| 768 | as.advisor().i -= k; |
| 769 | // Update all change information |
| 770 | a_ch.lshift(k); |
| 771 | } |
| 772 | } |
| 773 | audit(); |
| 774 | |
| 775 | // Compress states |
| 776 | if (!a_ch.empty()) { |
| 777 | int f = a_ch.fst(); |
| 778 | int l = a_ch.lst(); |
| 779 | assert((f >= 0) && (l <= n)); |
| 780 | Region r; |
| 781 | // State map for in-states |
| 782 | StateIdx* i_map = r.alloc<StateIdx>(max_states); |
| 783 | // State map for out-states |
| 784 | StateIdx* o_map = r.alloc<StateIdx>(max_states); |
| 785 | // Number of in-states |
| 786 | StateIdx i_n = 0; |
| 787 | |
| 788 | n_states -= layers[l].n_states; |
| 789 | // Initialize map for in-states and compress |
| 790 | for (StateIdx j=0; j<layers[l].n_states; j++) |
| 791 | if ((layers[l].states[j].i_deg != 0) || |
| 792 | (layers[l].states[j].o_deg != 0)) { |
| 793 | layers[l].states[i_n]=layers[l].states[j]; |
| 794 | i_map[j]=i_n++; |
| 795 | } |
| 796 | layers[l].n_states = i_n; |
| 797 | n_states += layers[l].n_states; |
| 798 | assert(i_n > 0); |
| 799 | |
| 800 | // Update in-states in edges for last layer, if any |
| 801 | if (l < n) |