Browse Source

test dowiazania zaleznych drog

a.binder 9 years ago
parent
commit
632cce4200

+ 5 - 4
SE/dev/php-cli/build_edge_paths_with_PE_controll_loop.xsl

@@ -26,7 +26,8 @@
                 <xsl:comment>test sort nie dziala</xsl:comment>
                 <xsl:comment>test sort nie dziala</xsl:comment>
                 <delete dir="{$edge_paths_with_PE_controll_temp}"/>
                 <delete dir="{$edge_paths_with_PE_controll_temp}"/>
                 <delete dir="{$edge_paths_with_PE_controll_temp.alias}"/>
                 <delete dir="{$edge_paths_with_PE_controll_temp.alias}"/>
-                <mkdir dir="{$edge_paths_with_PE_controll_temp}"/>
+                <delete dir="{$edge_paths_with_PE_controll_paths_temp}"/>
+                <mkdir dir="{$edge_paths_with_PE_controll_paths_temp}"/>
                 <symlink link="{$edge_paths_with_PE_controll_temp.alias}" resource="{$edge_paths_with_PE_controll_temp}"/>
                 <symlink link="{$edge_paths_with_PE_controll_temp.alias}" resource="{$edge_paths_with_PE_controll_temp}"/>
                 
                 
                 
                 
@@ -64,10 +65,10 @@
             <param name="Cable_Price" expression="{$Cable_Price}"/>
             <param name="Cable_Price" expression="{$Cable_Price}"/>
             <param name="max_combinate_groups_elements" expression="{$max_combinate_groups_elements}"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
             <param name="max_combinate_groups_elements" expression="{$max_combinate_groups_elements}"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
             <param name="logic" expression="{$logic}"/>
             <param name="logic" expression="{$logic}"/>
-            <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
-            <move file="{$edge_paths_with_PE_controll.xsl}.{@id}.xml" tofile="{$edge_paths_with_PE_controll_paths_temp}/{$edge_paths_with_PE_controll.xsl}.{@id}.xml"/>
-            
+            <param name="edge_paths_with_PE_controll_paths_temp" expression="{$edge_paths_with_PE_controll_paths_temp}"/>
+            <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly --> 
         </xslt>
         </xslt>
+        <move file="{$edge_paths_with_PE_controll.xsl}.{@id}.xml" todir="{$edge_paths_with_PE_controll_paths_temp}"/>
     </xsl:template>
     </xsl:template>
     
     
 </xsl:stylesheet>
 </xsl:stylesheet>

+ 191 - 19
SE/dev/php-cli/edge_paths_with_PE_controll.xsl

@@ -14,17 +14,17 @@
     
     
     <xsl:param name="PE_Price" select="2500"/>
     <xsl:param name="PE_Price" select="2500"/>
     <xsl:param name="Cable_Price" select="3"/>
     <xsl:param name="Cable_Price" select="3"/>
-    <xsl:param name="max_combinate_groups_elements" select="10"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
+    <xsl:param name="max_combinate_groups_elements" select="8"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
     <xsl:param name="logic" select="'grouped'"/> <!-- tutaj robi grupy po $max_combinate_groups_elements -->
     <xsl:param name="logic" select="'grouped'"/> <!-- tutaj robi grupy po $max_combinate_groups_elements -->
     <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
     <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
     
     
-    <xsl:param name="debug" select="0" />
+    <xsl:param name="debug" select="1"/>
     
     
     
     
     <!--<xsl:param name="edge_paths_with_PE.xml"/>-->
     <!--<xsl:param name="edge_paths_with_PE.xml"/>-->
     <xsl:param name="edge_paths_with_PE_controll_temp" select="'edge_paths_with_PE_controll_temp'"/> <!-- cache do przekazywani danych z petli-->
     <xsl:param name="edge_paths_with_PE_controll_temp" select="'edge_paths_with_PE_controll_temp'"/> <!-- cache do przekazywani danych z petli-->
     <xsl:param name="edge_paths_with_PE_controll_temp.alias" select="'edge_paths_with_PE_controll_temp.alias'" />
     <xsl:param name="edge_paths_with_PE_controll_temp.alias" select="'edge_paths_with_PE_controll_temp.alias'" />
-    
+    <xsl:param name="edge_paths_with_PE_controll_paths_temp" select="'edge_paths_with_PE_controll_paths_temp'"/> <!-- do przechowywania calych sciezek do PathCrossed-->
     <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci  -->
     <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci  -->
     
     
     
     
@@ -36,8 +36,6 @@
             max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
             max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
             logic=<xsl:value-of select="$logic"/> .EOF
             logic=<xsl:value-of select="$logic"/> .EOF
         </xsl:message>
         </xsl:message>
-        
-        
         <edge_paths_with_PE_controll>
         <edge_paths_with_PE_controll>
                 <xsl:attribute name="logic" select="$logic"/>
                 <xsl:attribute name="logic" select="$logic"/>
                   <!--  <xsl:attribute name="id" select="@id"/>
                   <!--  <xsl:attribute name="id" select="@id"/>
@@ -47,7 +45,6 @@
                         <xsl:with-param name="edge_joins_filled_path" select="parent::node()"/><!-- jak lecimy natywnie dla pliku  edge_joins_filled_paths_xml to dane sa w node()-->
                         <xsl:with-param name="edge_joins_filled_path" select="parent::node()"/><!-- jak lecimy natywnie dla pliku  edge_joins_filled_paths_xml to dane sa w node()-->
                     </xsl:apply-templates>
                     </xsl:apply-templates>
         </edge_paths_with_PE_controll>
         </edge_paths_with_PE_controll>
-        
     </xsl:template>
     </xsl:template>
     
     
     <xsl:template match="edge_joins_filled_paths">
     <xsl:template match="edge_joins_filled_paths">
@@ -94,7 +91,6 @@
                 Points_cnt=<xsl:value-of select="@Points_cnt"/>
                 Points_cnt=<xsl:value-of select="@Points_cnt"/>
             </xsl:message>
             </xsl:message>
         <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
         <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
-        
         <EdgeWayJoinsPair>
         <EdgeWayJoinsPair>
             <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
             <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
         </EdgeWayJoinsPair>
         </EdgeWayJoinsPair>
@@ -102,6 +98,48 @@
         <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
         <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
         
         
         
         
+        <!-- sciagamy dane drog, z ktorymi sie przecinamy -->
+         <xsl:variable name="PathsCrossed">
+             <PathsCrossed>
+                <xsl:for-each-group select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString/Ways" group-by="@ID_WAY">
+                    <Ways>
+                        <xsl:variable name="ID_WAY_joining" select="@ID_WAY"/>
+                        <xsl:attribute name="ID_WAY" select="$ID_WAY_joining"/>
+                        <xsl:variable name="ways_id_joining" select="@ways_id"/>
+                        <xsl:attribute name="ways_id_joining" select="$ways_id_joining"/>
+                        <xsl:variable name="ID_Join_joining" select="parent::node()/@ID_Join"/>
+                        <xsl:attribute name="ID_Join_joining" select="$ID_Join_joining"/>
+                        <xsl:choose>
+                            <xsl:when test="doc-available(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))">
+                                <xsl:variable name="Neigh_controll">
+                                    <xsl:copy-of select="doc(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))"/>
+                                </xsl:variable>
+                                <!-- wykryc gdzie sie lacza i jakie sa odleglosci prawdziwe -->
+                                <!-- jak nasza droga sie laczy do przeciwnej? ktory nasz Way w nim siedzi -->
+                                <!-- zignorowac wezel zwiazany z podlaczonym tam joinem -->
+                               <!-- <IgnoreLocaldistance>
+                                    <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
+                                </IgnoreLocaldistance>
+                                <IgnoreLocaldistance>
+                                    <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
+                                </IgnoreLocaldistance>-->
+                                <!--<xsl:for-each select="$Neigh_controll/edge_paths_with_PE_controll/Path/PointMatrixGroupPE/PointMatrixGroup/odpalam_liczenie/(bp:Path_Point|bp:Path_Point_Cable)">
+                                    <xsl:copy-of select="."/>
+                                </xsl:for-each>-->
+                                <xsl:apply-templates mode="PathsCrossed" select="$Neigh_controll"/>
+                            </xsl:when>
+                            <xsl:otherwise>
+                                <xsl:message> WARNING path should be analyzed and aviable in:<xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></xsl:message>
+                                <Warning> WARNING path should be analyzed and aviable in: <xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></Warning>
+                            </xsl:otherwise>
+                        </xsl:choose>
+                    </Ways>
+                </xsl:for-each-group>
+             </PathsCrossed>
+         </xsl:variable>
+         <xsl:copy-of select="$PathsCrossed"/>
+            
+        
         <!-- rozmieszczamy prawidlowo PE na danej trasie -->
         <!-- rozmieszczamy prawidlowo PE na danej trasie -->
         <xsl:variable name="EconomicDistanceCut">
         <xsl:variable name="EconomicDistanceCut">
             <EconomicDistanceCut>
             <EconomicDistanceCut>
@@ -120,17 +158,78 @@
                             <xsl:when test="$Ways or $Points">
                             <xsl:when test="$Ways or $Points">
                                 <xsl:attribute name="point_count" select="$Points + $Ways"/>
                                 <xsl:attribute name="point_count" select="$Points + $Ways"/>
                                 <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
                                 <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
+                                <xsl:if test="Ways">
+                                    <!-- sprawdzamy jak sie dowiazuje i ile ma do najblizszego wezla -->
+                                        <xsl:for-each-group select="Ways" group-by="@ID_WAY">
+                                           <PathsCrossed>
+                                               <xsl:attribute name="ID_WAY" select="@ID_WAY"/><xsl:attribute name="debug" select="'created at #163 by parsing Ways'"/>
+                                            <xsl:variable name="Joining_ID_Join_from" select="parent::node()/@ID_Join"/>    
+                                            <xsl:choose>
+                                                <xsl:when test="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos">
+                                                    <xsl:variable name="NeighJoin_pos" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos"/>
+                                                    <xsl:variable name="NeighJoin_pos_distance" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@pos= $NeighJoin_pos]/@distance)"/>
+                                                    <xsl:attribute name="NeighJoin_pos" select="$NeighJoin_pos"/>
+                                                    <xsl:attribute name="NeighJoin_pos_distance" select="$NeighJoin_pos_distance"/>
+                                                    <xsl:attribute name="Deb_Cur_ID_WAY" select="@ID_WAY"/>
+                                                    <xsl:attribute name="Joining_ID_Join_from" select="$Joining_ID_Join_from"/>
+                                                    
+                                                    <!-- chk w gore -->
+                                                    <xsl:variable name="NeighJoin_way_up_pos" select="max($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos)  &lt; number($NeighJoin_pos) ]   /@pos)"/>
+                                                    <xsl:choose>
+                                                        <xsl:when test="$NeighJoin_way_up_pos">
+                                                            <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
+                                                            <xsl:variable name="NeighJoin_way_up_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@ID_Join" />
+                                                            <xsl:variable name="NeighJoin_way_up_len"   select="number($NeighJoin_pos_distance) - number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@distance) "/>
+                                                            <xsl:attribute name="NeighJoin_way_up_len" select="$NeighJoin_way_up_len"/>
+                                                            <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
+                                                            <xsl:attribute name="NeighJoin_way_up_ID_Join" select="$NeighJoin_way_up_ID_Join"/>
+                                                        </xsl:when>
+                                                        <xsl:otherwise>
+                                                            <xsl:attribute name="NeighJoin_way_up_len" select="-1"/>
+                                                        </xsl:otherwise>
+                                                    </xsl:choose>
+                                                    <xsl:variable name="NeighJoin_way_dn_pos" select="min($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos)  &gt; number($NeighJoin_pos) ]   /@pos)"/>
+                                                    <xsl:choose>
+                                                        <xsl:when test="$NeighJoin_way_dn_pos">
+                                                            <xsl:variable name="NeighJoin_way_dn_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@ID_Join"/>
+                                                            <xsl:variable name="NeighJoin_way_dn_len" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@distance) - number($NeighJoin_pos_distance) "/>
+                                                            <xsl:attribute name="NeighJoin_way_dn_pos" select="$NeighJoin_way_dn_pos"/>
+                                                            <xsl:attribute name="NeighJoin_way_dn_ID_Join" select="$NeighJoin_way_dn_ID_Join"/>
+                                                            <xsl:attribute name="NeighJoin_way_dn_len" select="$NeighJoin_way_dn_len"/>
+                                                        </xsl:when>
+                                                        <xsl:otherwise>
+                                                            <xsl:attribute name="NeighJoin_way_dn_len" select="-1"/>
+                                                        </xsl:otherwise>
+                                                    </xsl:choose>
+                                                    <!-- chk w dol -->
+                                                    <xsl:if test=" number($debug) &gt; 3">
+                                                            <debug186>
+                                                                <xsl:copy-of select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]"/>
+                                                            </debug186>
+                                                    </xsl:if>
+                                                </xsl:when>
+                                                <xsl:otherwise>
+                                                    <xsl:comment>No connection to other roads found</xsl:comment>
+                                                </xsl:otherwise>
+                                            </xsl:choose>
+                                           </PathsCrossed>
+                                        </xsl:for-each-group>
+                                </xsl:if>
                             </xsl:when>
                             </xsl:when>
                             <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
                             <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
                                 <xsl:attribute name="point_count" select="0"/>
                                 <xsl:attribute name="point_count" select="0"/>
                             </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
                             </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
                         </xsl:choose>
                         </xsl:choose>
+                            
                         </distance>
                         </distance>
                     </xsl:for-each>
                     </xsl:for-each>
             </EconomicDistanceCut>
             </EconomicDistanceCut>
         </xsl:variable>
         </xsl:variable>
-        <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
-            
+            <xsl:if test="$debug">
+                <debug_174>
+                      <xsl:copy-of select="$EconomicDistanceCut"/>
+                </debug_174>
+            </xsl:if>
             <xsl:variable name="EconomicDistanceCut2">
             <xsl:variable name="EconomicDistanceCut2">
                 <EconomicDistanceCut2>
                 <EconomicDistanceCut2>
                     <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
                     <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
@@ -175,6 +274,7 @@
                             <xsl:copy-of select="@pos"/><!-- position() -->
                             <xsl:copy-of select="@pos"/><!-- position() -->
                             <xsl:copy-of select="@len"/>
                             <xsl:copy-of select="@len"/>
                             <xsl:copy-of select="@ForceCutByPrice"/>
                             <xsl:copy-of select="@ForceCutByPrice"/>
+                            <xsl:copy-of select="PathsCrossed"/>
                             <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
                             <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
                         </distance2>
                         </distance2>
                     </xsl:for-each>
                     </xsl:for-each>
@@ -197,6 +297,7 @@
                                     <xsl:attribute name="PosCut3Flag" select="0"/>
                                     <xsl:attribute name="PosCut3Flag" select="0"/>
                                 </xsl:otherwise>
                                 </xsl:otherwise>
                             </xsl:choose>
                             </xsl:choose>
+                            <xsl:copy-of select="PathsCrossed"/>
                         </distance2>
                         </distance2>
                     </xsl:for-each>
                     </xsl:for-each>
                 </EconomicDistanceCut2>
                 </EconomicDistanceCut2>
@@ -209,6 +310,7 @@
                         <distance2>
                         <distance2>
                             <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
                             <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
                             <xsl:copy-of select="@*"/>
                             <xsl:copy-of select="@*"/>
+                            <xsl:copy-of select="PathsCrossed"/>
                         </distance2>
                         </distance2>
                     </xsl:for-each>
                     </xsl:for-each>
                 </EconomicDistanceCut2>
                 </EconomicDistanceCut2>
@@ -261,6 +363,7 @@
                                     <distance2>
                                     <distance2>
                                         <xsl:attribute name="PosMatrGroup" select="position()"/>
                                         <xsl:attribute name="PosMatrGroup" select="position()"/>
                                         <xsl:copy-of select="@*"></xsl:copy-of>
                                         <xsl:copy-of select="@*"></xsl:copy-of>
+                                        <xsl:copy-of select="PathsCrossed"/>
                                     </distance2>
                                     </distance2>
                                 </xsl:for-each>
                                 </xsl:for-each>
                         </PointMatrixGroupPos>
                         </PointMatrixGroupPos>
@@ -271,8 +374,11 @@
                 gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
                 gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
             -->
             -->
             <!-- debug -->
             <!-- debug -->
-           
-            <!--<xsl:copy-of select="$PointMatrixGroup"/>-->
+           <xsl:if test="number($debug) &gt; 3">
+               <debug_356>
+                    <xsl:copy-of select="$PointMatrixGroup"/>
+               </debug_356>
+           </xsl:if>
             <PointMatrixGroupPE>
             <PointMatrixGroupPE>
             <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
             <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
                 <xsl:for-each select="PointMatrixGroupPos">
                 <xsl:for-each select="PointMatrixGroupPos">
@@ -292,7 +398,7 @@
                         </xsl:message>
                         </xsl:message>
                 <!-- ida kandydaci -->
                 <!-- ida kandydaci -->
                         <xsl:variable name="candidates">
                         <xsl:variable name="candidates">
-                            <xsl:for-each select="distance2[ (  $logic='sorted' and ( ( position() &lt;= $bit_max_Pos and @point_count &gt;0 ) or (  position()=1 and $point_count_Pos &gt; 0 )  ) or position()= last()  )   or ( @point_count &gt;0 and $logic='grouped'  )  ]">  <!--@point_count &gt;0-->  <!--( position() &lt;= $bit_max_Pos and @point_count &gt;0 ) or (  position()=1 and $point_count_Pos &gt; 0 )  or position()= last() --> <!-- jak jest maly wspolczynnik to chociaz jeden punkt jak sa punkty jakies w tej grupie -->
+                            <xsl:for-each select="distance2[ @point_count &gt;0 ]">  <!--@point_count &gt;0-->   <!-- (  $logic='sorted' and ( ( position() &lt;= $bit_max_Pos and @point_count &gt;0 ) or (  position()=1 and $point_count_Pos &gt; 0 )  ) or position()= last()  )   or ( @point_count &gt;0 and $logic='grouped'  )  -->  <!--( position() &lt;= $bit_max_Pos and @point_count &gt;0 ) or (  position()=1 and $point_count_Pos &gt; 0 )  or position()= last() --> <!-- jak jest maly wspolczynnik to chociaz jeden punkt jak sa punkty jakies w tej grupie -->
                                     <!--<xsl:sort select="@cost_dist" order="descending"/>-->
                                     <!--<xsl:sort select="@cost_dist" order="descending"/>-->
                                     <bp:Path_Point>
                                     <bp:Path_Point>
                                         <xsl:copy-of select="@ID_Join"/>
                                         <xsl:copy-of select="@ID_Join"/>
@@ -307,6 +413,7 @@
                                         <xsl:attribute name="point_count" select="@point_count"/>
                                         <xsl:attribute name="point_count" select="@point_count"/>
                                         <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
                                         <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
                                         <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
                                         <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
+                                        <xsl:copy-of select="PathsCrossed"/>
                                     </bp:Path_Point>
                                     </bp:Path_Point>
                                 </xsl:for-each>
                                 </xsl:for-each>
                         </xsl:variable>
                         </xsl:variable>
@@ -332,7 +439,7 @@
                         </poprzednie_odpalam_liczenie_or_nie>-->
                         </poprzednie_odpalam_liczenie_or_nie>-->
                         <xsl:variable name="odpalam_liczenie_or_nie">
                         <xsl:variable name="odpalam_liczenie_or_nie">
                             <xsl:choose>
                             <xsl:choose>
-                                <xsl:when test="count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements  and count($candidates/bp:Path_Point)&gt;1">
+                                <xsl:when test="1=1"> <!-- bylo count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements  and count($candidates/bp:Path_Point)&gt;1-->
                                     <xsl:variable name="max_bit">
                                     <xsl:variable name="max_bit">
                                         <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
                                         <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
                                     </xsl:variable>
                                     </xsl:variable>
@@ -349,10 +456,10 @@
                                             <xsl:with-param name="max_bit" select="$max_bit"/>
                                             <xsl:with-param name="max_bit" select="$max_bit"/>
                                             <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
                                             <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
                                         </xsl:call-template>
                                         </xsl:call-template>
-                                        <debug352_cand><xsl:copy-of select="$candidates"></xsl:copy-of> </debug352_cand>
                                     </odpalam_liczenie>
                                     </odpalam_liczenie>
                                 </xsl:when>
                                 </xsl:when>
                                 <xsl:otherwise>
                                 <xsl:otherwise>
+                                    <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
                                     <xsl:for-each select="$candidates/bp:Path_Point">
                                     <xsl:for-each select="$candidates/bp:Path_Point">
                                         <bp:Path_Point>
                                         <bp:Path_Point>
                                             <xsl:copy-of select="@*"/>
                                             <xsl:copy-of select="@*"/>
@@ -363,6 +470,17 @@
                                 </xsl:otherwise>
                                 </xsl:otherwise>
                             </xsl:choose>
                             </xsl:choose>
                         </xsl:variable>
                         </xsl:variable>
+                        <xsl:if test="number($debug) &gt; 0">
+                            <debug423>
+                                <xsl:attribute name="liczenie_dla"/>
+                                <candidates>
+                                    <xsl:copy-of select="$candidates"/>
+                                </candidates>
+                                <poprzednie_odpalam_liczenie_or_nie>
+                                    <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
+                                </poprzednie_odpalam_liczenie_or_nie>
+                            </debug423>
+                        </xsl:if>
                         <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
                         <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
                         <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
                         <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
                             <poprzednie_odpalam_liczenie_or_nie>
                             <poprzednie_odpalam_liczenie_or_nie>
@@ -402,6 +520,14 @@
     
     
     
     
     
     
+    <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
+        <xsl:apply-templates mode="PathsCrossed"/>
+    </xsl:template>
+    <xsl:template match="bp:Path_Point_Cable|bp:Path_Point" mode="PathsCrossed">
+        <xsl:copy-of select="."/>
+    </xsl:template>
+    <xsl:template match="*|text()" mode="PathsCrossed"/>
+        
     
     
     
     
     
     
@@ -425,7 +551,7 @@
             </xsl:for-each>
             </xsl:for-each>
         </xsl:variable>
         </xsl:variable>
         <!-- debug -->
         <!-- debug -->
-        <xsl:if test="$debug">
+        <xsl:if test=" number($debug) &gt; 2">
             <variant><xsl:attribute name="variant" select="$variant"/>
             <variant><xsl:attribute name="variant" select="$variant"/>
                 <xsl:attribute name="cur_bit" select="$bit"/>
                 <xsl:attribute name="cur_bit" select="$bit"/>
                 <xsl:attribute name="best_cost" select="$best_cost"/>
                 <xsl:attribute name="best_cost" select="$best_cost"/>
@@ -447,7 +573,7 @@
                 <xsl:copy-of select="$calc_cost_way"/>    
                 <xsl:copy-of select="$calc_cost_way"/>    
             </costs>
             </costs>
         </xsl:variable>
         </xsl:variable>
-        <xsl:if test="$debug"><xsl:copy-of select="$cost_sum"/></xsl:if>
+        <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
         <xsl:variable name="best">
         <xsl:variable name="best">
             <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
             <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
             <xsl:choose>
             <xsl:choose>
@@ -465,7 +591,7 @@
                 </xsl:otherwise>
                 </xsl:otherwise>
             </xsl:choose>
             </xsl:choose>
         </xsl:variable>
         </xsl:variable>
-        <xsl:if test="$debug"><xsl:copy-of select="$best"/></xsl:if>
+        <xsl:if test=" number($debug) &gt; 3 "><xsl:copy-of select="$best"/></xsl:if>
         <xsl:choose>
         <xsl:choose>
             <xsl:when test="$bit = $max_bit">
             <xsl:when test="$bit = $max_bit">
                 <koniec_wariantow>
                 <koniec_wariantow>
@@ -543,13 +669,57 @@
                 <bp:Path_Point>
                 <bp:Path_Point>
                     <xsl:attribute name="poprzednia_grupa" select="true()"/>
                     <xsl:attribute name="poprzednia_grupa" select="true()"/>
                     <xsl:copy-of select="@*"/>
                     <xsl:copy-of select="@*"/>
+                    <xsl:attribute name="distance_Neigh" select="0"/>
                 </bp:Path_Point>
                 </bp:Path_Point>
             </xsl:for-each>
             </xsl:for-each>
             <xsl:for-each select="$cand_to_calc/bp:Path_Point">
             <xsl:for-each select="$cand_to_calc/bp:Path_Point">
                 <bp:Path_Point>
                 <bp:Path_Point>
                     <xsl:copy-of select="@*"/>
                     <xsl:copy-of select="@*"/>
+                    <xsl:attribute name="distance_Neigh" select="0"/>
                 </bp:Path_Point>
                 </bp:Path_Point>
             </xsl:for-each>
             </xsl:for-each>
+            <!-- dorzucenie Crossed -->
+
+            <xsl:for-each select="$cand_to_calc/bp:Path_Point">
+                    <xsl:variable name="PathCrossLast" select="position() = last()"/>
+                    <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
+                        <xsl:message>#681: PathsCrossed up $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>;</xsl:message>
+                        <bp:Path_Point>
+                            <xsl:attribute name="poprzednia_grupa" select="true()"/>
+                            <xsl:attribute name="bin_pos" select="1"/>
+                            <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
+                            <xsl:choose>
+                                <xsl:when test="$PathCrossLast">
+                                    <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@distance)"/>
+                                </xsl:when>
+                                <xsl:otherwise>
+                                    <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@distance)"/>
+                                </xsl:otherwise>
+                            </xsl:choose>
+                            <xsl:attribute name="pos" select="-1"/>
+                        </bp:Path_Point>
+                    </xsl:for-each>
+            </xsl:for-each>
+            <xsl:for-each select="$cand_to_calc/bp:Path_Point">
+                <xsl:variable name="PathCrossLast" select="position() = last()"/>
+                <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
+                    <xsl:message>#681: PathsCrossed dwn  $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_dn_ID_Join"/>;</xsl:message>
+                    <bp:Path_Point>
+                        <xsl:attribute name="poprzednia_grupa" select="true()"/>
+                        <xsl:attribute name="bin_pos" select="1"/>
+                        <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
+                        <xsl:choose>
+                            <xsl:when test="$PathCrossLast">
+                                <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@distance)"/>
+                            </xsl:when>
+                            <xsl:otherwise>
+                                <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@distance)"/>
+                            </xsl:otherwise>
+                        </xsl:choose>
+                        <xsl:attribute name="pos" select="-1"/>
+                    </bp:Path_Point>
+                </xsl:for-each>
+            </xsl:for-each>
             <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
             <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
         </xsl:variable>
         </xsl:variable>
         <xsl:if test="number($debug) &gt;1">
         <xsl:if test="number($debug) &gt;1">
@@ -562,6 +732,8 @@
             
             
         </xsl:if>
         </xsl:if>
         <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc  -->
         <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc  -->
+            <xsl:sort select="number(@distance)"/>
+            <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
             <xsl:choose>
             <xsl:choose>
                 <xsl:when test="@poprzednia_grupa">
                 <xsl:when test="@poprzednia_grupa">
                     <cost>
                     <cost>
@@ -572,7 +744,7 @@
                     </cost>
                     </cost>
                 </xsl:when>
                 </xsl:when>
                 <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
                 <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
-                    <xsl:variable name="way_up_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@id_path) &lt;  current()/number(@id_path )]/number(@id_path))"/>
+                    <xsl:variable name="way_up_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &lt;  current()/number(@distance )]/number(@id_path))"/>
                     <xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>
                     <xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>
                     <xsl:variable name="way_up_len" >
                     <xsl:variable name="way_up_len" >
                             <xsl:choose>
                             <xsl:choose>
@@ -581,7 +753,7 @@
                                 <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
                                 <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
                             </xsl:choose>
                             </xsl:choose>
                     </xsl:variable>
                     </xsl:variable>
-                    <xsl:variable name="way_dn_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@id_path) &gt;  current()/number(@id_path) ]/number(@id_path)) " />
+                    <xsl:variable name="way_dn_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &gt;  current()/number(@distance) ]/number(@id_path)) " />
                     <xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_dn_id ]/@ID_Join"/>
                     <xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_dn_id ]/@ID_Join"/>
                     <xsl:variable name="way_dn_len">
                     <xsl:variable name="way_dn_len">
                         <xsl:choose>
                         <xsl:choose>