edge_paths_with_PE_controll.xsl 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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="2500"/>
  11. <xsl:param name="Cable_Price" select="3"/>
  12. <xsl:param name="max_combinate_groups_elements" select="10"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
  13. <xsl:param name="logic" select="'grouped'"/> <!-- tutaj robi grupy po $max_combinate_groups_elements -->
  14. <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
  15. <xsl:param name="debug"/>
  16. <xsl:param name="edge_paths_with_PE.xml"/>
  17. <xsl:param name="edge_paths_with_PE_controll_temp" select="'edge_paths_with_PE_controll_temp'"/> <!-- cache do przekazywani danych z petli-->
  18. <xsl:param name="edge_paths_with_PE_controll_temp.alias" select="'edge_paths_with_PE_controll_temp.alias'" />
  19. <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
  20. <xsl:template match="edge_joins_filled_paths_xml"><!-- w przypadku wyzwolenia dla pojedynczego pliku -->
  21. <xsl:message>Running script for params:
  22. PE_Price=<xsl:value-of select="$PE_Price"/>
  23. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  24. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  25. logic=<xsl:value-of select="$logic"/> .EOF
  26. </xsl:message>
  27. <edge_paths_with_PE_controll>
  28. <xsl:attribute name="logic" select="$logic"/>
  29. <!-- <xsl:attribute name="id" select="@id"/>
  30. <xsl:attribute name="len" select="@len"/>
  31. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>-->
  32. <xsl:apply-templates mode="PointMatrixGroup">
  33. <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()-->
  34. </xsl:apply-templates>
  35. </edge_paths_with_PE_controll>
  36. </xsl:template>
  37. <xsl:template match="edge_joins_filled_paths">
  38. <xsl:message>Running script for params:
  39. PE_Price=<xsl:value-of select="$PE_Price"/>
  40. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  41. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  42. logic=<xsl:value-of select="$logic"/> .EOF
  43. </xsl:message>
  44. <xsl:variable name="edge_joins_filled_paths_len">
  45. <xsl:for-each select="item">
  46. <xsl:sort select="number(asText/@len)" order="descending"/>
  47. <Path>
  48. <xsl:attribute name="id" select="@id"/>
  49. <xsl:attribute name="len" select="asText/@len"/>
  50. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  51. </Path>
  52. </xsl:for-each>
  53. </xsl:variable>
  54. <edge_paths_with_PE_controll>
  55. <xsl:attribute name="logic" select="$logic"/>
  56. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  57. </edge_paths_with_PE_controll>
  58. <!--<xsl:result-document href="edge_paths_with_PE.xml">
  59. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  60. </xsl:result-document>-->
  61. </xsl:template>
  62. <xsl:template match="Path|asText_XMl" mode="PointMatrixGroup">
  63. <xsl:param name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
  64. <Path>
  65. <xsl:attribute name="id" select="@id"/>
  66. <xsl:variable name="ID_Way" select="@id"/>
  67. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  68. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  69. <xsl:attribute name="len" select="@len"/>
  70. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  71. <xsl:variable name="len" select="@len"/>
  72. <xsl:message> Path dla ID_Way=<xsl:value-of select="$ID_Way"/>; len=<xsl:value-of select="@len"/>; Count=<xsl:value-of select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  73. Points_cnt=<xsl:value-of select="@Points_cnt"/>
  74. </xsl:message>
  75. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  76. <!--<EdgeWayJoinsPair>
  77. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  78. </EdgeWayJoinsPair>-->
  79. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  80. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  81. <xsl:variable name="EconomicDistanceCut">
  82. <EconomicDistanceCut>
  83. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString">
  84. <distance>
  85. <xsl:attribute name="pos" select="position()"/>
  86. <xsl:attribute name="not_id" select="@not_id"/>
  87. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  88. <xsl:attribute name="len" select="@len"/>
  89. <xsl:attribute name="id_path" select="@id_path"/>
  90. <xsl:variable name="Points" select="count(Points)"/>
  91. <xsl:attribute name="Points" select="$Points"/>
  92. <xsl:variable name="Ways" select="count(Ways)"/>
  93. <xsl:attribute name="Ways_count" select="$Ways"/>
  94. <xsl:choose>
  95. <xsl:when test="$Ways or $Points">
  96. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  97. <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  98. </xsl:when>
  99. <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
  100. <xsl:attribute name="point_count" select="0"/>
  101. </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  102. </xsl:choose>
  103. </distance>
  104. </xsl:for-each>
  105. </EconomicDistanceCut>
  106. </xsl:variable>
  107. <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
  108. <xsl:variable name="EconomicDistanceCut2">
  109. <EconomicDistanceCut2>
  110. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  111. <distance2>
  112. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  113. <xsl:copy-of select="@ID_Join"/>
  114. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  115. <xsl:choose>
  116. <xsl:when test="number(@point_count)&gt;0">
  117. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  118. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  119. ]/@pos)"/>
  120. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  121. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  122. number(@pos )&lt; number(current()/@pos )
  123. and number(@pos) &gt;= number($max_pos_z_pkt)
  124. ]/@len)"/>
  125. <xsl:attribute name="disttopkt" select="$disttopkt" />
  126. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * number(@point_count)"/>
  127. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  128. <xsl:attribute name="point_count" select="@point_count"/>
  129. <xsl:attribute name="Ways_count" select="@Ways_count"/>
  130. <xsl:choose> <!-- to powinno przeciac grupe ale moze nie? -->
  131. <xsl:when test="$cost_dist &gt; $PE_Price">
  132. <xsl:attribute name="cut_by_pe" select="1"/>
  133. </xsl:when>
  134. <xsl:otherwise><xsl:attribute name="cut_by_pe" select="0"/></xsl:otherwise>
  135. </xsl:choose>
  136. <xsl:attribute name="not_id" select="@not_id"/> <!-- to jest z ID way - way ma 2 pointsy! -->
  137. </xsl:when>
  138. <xsl:otherwise>
  139. <xsl:choose>
  140. <xsl:when test="number(@Ways_count)&gt;0">
  141. <xsl:attribute name="point_count" select="@Ways_count"/>
  142. </xsl:when>
  143. <xsl:otherwise><xsl:attribute name="point_count" select="0"/></xsl:otherwise>
  144. </xsl:choose>
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. <xsl:attribute name="id_path" select="@id_path"/>
  148. <xsl:copy-of select="@point_count"/>
  149. <xsl:copy-of select="@pos"/><!-- position() -->
  150. <xsl:copy-of select="@len"/>
  151. <xsl:copy-of select="@ForceCutByPrice"/>
  152. <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
  153. </distance2>
  154. </xsl:for-each>
  155. </EconomicDistanceCut2>
  156. </xsl:variable>
  157. <xsl:copy-of select="$EconomicDistanceCut"/>
  158. <xsl:variable name="EconomicDistanceCut2">
  159. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  160. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  161. <distance2>
  162. <xsl:copy-of select="@*"/>
  163. <xsl:choose>
  164. <xsl:when test=" position() mod $max_combinate_groups_elements = 0"> <!--- minus puste sum($EconomicDistanceCut/EconomicDistanceCut/distance[ number(@pos) &lt; number(current()/@pos) ]/number(@NotPoints)) ) --><!-- nabija grupe do przeliczenia-->
  165. <xsl:attribute name="PosCut3Flag" select="1"/>
  166. </xsl:when>
  167. <xsl:otherwise>
  168. <xsl:attribute name="PosCut3Flag" select="0"/>
  169. </xsl:otherwise>
  170. </xsl:choose>
  171. </distance2>
  172. </xsl:for-each>
  173. </EconomicDistanceCut2>
  174. </xsl:variable>
  175. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  176. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  177. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  178. <distance2>
  179. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  180. <xsl:copy-of select="@*"/>
  181. </distance2>
  182. </xsl:for-each>
  183. </EconomicDistanceCut2>
  184. </xsl:variable>
  185. <!-- debug -->
  186. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  187. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  188. <distance2>
  189. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  190. <xsl:copy-of select="@PosCut3GrId"/>
  191. <xsl:copy-of select="@CurSumNotPoints"/>
  192. <xsl:copy-of select="@NotPoints"/>
  193. <!-\-<xsl:copy-of select="@pos"/>-\->
  194. </distance2>
  195. </xsl:for-each>
  196. </EconomicDistanceCut2>-->
  197. <!-- debug -->
  198. <!--<debug>
  199. <xsl:copy-of select="$EconomicDistanceCut2"/>
  200. </debug>-->
  201. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  202. <!--<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-->
  203. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  204. <xsl:variable name="PointMatrixGroup">
  205. <PointMatrixGroup>
  206. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  207. <PointMatrixGroupPos>
  208. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  209. <xsl:variable name="countGr" select="count(current-group())"/>
  210. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  211. <xsl:message>Nowa grupa Ways:<xsl:value-of select="@PosCut3GrId"/>; distanceGr=<xsl:value-of select="@PosCut3GrId"/>;elements_cnt_Pos=<xsl:value-of select="$elements_cnt_Pos"/>; @bit_max_Pos=<xsl:value-of select="$bit_max_Pos"/>; @id_path=<xsl:value-of select="@id_path"/>; countGr=<xsl:value-of select="$countGr"/>; point_count_Pos=<xsl:value-of select="sum(current-group()/@point_count)"/>; len_sum=<xsl:value-of select="sum(current-group()/@len)"/> ; distanceBeg/distanceEnd= <xsl:value-of select="min(current-group()/number(@distance))"/>/<xsl:value-of select="max(current-group()/number(@distance))"/>
  212. </xsl:message>
  213. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  214. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  215. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  216. <xsl:attribute name="id_path" select="@id_path"/>
  217. <xsl:attribute name="point_count_Pos" select="sum(current-group()/@point_count)"/><!-- po przesortowaniu z usunieciem wezlow bez skojarzen przylaczy - jest to nieprawdziwe - rzebaa dodac te dane z poprzednich sciezek itp -->
  218. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  219. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  220. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  221. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  222. <xsl:attribute name="countGr" select="$countGr"/>
  223. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  224. <xsl:for-each select="current-group()">
  225. <distance2>
  226. <xsl:attribute name="PosMatrGroup" select="position()"/>
  227. <xsl:copy-of select="@*"></xsl:copy-of>
  228. </distance2>
  229. </xsl:for-each>
  230. </PointMatrixGroupPos>
  231. </xsl:for-each-group>
  232. </PointMatrixGroup>
  233. </xsl:variable>
  234. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  235. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  236. -->
  237. <!-- debug -->
  238. <!--<xsl:copy-of select="$PointMatrixGroup"/>-->
  239. <PointMatrixGroupPE>
  240. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  241. <xsl:for-each select="PointMatrixGroupPos">
  242. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  243. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  244. <xsl:variable name="distanceGr" select="@distanceGr"/>
  245. <PointMatrixGroup>
  246. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  247. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  248. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  249. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  250. <xsl:attribute name="len_sum" select="@len_sum"/>
  251. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  252. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  253. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  254. <xsl:message>#239: calc @distanceGr=<xsl:value-of select="$distanceGr"/>; @point_count_Pos=<xsl:value-of select="@point_count_Pos"/>;@LineStringCount ; @len_sum=<xsl:value-of select="@len_sum"/>; @distanceBeg=<xsl:value-of select="@distanceBeg"/>; @distanceEnd=<xsl:value-of select="@distanceEnd"/>;
  255. </xsl:message>
  256. <!-- ida kandydaci -->
  257. <xsl:variable name="candidates">
  258. <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 -->
  259. <xsl:sort select="@cost_dist" order="descending"/>
  260. <bp:Path_Point>
  261. <xsl:copy-of select="@ID_Join"/>
  262. <xsl:attribute name="DebugPosPoint" select="position()"/>
  263. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  264. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  265. <xsl:attribute name="pos" select="@pos"/>
  266. <xsl:attribute name="len" select="@len"/>
  267. <xsl:attribute name="distance" select="@distance"/>
  268. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  269. <xsl:attribute name="id_path" select="@id_path"/>
  270. <xsl:attribute name="point_count" select="@point_count"/>
  271. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  272. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  273. </bp:Path_Point>
  274. </xsl:for-each>
  275. </xsl:variable>
  276. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  277. $last = A
  278. - najprosciej przez pliki oszukujac silnik xsl
  279. - tozsamowsci $ID_Way $distanceGr
  280. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  281. -->
  282. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  283. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  284. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  285. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  286. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  287. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  288. </xsl:if>
  289. </xsl:variable>
  290. <!--<poprzednie_odpalam_liczenie_or_nie>
  291. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  292. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  293. </poprzednie_odpalam_liczenie_or_nie>-->
  294. <xsl:variable name="odpalam_liczenie_or_nie">
  295. <xsl:choose>
  296. <xsl:when test="count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1">
  297. <xsl:variable name="max_bit">
  298. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  299. </xsl:variable>
  300. <odpalam_liczenie>
  301. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  302. <xsl:call-template name="calculate_optimum">
  303. <xsl:with-param name="candidates" select="$candidates"/>
  304. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  305. <xsl:with-param name="max_bit" select="$max_bit"/>
  306. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  307. </xsl:call-template>
  308. </odpalam_liczenie>
  309. </xsl:when>
  310. <xsl:otherwise>
  311. <xsl:for-each select="$candidates/bp:Path_Point">
  312. <bp:Path_Point>
  313. <xsl:copy-of select="@*"/>
  314. <xsl:attribute name="bin_pos" select="1"/>
  315. </bp:Path_Point>
  316. </xsl:for-each>
  317. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  318. </xsl:otherwise>
  319. </xsl:choose>
  320. </xsl:variable>
  321. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  322. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  323. <poprzednie_odpalam_liczenie_or_nie>
  324. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  325. <xsl:if test="position() = last()">
  326. <xsl:copy-of select="."/>
  327. </xsl:if>
  328. </xsl:for-each>
  329. <nizej_zwykly></nizej_zwykly>
  330. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  331. <xsl:if test="position() = last()">
  332. <xsl:copy-of select="."/>
  333. </xsl:if>
  334. </xsl:for-each>
  335. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  336. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  337. </poprzednie_odpalam_liczenie_or_nie>
  338. </xsl:result-document>
  339. </PointMatrixGroup>
  340. </xsl:for-each>
  341. </xsl:for-each>
  342. </PointMatrixGroupPE>
  343. <!--<PointMatrix>
  344. <xsl:attribute name="bit_max" select="$bit_max"/>
  345. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  346. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  347. <!-\-<xsl:call-template name="PE_wariant">
  348. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  349. <xsl:with-param name="bit_max" select="$bit_max"/>
  350. </xsl:call-template>-\->
  351. </PointMatrix>-->
  352. </Path>
  353. </xsl:template>
  354. <xsl:template name="calculate_optimum">
  355. <xsl:param name="candidates" required="yes"/>
  356. <xsl:param name="elements_cnt" required="yes"/>
  357. <xsl:param name="variant" select="1"/>
  358. <xsl:param name="max_bit" required="yes"/>
  359. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  360. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  361. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  362. <xsl:variable name="cand_to_calc">
  363. <xsl:for-each select="$candidates/bp:Path_Point">
  364. <xsl:sort select="@distance"/>
  365. <bp:Path_Point>
  366. <!--<xsl:attribute name="bit" select="$bit"/>-->
  367. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  368. <xsl:copy-of select="@*"/>
  369. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  370. </bp:Path_Point>
  371. </xsl:for-each>
  372. </xsl:variable>
  373. <!-- debug -->
  374. <xsl:if test="$debug">
  375. <variant><xsl:attribute name="variant" select="$variant"/>
  376. <xsl:attribute name="cur_bit" select="$bit"/>
  377. <xsl:attribute name="best_cost" select="$best_cost"/>
  378. <xsl:attribute name="best_variant" select="$best_variant"/>
  379. <xsl:copy-of select="$cand_to_calc"/>
  380. </variant>
  381. </xsl:if>
  382. <xsl:variable name="calc_cost_way">
  383. <xsl:call-template name="calc_cost_way">
  384. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  385. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  386. </xsl:call-template>
  387. </xsl:variable>
  388. <xsl:variable name="cost_sum">
  389. <costs>
  390. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  391. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  392. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  393. <xsl:copy-of select="$calc_cost_way"/>
  394. </costs>
  395. </xsl:variable>
  396. <xsl:if test="$debug"><xsl:copy-of select="$cost_sum"/></xsl:if>
  397. <xsl:variable name="best">
  398. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  399. <xsl:choose>
  400. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  401. <best>
  402. <xsl:attribute name="best_cost" select="$cur_Price"/>
  403. <xsl:attribute name="best_variant" select="$bit"/>
  404. </best>
  405. </xsl:when>
  406. <xsl:otherwise>
  407. <best>
  408. <xsl:attribute name="best_cost" select="$best_cost"/>
  409. <xsl:attribute name="best_variant" select="$best_variant"/>
  410. </best>
  411. </xsl:otherwise>
  412. </xsl:choose>
  413. </xsl:variable>
  414. <xsl:if test="$debug"><xsl:copy-of select="$best"/></xsl:if>
  415. <xsl:choose>
  416. <xsl:when test="$bit = $max_bit">
  417. <koniec_wariantow>
  418. <xsl:message>#410 OK - przeliczony wariant bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  419. <xsl:attribute name="best_variant" select="$best_variant"/>
  420. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  421. <xsl:variable name="cand_to_calc_best">
  422. <xsl:for-each select="$candidates/bp:Path_Point">
  423. <xsl:sort select="@distance"/>
  424. <bp:Path_Point>
  425. <!--<xsl:attribute name="bit" select="$bit"/>-->
  426. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  427. <xsl:copy-of select="@*"/>
  428. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  429. </bp:Path_Point>
  430. </xsl:for-each>
  431. </xsl:variable>
  432. <xsl:variable name="show_cables">
  433. <xsl:call-template name="calc_cost_way">
  434. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  435. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  436. <xsl:with-param name="show_cables" select="1"/>
  437. </xsl:call-template>
  438. </xsl:variable>
  439. <xsl:for-each select="$candidates/bp:Path_Point">
  440. <xsl:sort select="@distance"/>
  441. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  442. <bp:Path_Point>
  443. <xsl:attribute name="bit" select="$best_variant"/>
  444. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  445. <xsl:copy-of select="@*"/>
  446. <xsl:attribute name="Price" select="$best_cost"/>
  447. <xsl:copy-of select="bp:Path_Point"/>
  448. </bp:Path_Point>
  449. </xsl:if>
  450. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  451. <bp:Path_Point_Cable>
  452. <xsl:attribute name="bit" select="$best_variant"/>
  453. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  454. <xsl:copy-of select="@*"/>
  455. <xsl:attribute name="Price" select="$best_cost"/>
  456. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  457. <!-- todo do jakiego Join zostal przybity -->
  458. <xsl:copy-of select="bp:Path_Point"/>
  459. <!--<xsl:if test="$debug">
  460. <debug_show_cables>
  461. <xsl:copy-of select="$show_cables"></xsl:copy-of>
  462. </debug_show_cables>
  463. </xsl:if>-->
  464. </bp:Path_Point_Cable>
  465. </xsl:if>
  466. </xsl:for-each>
  467. </koniec_wariantow>
  468. </xsl:when>
  469. <xsl:otherwise>
  470. <xsl:call-template name="calculate_optimum">
  471. <xsl:with-param name="candidates" select="$candidates"/>
  472. <xsl:with-param name="max_bit" select="$max_bit"/>
  473. <xsl:with-param name="variant" select="$variant + 1"/>
  474. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  475. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  476. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  477. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  478. </xsl:call-template>
  479. </xsl:otherwise>
  480. </xsl:choose>
  481. </xsl:template>
  482. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  483. <xsl:param name="cand_to_calc" required="yes"/>
  484. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  485. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  486. <xsl:variable name="candidates_merged_with_poprzednie">
  487. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/*">
  488. <bp:Path_Point>
  489. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  490. <xsl:copy-of select="@*"/>
  491. </bp:Path_Point>
  492. </xsl:for-each>
  493. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  494. <bp:Path_Point>
  495. <xsl:copy-of select="@*"/>
  496. </bp:Path_Point>
  497. </xsl:for-each>
  498. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  499. </xsl:variable>
  500. <xsl:if test="$debug">
  501. <candidates_merged_with_poprzednie>
  502. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  503. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  504. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  505. </candidates_merged_with_poprzednie>
  506. </xsl:if>
  507. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  508. <xsl:choose>
  509. <xsl:when test="@poprzednia_grupa">
  510. <cost>
  511. <xsl:attribute name="Cable_Price" select="0"/>
  512. <xsl:attribute name="PE_Price" select="0"/>
  513. <xsl:attribute name="Price" select="0"/>
  514. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  515. </cost>
  516. </xsl:when>
  517. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  518. <xsl:variable name="way_up_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and @id_path &lt; current()/@id_path ]/number(@ID_Join))"/>
  519. <xsl:variable name="way_up_len" >
  520. <xsl:choose>
  521. <xsl:when test="$way_up_id">
  522. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/></xsl:when>
  523. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  524. </xsl:choose>
  525. </xsl:variable>
  526. <xsl:variable name="way_dn_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and @id_path &gt; current()/@id_path ]/number(@ID_Join)) " />
  527. <xsl:variable name="way_dn_len">
  528. <xsl:choose>
  529. <xsl:when test="$way_dn_id">
  530. <xsl:value-of select=" number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/@distance"/>
  531. </xsl:when>
  532. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  533. </xsl:choose>
  534. </xsl:variable>
  535. <xsl:choose><!-- czy w gore czy w dol -->
  536. <xsl:when test=" number($way_up_len) &gt;= number($way_dn_len) and number($way_dn_len) &gt; 0 or $way_up_len=-1"> <!--and not($way_dn_len='NaN') -->
  537. <cost>
  538. <xsl:variable name="Cable_Price_sum">
  539. <xsl:choose>
  540. <xsl:when test="number(@point_count) &gt; 0 ">
  541. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  542. </xsl:when>
  543. <xsl:otherwise>
  544. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  545. </xsl:otherwise>
  546. </xsl:choose>
  547. </xsl:variable>
  548. <!-- todo @point_count -->
  549. <xsl:if test="$show_cables">
  550. <xsl:attribute name="choosed" select="'down'"/>
  551. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  552. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  553. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  554. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  555. <xsl:attribute name="PE_Price" select="0"/>
  556. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  557. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  558. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  559. </xsl:if>
  560. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  561. </cost>
  562. </xsl:when>
  563. <xsl:otherwise>
  564. <cost>
  565. <xsl:variable name="Cable_Price_sum">
  566. <xsl:choose>
  567. <xsl:when test="number(@point_count) &gt; 0 ">
  568. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  569. </xsl:when>
  570. <xsl:otherwise>
  571. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  572. </xsl:otherwise>
  573. </xsl:choose>
  574. </xsl:variable>
  575. <xsl:if test="$show_cables">
  576. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  577. <xsl:attribute name="PE_Price" select="0"/>
  578. <xsl:attribute name="choosed" select="'up'"/>
  579. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  580. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  581. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  582. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  583. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  584. </xsl:if>
  585. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  586. </cost>
  587. </xsl:otherwise>
  588. </xsl:choose>
  589. </xsl:when>
  590. <xsl:otherwise>
  591. <cost>
  592. <xsl:attribute name="Cable_Price" select="0"/>
  593. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  594. <xsl:attribute name="Price" select="$PE_Price"/>
  595. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  596. </cost>
  597. </xsl:otherwise>
  598. </xsl:choose>
  599. </xsl:for-each>
  600. </xsl:template>
  601. </xsl:stylesheet>