edge_paths_with_PE_controll.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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="@Count"/>
  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="PointMatrixGroupPE" mode="edge_paths_with_PE.xml">
  51. <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
  52. </xsl:template>
  53. <xsl:template match="PointMatrixGroup" mode="edge_paths_with_PE.xml">
  54. <!--<test_matrux><xsl:copy-of select="."></xsl:copy-of></test_matrux>-->
  55. <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
  56. </xsl:template>
  57. <xsl:template match="bp:Path_Point" mode="edge_paths_with_PE.xml">
  58. <xsl:copy-of select="."/>
  59. </xsl:template>
  60. <xsl:template match="Path" mode="PointMatrixGroup">
  61. <Path>
  62. <xsl:variable name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
  63. <xsl:attribute name="id" select="@id"/>
  64. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  65. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  66. <xsl:attribute name="len" select="@len"/>
  67. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  68. <xsl:variable name="len" select="@len"/>
  69. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  70. <!--<EdgeWayJoinsPair>
  71. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  72. </EdgeWayJoinsPair>-->
  73. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  74. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  75. <xsl:variable name="EconomicDistanceCut">
  76. <EconomicDistanceCut>
  77. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString">
  78. <distance>
  79. <xsl:attribute name="pos" select="position()"/>
  80. <xsl:attribute name="not_id" select="@not_id"/>
  81. <xsl:attribute name="len" select="@len"/>
  82. <xsl:attribute name="id_path" select="@id_path"/>
  83. <xsl:attribute name="Points" select="count(Points)"/>
  84. <xsl:variable name="Points" select="count(Points)"/>
  85. <xsl:variable name="Ways" select="count(Ways)"/>
  86. <xsl:choose>
  87. <xsl:when test="$Ways or $Points">
  88. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  89. </xsl:when>
  90. </xsl:choose>
  91. </distance>
  92. </xsl:for-each>
  93. </EconomicDistanceCut>
  94. </xsl:variable>
  95. <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
  96. <xsl:variable name="EconomicDistanceCut2">
  97. <EconomicDistanceCut2>
  98. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  99. <distance2>
  100. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  101. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  102. <xsl:choose>
  103. <xsl:when test="@point_count&gt;0">
  104. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  105. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  106. ]/@pos)"/>
  107. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  108. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  109. number(@pos )&lt; number(current()/@pos )
  110. and number(@pos) &gt;= number($max_pos_z_pkt)
  111. ]/@len)"/>
  112. <xsl:attribute name="disttopkt" select="$disttopkt" />
  113. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * @point_count"/>
  114. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  115. <xsl:attribute name="point_count" select="@point_count"/>
  116. <xsl:if test="$cost_dist &gt; $PE_Price">
  117. <xsl:attribute name="cut_by_pe" select="1"/>
  118. </xsl:if>
  119. <xsl:attribute name="not_id" select="@not_id"/>
  120. </xsl:when>
  121. </xsl:choose>
  122. <xsl:attribute name="id_path" select="@id_path"/>
  123. <xsl:copy-of select="@point_count"/>
  124. <xsl:copy-of select="@pos"/>
  125. <xsl:copy-of select="@len"/>
  126. </distance2>
  127. </xsl:for-each>
  128. </EconomicDistanceCut2>
  129. </xsl:variable>
  130. <xsl:copy-of select="$EconomicDistanceCut2"/>
  131. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  132. <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-->
  133. <!-- pogrupujemy elementy co 50 metrow -->
  134. <xsl:variable name="PointMatrixGroup">
  135. <PointMatrixGroup>
  136. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="round( @distance div ( $PE_Price div $Cable_Price + 50 ))">
  137. <PointMatrixGroupPos>
  138. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  139. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  140. <xsl:attribute name="distanceGr" select=" current-grouping-key()"/>
  141. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  142. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  143. <xsl:attribute name="id_path" select="@id_path"/>
  144. <xsl:attribute name="point_count_Pos" select="sum(current-group()/@point_count)"/>
  145. <xsl:attribute name="point_count" select="@point_count"/>
  146. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  147. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  148. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  149. <xsl:for-each select="current-group()">
  150. <xsl:copy-of select="."/>
  151. </xsl:for-each>
  152. </PointMatrixGroupPos>
  153. </xsl:for-each-group>
  154. </PointMatrixGroup>
  155. </xsl:variable>
  156. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  157. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  158. -->
  159. <!-- debug -->
  160. <xsl:copy-of select="$PointMatrixGroup"/>
  161. <PointMatrixGroupPE>
  162. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  163. <xsl:for-each select="PointMatrixGroupPos">
  164. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  165. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  166. <xsl:variable name="distanceGr" select="@distanceGr"/>
  167. <PointMatrixGroup>
  168. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/><xsl:attribute name="point_count_Pos" select="$point_count_Pos"/><xsl:attribute name="distanceGr" select="$distanceGr"/>
  169. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  170. <xsl:attribute name="len_sum" select="@len_sum"/>
  171. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  172. <!-- ida kandydaci -->
  173. <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 -->
  174. <xsl:sort select="@cost_dist" order="descending"/>
  175. <bp:Path_Point>
  176. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  177. <xsl:attribute name="pos" select="@pos"/>
  178. <xsl:attribute name="len" select="@len"/>
  179. <xsl:attribute name="distance" select="@distance"/>
  180. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  181. <xsl:attribute name="id_path" select="@id_path"/>
  182. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  183. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  184. </bp:Path_Point>
  185. </xsl:for-each>
  186. </PointMatrixGroup>
  187. </xsl:for-each>
  188. </xsl:for-each>
  189. </PointMatrixGroupPE>
  190. <!--<PointMatrix>
  191. <xsl:attribute name="bit_max" select="$bit_max"/>
  192. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  193. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  194. <!-\-<xsl:call-template name="PE_wariant">
  195. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  196. <xsl:with-param name="bit_max" select="$bit_max"/>
  197. </xsl:call-template>-\->
  198. </PointMatrix>-->
  199. </Path>
  200. </xsl:template>
  201. </xsl:stylesheet>