edge_paths_with_PE_controll.xsl 38 KB

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