edge_paths_with_PE_controll.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
  5. exclude-result-prefixes="xs"
  6. version="2.0">
  7. <!--<xsl:import href="PE_wariant_bit_table.xsl"/>-->
  8. <xsl:output indent="yes"/>
  9. <xsl:strip-space elements="*"/>
  10. <xsl:param name="PE_Price" select="1500"/>
  11. <xsl:param name="Cable_Price" select="10"/>
  12. <xsl:param name="edge_paths_with_PE.xml"/>
  13. <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
  14. <xsl:template match="edge_joins_filled_paths">
  15. <xsl:variable name="edge_joins_filled_paths_len">
  16. <xsl:for-each select="item">
  17. <xsl:sort select="number(asText/@len)" order="descending"/>
  18. <Path>
  19. <xsl:attribute name="id" select="@id"/>
  20. <xsl:attribute name="len" select="asText/@len"/>
  21. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  22. </Path>
  23. </xsl:for-each>
  24. </xsl:variable>
  25. <xsl:variable name="edge_paths_with_PE_controll">
  26. <edge_paths_with_PE_controll>
  27. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  28. </edge_paths_with_PE_controll>
  29. </xsl:variable>
  30. <xsl:copy-of select="$edge_paths_with_PE_controll"/>
  31. <xsl:result-document href="edge_paths_with_PE.xml">
  32. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  33. </xsl:result-document>
  34. </xsl:template>
  35. <xsl:template match="edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml">
  36. <PE_candidates_dump>
  37. <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
  38. </PE_candidates_dump>
  39. </xsl:template>
  40. <xsl:template match="Path" mode="edge_paths_with_PE.xml">
  41. <LINESTRING>
  42. <xsl:attribute name="ID_Way" select="@id"/>
  43. <xsl:attribute name="Count" select="''"/>
  44. <xsl:attribute name="ID_Point_count" select="@Points_cnt"/>
  45. <xsl:attribute name="distance"/>
  46. <xsl:attribute name="dumb_frequency" select="''"/>
  47. <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
  48. </LINESTRING>
  49. </xsl:template>
  50. <xsl:template match="bp:Path_Point" mode="edge_paths_with_PE.xml">
  51. <xsl:copy-of select="."/>
  52. </xsl:template>
  53. <xsl:template match="Path" mode="PointMatrixGroup">
  54. <Path>
  55. <xsl:variable name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
  56. <xsl:attribute name="id" select="@id"/>
  57. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  58. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  59. <xsl:attribute name="len" select="@len"/>
  60. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  61. <xsl:variable name="len" select="@len"/>
  62. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  63. <!--<EdgeWayJoinsPair>
  64. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  65. </EdgeWayJoinsPair>-->
  66. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  67. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  68. <xsl:variable name="EconomicDistanceCut">
  69. <EconomicDistanceCut>
  70. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString">
  71. <distance>
  72. <xsl:attribute name="pos" select="position()"/>
  73. <xsl:attribute name="not_id" select="@not_id"/>
  74. <xsl:attribute name="len" select="@len"/>
  75. <xsl:attribute name="id_path" select="@id_path"/>
  76. <xsl:variable name="Points" select="count(Points)"/>
  77. <xsl:variable name="Ways" select="count(Ways)"/>
  78. <xsl:choose>
  79. <xsl:when test="Points or Ways">
  80. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  81. </xsl:when>
  82. </xsl:choose>
  83. </distance>
  84. </xsl:for-each>
  85. </EconomicDistanceCut>
  86. </xsl:variable>
  87. <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
  88. <xsl:variable name="EconomicDistanceCut2">
  89. <EconomicDistanceCut2>
  90. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  91. <distance2>
  92. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  93. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  94. <xsl:choose>
  95. <xsl:when test="@point_count&gt;0">
  96. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  97. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  98. ]/@pos)"/>
  99. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  100. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  101. number(@pos )&lt; number(current()/@pos )
  102. and number(@pos) &gt;= number($max_pos_z_pkt)
  103. ]/@len)"/>
  104. <xsl:attribute name="disttopkt" select="$disttopkt" />
  105. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * @point_count"/>
  106. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  107. <xsl:if test="$cost_dist &gt; $PE_Price">
  108. <xsl:attribute name="cut_by_pe" select="1"/>
  109. </xsl:if>
  110. <xsl:attribute name="not_id" select="@not_id"/>
  111. </xsl:when>
  112. </xsl:choose>
  113. <xsl:attribute name="id_path" select="@id_path"/>
  114. <xsl:copy-of select="@point_count"/>
  115. <xsl:copy-of select="@pos"/>
  116. <xsl:copy-of select="@len"/>
  117. </distance2>
  118. </xsl:for-each>
  119. </EconomicDistanceCut2>
  120. </xsl:variable>
  121. <!--<xsl:copy-of select="$EconomicDistanceCut2"/>-->
  122. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  123. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price]) )"/><!-- max licbza PE-->
  124. <!-- pogrupujemy elementy co 50 metrow -->
  125. <xsl:variable name="PointMatrixGroup">
  126. <PointMatrixGroup>
  127. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="round( @distance div ( $PE_Price div $Cable_Price + 50 ))">
  128. <PointMatrixGroupPos>
  129. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  130. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  131. <xsl:attribute name="distanceGr" select=" current-grouping-key()"/>
  132. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  133. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  134. <xsl:attribute name="id_path" select="@id_path"/>
  135. <xsl:attribute name="point_count_Pos" select="sum(current-group()/@point_count)"/>
  136. <xsl:for-each select="current-group()">
  137. <xsl:copy-of select="."/>
  138. </xsl:for-each>
  139. </PointMatrixGroupPos>
  140. </xsl:for-each-group>
  141. </PointMatrixGroup>
  142. </xsl:variable>
  143. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  144. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  145. -->
  146. <!-- debug -->
  147. <xsl:copy-of select="$PointMatrixGroup"/>
  148. <PointMatrixGroupPE>
  149. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup/PointMatrixGroupPos">
  150. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  151. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  152. <!-- ida kandydaci -->
  153. <xsl:for-each select="distance2[ position() &lt;= $bit_max_Pos or ( position()=1 and $point_count_Pos &gt; 0 ) ]"> <!-- jak jest maly wspolczynnik to chociaz jeden punkt jak sa punkty jakies w tej grupie -->
  154. <xsl:sort select="@cost_dist" order="descending"/>
  155. <bp:Path_Point>
  156. <xsl:attribute name="pos" select="@pos"/>
  157. <xsl:attribute name="len" select="@len"/>
  158. <xsl:attribute name="distance" select="@distance"/>
  159. <xsl:attribute name="id_path" select="@id_path"/>
  160. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  161. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  162. </bp:Path_Point>
  163. </xsl:for-each>
  164. </xsl:for-each>
  165. </PointMatrixGroupPE>
  166. <!--<PointMatrix>
  167. <xsl:attribute name="bit_max" select="$bit_max"/>
  168. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  169. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  170. <!-\-<xsl:call-template name="PE_wariant">
  171. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  172. <xsl:with-param name="bit_max" select="$bit_max"/>
  173. </xsl:call-template>-\->
  174. </PointMatrix>-->
  175. </Path>
  176. </xsl:template>
  177. </xsl:stylesheet>