edge_paths_with_PE_controll.xsl 41 KB

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