File wellmet/voronoi.py changed (mode: 100644) (index 307bf40..9a12bdd) |
... |
... |
class ContactVoronoi: |
619 |
619 |
def update_contacts(self): |
def update_contacts(self): |
620 |
620 |
#č já vím, že sample box pokážde failsi přepočítavá |
#č já vím, že sample box pokážde failsi přepočítavá |
621 |
621 |
self.failsi = failsi = self.sample_box.failsi |
self.failsi = failsi = self.sample_box.failsi |
622 |
|
self.points = getattr(self.sample_box, self.model_space) |
|
|
622 |
|
self.points = points = getattr(self.sample_box, self.model_space) |
623 |
623 |
self.PDF = self.sample_box.pdf(self.model_space) |
self.PDF = self.sample_box.pdf(self.model_space) |
624 |
624 |
|
|
625 |
625 |
assert len(self._indices_to_update) == 0 |
assert len(self._indices_to_update) == 0 |
626 |
626 |
|
|
627 |
627 |
nis = self.ns |
nis = self.ns |
|
628 |
|
workers = self.workers |
628 |
629 |
|
|
629 |
630 |
#č zde postupně v cyklu prochazíme všemi (novými) páry kontaktů |
#č zde postupně v cyklu prochazíme všemi (novými) páry kontaktů |
630 |
631 |
#č a omezujeme se pouse nejbližšími vzorky |
#č a omezujeme se pouse nejbližšími vzorky |
|
... |
... |
class ContactVoronoi: |
635 |
636 |
for i in range(self._nsim, self.sample_box.nsim): |
for i in range(self._nsim, self.sample_box.nsim): |
636 |
637 |
if failsi[i]: #č první je červený |
if failsi[i]: #č první je červený |
637 |
638 |
for j in range(i): |
for j in range(i): |
|
639 |
|
tp = TwoPoints(points, (i, j), workers=workers) |
638 |
640 |
if failsi[j]: |
if failsi[j]: |
639 |
641 |
#č červený kontakt |
#č červený kontakt |
640 |
642 |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
641 |
|
self.onboard_couple((i, j), event_id=1, nis=nis) |
|
|
643 |
|
self.onboard_couple(tp, event_id=1, nis=nis) |
642 |
644 |
else: |
else: |
643 |
645 |
#č žlutý kontakt |
#č žlutý kontakt |
644 |
646 |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
645 |
|
self.onboard_couple((i, j), event_id=2, nis=nis) |
|
|
647 |
|
self.onboard_couple(tp, event_id=2, nis=nis) |
646 |
648 |
|
|
647 |
649 |
else: #č první je zelený |
else: #č první je zelený |
648 |
650 |
for j in range(i): |
for j in range(i): |
649 |
651 |
if failsi[j]: |
if failsi[j]: |
650 |
652 |
#č žlutý kontakt |
#č žlutý kontakt |
651 |
653 |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
652 |
|
self.onboard_couple((i, j), event_id=2, nis=nis) |
|
|
654 |
|
tp = TwoPoints(points, (i, j), workers=workers) |
|
655 |
|
self.onboard_couple(tp, event_id=2, nis=nis) |
653 |
656 |
|
|
654 |
657 |
#else: #č jinak nič |
#else: #č jinak nič |
655 |
658 |
#оӵ Вож. Кулэ ӧвӧл |
#оӵ Вож. Кулэ ӧвӧл |
|
... |
... |
class ContactVoronoi: |
824 |
827 |
self.mixed_couples.pop(couple_indices, None) |
self.mixed_couples.pop(couple_indices, None) |
825 |
828 |
self.red_couples.pop(couple_indices, None) |
self.red_couples.pop(couple_indices, None) |
826 |
829 |
|
|
827 |
|
def onboard_couple(self, couple_indices, event_id, nis): |
|
828 |
|
#č (i, j)? poprvé ta čísla vidíme |
|
829 |
|
i, j = couple_indices |
|
|
830 |
|
def explore_couple(self, couple_indices, nis): |
|
831 |
|
""" |
|
832 |
|
Method is dedicated for the external usage. |
|
833 |
|
If someone thinks CV missed out some pair, |
|
834 |
|
it could say about and try to fix the thing. |
|
835 |
|
""" |
|
836 |
|
i, j = max(couple_indices), min(couple_indices) |
|
837 |
|
couple_indices = (i, j) |
|
838 |
|
failsi = self.sample_box.failsi |
|
839 |
|
if failsi[i]: #č první je červený |
|
840 |
|
if failsi[j]: |
|
841 |
|
#č červený kontakt |
|
842 |
|
# -1 = 'outside', 0=success, 1=failure, 2=mix |
|
843 |
|
event_id = 1 |
|
844 |
|
else: |
|
845 |
|
#č žlutý kontakt |
|
846 |
|
# -1 = 'outside', 0=success, 1=failure, 2=mix |
|
847 |
|
event_id = 2 |
|
848 |
|
|
|
849 |
|
else: #č první je zelený |
|
850 |
|
if failsi[j]: |
|
851 |
|
#č žlutý kontakt |
|
852 |
|
# -1 = 'outside', 0=success, 1=failure, 2=mix |
|
853 |
|
event_id = 2 |
|
854 |
|
else: |
|
855 |
|
return |
|
856 |
|
#оӵ Вож. Кулэ ӧвӧл |
830 |
857 |
|
|
831 |
858 |
tp = TwoPoints(self.points, couple_indices, workers=self.workers) |
tp = TwoPoints(self.points, couple_indices, workers=self.workers) |
|
859 |
|
#č pokud pár známe, jen přídáme další sadu bodů |
|
860 |
|
if couple_indices in self.couples: |
|
861 |
|
if event_id == 2: |
|
862 |
|
best_nodes = self.mixed_couples[couple_indices] |
|
863 |
|
else: |
|
864 |
|
best_nodes = self.red_couples[couple_indices] |
|
865 |
|
nodes = self.sample_alike(tp, best_nodes, nis) |
|
866 |
|
if nodes is not None: |
|
867 |
|
self.couples[couple_indices].append(nodes.idx) |
|
868 |
|
if nodes.score > best_nodes.score: |
|
869 |
|
self._recommend_to_integration(nodes) |
|
870 |
|
|
|
871 |
|
return nodes |
|
872 |
|
|
|
873 |
|
#č pár nám není znám. Ještě jednou pokusíme nasypat body |
|
874 |
|
nodes = self.onboard_couple(tp, event_id=event_id, nis=nis) |
|
875 |
|
|
|
876 |
|
#č project páry na update |
|
877 |
|
for couple_indices in self._indices_to_update: |
|
878 |
|
#č nepodporuje slovník množinové operace |
|
879 |
|
self.update_couple(couple_indices) |
|
880 |
|
self._indices_to_update.clear() |
|
881 |
|
|
|
882 |
|
return nodes |
|
883 |
|
|
|
884 |
|
|
|
885 |
|
|
|
886 |
|
|
|
887 |
|
|
|
888 |
|
def onboard_couple(self, tp, event_id, nis): |
|
889 |
|
#č (i, j)? poprvé ta čísla vidíme |
|
890 |
|
i, j = couple_indices = tp.couple_indices |
|
891 |
|
|
832 |
892 |
midpoint = tp.half_point |
midpoint = tp.half_point |
833 |
893 |
#č Nejdřív - zda je přímy kontakt, prostě na usečce |
#č Nejdřív - zda je přímy kontakt, prostě na usečce |
834 |
894 |
#TData(X=nodes[gmask], imask, dd) |
#TData(X=nodes[gmask], imask, dd) |
|
... |
... |
class ContactVoronoi: |
836 |
896 |
if nodes is not None: |
if nodes is not None: |
837 |
897 |
#č kontakt existuje, dáme vědět aktualizovačce |
#č kontakt existuje, dáme vědět aktualizovačce |
838 |
898 |
##č (snad jediné místo kde tuhle funkci voláme) |
##č (snad jediné místo kde tuhle funkci voláme) |
|
899 |
|
self._add_indices_to_update(i) #č může nás volat i explore_couple() |
839 |
900 |
self._add_indices_to_update(j) |
self._add_indices_to_update(j) |
840 |
901 |
self.couples[couple_indices].append(nodes.idx) |
self.couples[couple_indices].append(nodes.idx) |
841 |
902 |
|
|
|
... |
... |
class ContactVoronoi: |
875 |
936 |
|
|
876 |
937 |
#č kontakt existuje, dáme vědět aktualizovačce |
#č kontakt existuje, dáme vědět aktualizovačce |
877 |
938 |
##č (druhé místo kde tuhle funkci voláme) |
##č (druhé místo kde tuhle funkci voláme) |
|
939 |
|
self._add_indices_to_update(i) #č může nás volat i explore_couple() |
878 |
940 |
self._add_indices_to_update(j) |
self._add_indices_to_update(j) |
879 |
941 |
self.couples[couple_indices].append(nodes.idx) |
self.couples[couple_indices].append(nodes.idx) |
880 |
942 |
|
|
|
... |
... |
class ContactVoronoi: |
897 |
959 |
#č zde je to totálná zbytečnost |
#č zde je to totálná zbytečnost |
898 |
960 |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
# -1 = 'outside', 0=success, 1=failure, 2=mix |
899 |
961 |
self._recommend_to_integration(best_nodes) |
self._recommend_to_integration(best_nodes) |
900 |
|
|
|
|
962 |
|
return best_nodes |
901 |
963 |
|
|
902 |
964 |
|
|
903 |
965 |
|
|