5 for (
int i = 1; i < indice.Count(); i++)
6 if (indice[i].estado != NULL)
7 delete indice[i].estado;
11int CListaNo::NovoElemento(
TNo elemento) {
13 if (limite == 0 || indice.Count() < 2 * limite) {
15 indice.Add({ elemento, 1, 1 });
16 id = indice.Count() - 1;
20 if (livre.
Count() == 0)
25 indice[
id = livre.
Pop()] = { elemento, 1, 1 };
30void CListaNo::LibertarLista() {
31 bool jaProcessados =
false;
34 while (livre.
Count() < limite) {
42 int anteriorID = -1, piorID = -1;
49 while (livre.
Count() < limite)
50 LibertarSeguinte(
atual);
55 LibertarSeguinte(piorID);
56 if (livre.
Count() < limite) {
59 while (
Proximo(anteriorID) != piorID) {
60 indice[anteriorID].proxDistinto = 1;
61 anteriorID =
Proximo(anteriorID);
63 LibertarSeguinte(anteriorID);
71void CListaNo::LibertarSeguinte(
int id) {
74 if (indice[i].estado != NULL) {
75 delete indice[i].estado;
76 indice[i].estado = NULL;
78 indice[id].prox = indice[i].prox;
79 indice[id].proxDistinto = indice[i].proxDistinto;
85 int idNovo = NovoElemento(elemento);
88 indice.Add({ NULL,-1,-1 });
91 valor =
Valor(idNovo);
95 if (valorI == valor) {
97 indice[idNovo].prox =
Proximo(i);
99 indice[i].prox = idNovo;
102 else if (valorI < valor)
110 indice[idNovo].prox =
Proximo(i);
111 indice[idNovo].proxDistinto =
Proximo(i);
112 indice[i].prox = idNovo;
113 indice[i].proxDistinto = idNovo;
120 indice[idNovo].prox = i;
121 indice[idNovo].proxDistinto = i;
122 while (j != idNovo) {
123 indice[j].proxDistinto = idNovo;
125 indice[j].prox = idNovo;
141 for (
int j = 0; j < elementos.
Count(); j++)
142 lbElementos.
Add(elementos[j]->LowerBound());
143 lbElementos.
Sort(&idElementos);
146 for (
int j = 0; j < idElementos.
Count(); j++)
147 id =
Inserir(elementos[idElementos[j]],
id);
int atual
Índice do elemento atual a processar.
int Inserir(TNo elemento, int id=0)
Insere um novo estado na lista, por ordem de LowerBound.
int ProximoDistinto(int i=-1)
Retorna o próximo elemento com custo distinto.
int Proximo(int i=-1)
Retorna o próximo elemento na lista.
int Valor(int i)
Retorna o valor (LowerBound) de um elemento.
Representa um estado no espaço de estados.
TVector< Item > & Sort(TVector< int > *idxvect=nullptr)
Ordena todo o vetor, opcionalmente devolvendo Ãndices ordenados.
TVector< Item > & Add(Item a)
TVector< Item > & Push(Item a)