edge_paths_with_PE_controll.xsl 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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="8"/> <!-- 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" select="1"/>
  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. <xsl:param name="edge_paths_with_PE_controll_paths_temp" select="'edge_paths_with_PE_controll_paths_temp'"/> <!-- do przechowywania calych sciezek do PathCrossed-->
  20. <xsl:param name="edge_joins_filled_paths" select="'edge_joins_filled_paths'"/>
  21. <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
  22. <xsl:template match="edge_joins_filled_paths_xml"><!-- w przypadku wyzwolenia dla pojedynczego pliku -->
  23. <xsl:message>Running script for params:
  24. PE_Price=<xsl:value-of select="$PE_Price"/>
  25. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  26. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  27. logic=<xsl:value-of select="$logic"/> .EOF
  28. </xsl:message>
  29. <edge_paths_with_PE_controll>
  30. <xsl:attribute name="logic" select="$logic"/>
  31. <!-- <xsl:attribute name="id" select="@id"/>
  32. <xsl:attribute name="len" select="@len"/>
  33. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>-->
  34. <xsl:apply-templates mode="PointMatrixGroup">
  35. <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()-->
  36. </xsl:apply-templates>
  37. </edge_paths_with_PE_controll>
  38. </xsl:template>
  39. <xsl:template match="edge_joins_filled_paths">
  40. <xsl:message>Running script for params:
  41. PE_Price=<xsl:value-of select="$PE_Price"/>
  42. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  43. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  44. logic=<xsl:value-of select="$logic"/> .EOF
  45. </xsl:message>
  46. <xsl:variable name="edge_joins_filled_paths_len">
  47. <xsl:for-each select="item">
  48. <xsl:sort select="number(asText/@len)" order="descending"/>
  49. <Path>
  50. <xsl:attribute name="id" select="@id"/>
  51. <xsl:attribute name="len" select="asText/@len"/>
  52. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  53. </Path>
  54. </xsl:for-each>
  55. </xsl:variable>
  56. <edge_paths_with_PE_controll>
  57. <xsl:attribute name="logic" select="$logic"/>
  58. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  59. </edge_paths_with_PE_controll>
  60. <!--<xsl:result-document href="edge_paths_with_PE.xml">
  61. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  62. </xsl:result-document>-->
  63. </xsl:template>
  64. <xsl:template match="Path|asText_XMl" mode="PointMatrixGroup">
  65. <xsl:param name="edge_joins_filled_path" select=" doc(concat($edge_joins_filled_paths,'/edge_joins_filled_paths.',@id,'.xml'))"/>
  66. <Path>
  67. <xsl:attribute name="id" select="@id"/>
  68. <xsl:variable name="ID_Way" select="@id"/>
  69. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  70. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  71. <xsl:attribute name="len" select="@len"/>
  72. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  73. <xsl:variable name="len" select="@len"/>
  74. <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)"/>
  75. Points_cnt=<xsl:value-of select="@Points_cnt"/>
  76. </xsl:message>
  77. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  78. <EdgeWayJoinsPair>
  79. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  80. </EdgeWayJoinsPair>
  81. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  82. <!-- sciagamy dane drog, z ktorymi sie przecinamy -->
  83. <xsl:variable name="PathsCrossed">
  84. <PathsCrossed>
  85. <xsl:for-each-group select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString/Ways" group-by="@ID_WAY">
  86. <Ways>
  87. <xsl:variable name="ID_WAY_joining" select="@ID_WAY"/>
  88. <xsl:attribute name="ID_WAY" select="$ID_WAY_joining"/>
  89. <xsl:variable name="ways_id_joining" select="@ways_id"/>
  90. <xsl:attribute name="ways_id_joining" select="$ways_id_joining"/>
  91. <xsl:variable name="ID_Join_joining" select="parent::node()/@ID_Join"/>
  92. <xsl:attribute name="ID_Join_joining" select="$ID_Join_joining"/>
  93. <xsl:choose>
  94. <xsl:when test="doc-available(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))">
  95. <xsl:variable name="Neigh_controll">
  96. <xsl:copy-of select="doc(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))"/>
  97. </xsl:variable>
  98. <!-- wykryc gdzie sie lacza i jakie sa odleglosci prawdziwe -->
  99. <!-- jak nasza droga sie laczy do przeciwnej? ktory nasz Way w nim siedzi -->
  100. <!-- zignorowac wezel zwiazany z podlaczonym tam joinem -->
  101. <!-- <IgnoreLocaldistance>
  102. <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
  103. </IgnoreLocaldistance>
  104. <IgnoreLocaldistance>
  105. <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
  106. </IgnoreLocaldistance>-->
  107. <!--<xsl:for-each select="$Neigh_controll/edge_paths_with_PE_controll/Path/PointMatrixGroupPE/PointMatrixGroup/odpalam_liczenie/(bp:Path_Point|bp:Path_Point_Cable)">
  108. <xsl:copy-of select="."/>
  109. </xsl:for-each>-->
  110. <xsl:apply-templates mode="PathsCrossed" select="$Neigh_controll"/>
  111. </xsl:when>
  112. <xsl:otherwise>
  113. <xsl:message> WARNING path should be analyzed and aviable in:<xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></xsl:message>
  114. <Warning> WARNING path should be analyzed and aviable in: <xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></Warning>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. </Ways>
  118. </xsl:for-each-group>
  119. </PathsCrossed>
  120. </xsl:variable>
  121. <xsl:copy-of select="$PathsCrossed"/>
  122. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  123. <xsl:variable name="EconomicDistanceCut">
  124. <EconomicDistanceCut>
  125. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[not(@error)]">
  126. <distance>
  127. <xsl:attribute name="pos" select="position()"/>
  128. <xsl:attribute name="not_id" select="@not_id"/>
  129. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  130. <xsl:attribute name="len" select="@len"/>
  131. <xsl:attribute name="id_path" select="@id_path"/>
  132. <xsl:variable name="Points" select="count(Points)"/>
  133. <xsl:attribute name="Points" select="$Points"/>
  134. <xsl:variable name="Ways" select="count(Ways)"/>
  135. <xsl:attribute name="Ways_count" select="$Ways"/>
  136. <xsl:choose>
  137. <xsl:when test="$Ways or $Points">
  138. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  139. <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  140. <xsl:if test="Ways">
  141. <!-- sprawdzamy jak sie dowiazuje i ile ma do najblizszego wezla -->
  142. <xsl:for-each-group select="Ways" group-by="@ID_WAY">
  143. <PathsCrossed>
  144. <xsl:attribute name="ID_WAY" select="@ID_WAY"/><xsl:attribute name="debug" select="'created at #163 by parsing Ways'"/>
  145. <xsl:variable name="Joining_ID_Join_from" select="parent::node()/@ID_Join"/>
  146. <xsl:choose>
  147. <xsl:when test="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos">
  148. <xsl:variable name="NeighJoin_pos" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos"/>
  149. <xsl:variable name="NeighJoin_pos_distance" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@pos= $NeighJoin_pos]/@distance)"/>
  150. <xsl:attribute name="NeighJoin_pos" select="$NeighJoin_pos"/>
  151. <!--<xsl:attribute name="NeighJoin_pos_distance" select="$NeighJoin_pos_distance"/>-->
  152. <xsl:attribute name="Deb_Cur_ID_WAY" select="@ID_WAY"/>
  153. <xsl:attribute name="Joining_ID_Join_from" select="$Joining_ID_Join_from"/>
  154. <!-- chk w gore -->
  155. <xsl:variable name="NeighJoin_way_up_pos" select="max($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos) &lt; number($NeighJoin_pos) ] /@pos)"/>
  156. <xsl:choose>
  157. <xsl:when test="$NeighJoin_way_up_pos">
  158. <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
  159. <xsl:variable name="NeighJoin_way_up_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@ID_Join" />
  160. <xsl:variable name="NeighJoin_way_up_len" select="number($NeighJoin_pos_distance) - number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@distance) "/>
  161. <xsl:attribute name="NeighJoin_way_up_len" select="$NeighJoin_way_up_len"/>
  162. <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
  163. <xsl:attribute name="NeighJoin_way_up_ID_Join" select="$NeighJoin_way_up_ID_Join"/>
  164. </xsl:when>
  165. <xsl:otherwise>
  166. <xsl:attribute name="NeighJoin_way_up_len" select="-1"/>
  167. </xsl:otherwise>
  168. </xsl:choose>
  169. <xsl:variable name="NeighJoin_way_dn_pos" select="min($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos) &gt; number($NeighJoin_pos) ] /@pos)"/>
  170. <xsl:choose>
  171. <xsl:when test="$NeighJoin_way_dn_pos">
  172. <xsl:variable name="NeighJoin_way_dn_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@ID_Join"/>
  173. <xsl:variable name="NeighJoin_way_dn_len" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@distance) - number($NeighJoin_pos_distance) "/>
  174. <xsl:attribute name="NeighJoin_way_dn_pos" select="$NeighJoin_way_dn_pos"/>
  175. <xsl:attribute name="NeighJoin_way_dn_ID_Join" select="$NeighJoin_way_dn_ID_Join"/>
  176. <xsl:attribute name="NeighJoin_way_dn_len" select="$NeighJoin_way_dn_len"/>
  177. </xsl:when>
  178. <xsl:otherwise>
  179. <xsl:attribute name="NeighJoin_way_dn_len" select="-1"/>
  180. </xsl:otherwise>
  181. </xsl:choose>
  182. <!-- chk w dol -->
  183. <xsl:if test=" number($debug) &gt; 3">
  184. <debug186>
  185. <xsl:copy-of select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]"/>
  186. </debug186>
  187. </xsl:if>
  188. </xsl:when>
  189. <xsl:otherwise>
  190. <xsl:comment>No connection to other roads found</xsl:comment>
  191. </xsl:otherwise>
  192. </xsl:choose>
  193. </PathsCrossed>
  194. </xsl:for-each-group>
  195. </xsl:if>
  196. </xsl:when>
  197. <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
  198. <xsl:attribute name="point_count" select="0"/>
  199. </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  200. </xsl:choose>
  201. </distance>
  202. </xsl:for-each>
  203. </EconomicDistanceCut>
  204. </xsl:variable>
  205. <xsl:if test="$debug">
  206. <debug_174>
  207. <xsl:copy-of select="$EconomicDistanceCut"/>
  208. </debug_174>
  209. </xsl:if>
  210. <xsl:variable name="EconomicDistanceCut2">
  211. <EconomicDistanceCut2>
  212. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  213. <distance2>
  214. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  215. <xsl:copy-of select="@ID_Join"/>
  216. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  217. <xsl:choose>
  218. <xsl:when test="number(@point_count)&gt;0">
  219. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  220. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  221. ]/@pos)"/>
  222. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  223. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  224. number(@pos )&lt; number(current()/@pos )
  225. and number(@pos) &gt;= number($max_pos_z_pkt)
  226. ]/@len)"/>
  227. <xsl:attribute name="disttopkt" select="$disttopkt" />
  228. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * number(@point_count)"/>
  229. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  230. <xsl:attribute name="point_count" select="@point_count"/>
  231. <xsl:attribute name="Ways_count" select="@Ways_count"/>
  232. <xsl:choose> <!-- to powinno przeciac grupe ale moze nie? -->
  233. <xsl:when test="$cost_dist &gt; $PE_Price">
  234. <xsl:attribute name="cut_by_pe" select="1"/>
  235. </xsl:when>
  236. <xsl:otherwise><xsl:attribute name="cut_by_pe" select="0"/></xsl:otherwise>
  237. </xsl:choose>
  238. <xsl:attribute name="not_id" select="@not_id"/> <!-- to jest z ID way - way ma 2 pointsy! -->
  239. </xsl:when>
  240. <xsl:otherwise>
  241. <xsl:choose>
  242. <xsl:when test="number(@Ways_count)&gt;0">
  243. <xsl:attribute name="point_count" select="@Ways_count"/>
  244. </xsl:when>
  245. <xsl:otherwise><xsl:attribute name="point_count" select="0"/></xsl:otherwise>
  246. </xsl:choose>
  247. </xsl:otherwise>
  248. </xsl:choose>
  249. <xsl:attribute name="id_path" select="@id_path"/>
  250. <xsl:copy-of select="@point_count"/>
  251. <xsl:copy-of select="@pos"/><!-- position() -->
  252. <xsl:copy-of select="@len"/>
  253. <xsl:copy-of select="@ForceCutByPrice"/>
  254. <xsl:copy-of select="PathsCrossed"/>
  255. <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
  256. </distance2>
  257. </xsl:for-each>
  258. </EconomicDistanceCut2>
  259. </xsl:variable>
  260. <debug_Cut2_183>
  261. <xsl:copy-of select="$EconomicDistanceCut2"/>
  262. </debug_Cut2_183>
  263. <xsl:variable name="EconomicDistanceCut2">
  264. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  265. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  266. <distance2>
  267. <xsl:copy-of select="@*"/>
  268. <xsl:choose>
  269. <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-->
  270. <xsl:attribute name="PosCut3Flag" select="1"/>
  271. </xsl:when>
  272. <xsl:otherwise>
  273. <xsl:attribute name="PosCut3Flag" select="0"/>
  274. </xsl:otherwise>
  275. </xsl:choose>
  276. <xsl:copy-of select="PathsCrossed"/>
  277. </distance2>
  278. </xsl:for-each>
  279. </EconomicDistanceCut2>
  280. </xsl:variable>
  281. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  282. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  283. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  284. <distance2>
  285. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  286. <xsl:copy-of select="@*"/>
  287. <xsl:copy-of select="PathsCrossed"/>
  288. </distance2>
  289. </xsl:for-each>
  290. </EconomicDistanceCut2>
  291. </xsl:variable>
  292. <!-- debug -->
  293. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  294. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  295. <distance2>
  296. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  297. <xsl:copy-of select="@PosCut3GrId"/>
  298. <xsl:copy-of select="@CurSumNotPoints"/>
  299. <xsl:copy-of select="@NotPoints"/>
  300. <!-\-<xsl:copy-of select="@pos"/>-\->
  301. </distance2>
  302. </xsl:for-each>
  303. </EconomicDistanceCut2>-->
  304. <!-- debug -->
  305. <!--<debug>
  306. <xsl:copy-of select="$EconomicDistanceCut2"/>
  307. </debug>-->
  308. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  309. <!--<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-->
  310. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  311. <xsl:variable name="PointMatrixGroup">
  312. <PointMatrixGroup>
  313. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  314. <PointMatrixGroupPos>
  315. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  316. <xsl:variable name="countGr" select="count(current-group())"/>
  317. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  318. <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))"/>
  319. </xsl:message>
  320. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  321. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  322. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  323. <xsl:attribute name="id_path" select="@id_path"/>
  324. <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 -->
  325. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  326. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  327. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  328. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  329. <xsl:attribute name="countGr" select="$countGr"/>
  330. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  331. <xsl:for-each select="current-group()">
  332. <distance2>
  333. <xsl:attribute name="PosMatrGroup" select="position()"/>
  334. <xsl:copy-of select="@*"></xsl:copy-of>
  335. <xsl:copy-of select="PathsCrossed"/>
  336. </distance2>
  337. </xsl:for-each>
  338. </PointMatrixGroupPos>
  339. </xsl:for-each-group>
  340. </PointMatrixGroup>
  341. </xsl:variable>
  342. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  343. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  344. -->
  345. <!-- debug -->
  346. <xsl:if test="number($debug) &gt; 3">
  347. <debug_356>
  348. <xsl:copy-of select="$PointMatrixGroup"/>
  349. </debug_356>
  350. </xsl:if>
  351. <PointMatrixGroupPE>
  352. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  353. <xsl:for-each select="PointMatrixGroupPos">
  354. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  355. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  356. <xsl:variable name="distanceGr" select="@distanceGr"/>
  357. <PointMatrixGroup>
  358. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  359. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  360. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  361. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  362. <xsl:attribute name="len_sum" select="@len_sum"/>
  363. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  364. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  365. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  366. <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"/>;
  367. </xsl:message>
  368. <!-- ida kandydaci -->
  369. <xsl:variable name="candidates">
  370. <xsl:for-each select="distance2[ @point_count &gt;0 ]"> <!--@point_count &gt;0--> <!-- ( $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' ) --> <!--( 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 -->
  371. <!--<xsl:sort select="@cost_dist" order="descending"/>-->
  372. <bp:Path_Point>
  373. <xsl:copy-of select="@ID_Join"/>
  374. <xsl:attribute name="DebugPosPoint" select="position()"/>
  375. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  376. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  377. <xsl:attribute name="pos" select="@pos"/>
  378. <xsl:attribute name="len" select="@len"/>
  379. <xsl:attribute name="distance" select="@distance"/>
  380. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  381. <xsl:attribute name="id_path" select="@id_path"/>
  382. <xsl:attribute name="point_count" select="@point_count"/>
  383. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  384. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  385. <xsl:copy-of select="PathsCrossed"/>
  386. </bp:Path_Point>
  387. </xsl:for-each>
  388. </xsl:variable>
  389. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  390. $last = A
  391. - najprosciej przez pliki oszukujac silnik xsl
  392. - tozsamowsci $ID_Way $distanceGr
  393. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  394. -->
  395. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  396. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  397. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  398. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  399. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  400. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  401. </xsl:if>
  402. </xsl:variable>
  403. <!--<poprzednie_odpalam_liczenie_or_nie>
  404. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  405. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  406. </poprzednie_odpalam_liczenie_or_nie>-->
  407. <xsl:variable name="odpalam_liczenie_or_nie">
  408. <xsl:choose>
  409. <xsl:when test="1=1"> <!-- bylo count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1-->
  410. <xsl:variable name="max_bit">
  411. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  412. </xsl:variable>
  413. <odpalam_liczenie>
  414. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  415. <!--<disabled>temporary blad after #410 OK - przeliczony wariant bit=000000010000 ( nr 4095;)
  416. [xslt] #239: calc @distanceGr=23; @point_count_Pos=19;@LineStringCount ; @len_sum=177; @distanceBeg=5055; @distanceEnd=5475;
  417. [xslt]
  418. [xslt] /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/edge_paths_with_PE_controll.xsl:571: Fatal Error! Cannot convert string to double: ""
  419. [xslt] Failed to process /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/edge_joins_filled_paths.xml</disabled>-->
  420. <xsl:variable name="IfPathsCrossed" >
  421. <xsl:choose>
  422. <xsl:when test="$candidates/bp:Path_Point/PathsCrossed[@NeighJoin_way_up_ID_Join or @NeighJoin_way_dn_ID_Join]">
  423. <xsl:message>#534 there are PathsCrossed - allow to decrease -1</xsl:message>
  424. <xsl:value-of select="0"/>
  425. </xsl:when>
  426. <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
  427. </xsl:choose>
  428. </xsl:variable>
  429. <xsl:call-template name="calculate_optimum">
  430. <xsl:with-param name="candidates" select="$candidates"/>
  431. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  432. <xsl:with-param name="max_bit" select="$max_bit"/>
  433. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  434. <xsl:with-param name="variant" select="$IfPathsCrossed"/>
  435. </xsl:call-template>
  436. </odpalam_liczenie>
  437. </xsl:when>
  438. <xsl:otherwise>
  439. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  440. <xsl:for-each select="$candidates/bp:Path_Point">
  441. <bp:Path_Point>
  442. <xsl:copy-of select="@*"/>
  443. <xsl:attribute name="bin_pos" select="1"/>
  444. </bp:Path_Point>
  445. </xsl:for-each>
  446. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  447. </xsl:otherwise>
  448. </xsl:choose>
  449. </xsl:variable>
  450. <xsl:if test="number($debug) &gt; 0">
  451. <debug423>
  452. <xsl:attribute name="liczenie_dla"/>
  453. <candidates>
  454. <xsl:copy-of select="$candidates"/>
  455. </candidates>
  456. <poprzednie_odpalam_liczenie_or_nie>
  457. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  458. </poprzednie_odpalam_liczenie_or_nie>
  459. </debug423>
  460. </xsl:if>
  461. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  462. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  463. <poprzednie_odpalam_liczenie_or_nie>
  464. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  465. <xsl:if test="position() = last()">
  466. <xsl:copy-of select="."/>
  467. </xsl:if>
  468. </xsl:for-each>
  469. <nizej_zwykly></nizej_zwykly>
  470. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  471. <xsl:if test="position() = last()">
  472. <xsl:copy-of select="."/>
  473. </xsl:if>
  474. </xsl:for-each>
  475. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  476. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  477. </poprzednie_odpalam_liczenie_or_nie>
  478. </xsl:result-document>
  479. </PointMatrixGroup>
  480. </xsl:for-each>
  481. </xsl:for-each>
  482. </PointMatrixGroupPE>
  483. <!--<PointMatrix>
  484. <xsl:attribute name="bit_max" select="$bit_max"/>
  485. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  486. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  487. <!-\-<xsl:call-template name="PE_wariant">
  488. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  489. <xsl:with-param name="bit_max" select="$bit_max"/>
  490. </xsl:call-template>-\->
  491. </PointMatrix>-->
  492. </Path>
  493. </xsl:template>
  494. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  495. <xsl:apply-templates mode="PathsCrossed"/>
  496. </xsl:template>
  497. <xsl:template match="bp:Path_Point" mode="PathsCrossed"> <!-- nie potrzebujemy kabli ! bp:Path_Point_Cable-->
  498. <xsl:copy-of select="."/>
  499. </xsl:template>
  500. <xsl:template match="*|text()" mode="PathsCrossed"/>
  501. <xsl:template name="calculate_optimum">
  502. <xsl:param name="candidates" required="yes"/>
  503. <xsl:param name="elements_cnt" required="yes"/>
  504. <xsl:param name="variant" select="1"/>
  505. <xsl:param name="max_bit" required="yes"/>
  506. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  507. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  508. <!-- do jednorazowego wyzwolenia przez fukcje, aby tylko raz odjelo wariant zerowy -->
  509. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  510. <xsl:variable name="cand_to_calc">
  511. <xsl:for-each select="$candidates/bp:Path_Point">
  512. <!--<xsl:sort select="number(@distance)"/>-->
  513. <bp:Path_Point>
  514. <!--<xsl:attribute name="bit" select="$bit"/>-->
  515. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  516. <xsl:copy-of select="@*"/>
  517. <!--<xsl:copy-of select="bp:Path_Point"/>-->
  518. <xsl:copy-of select="PathsCrossed"/>
  519. </bp:Path_Point>
  520. </xsl:for-each>
  521. </xsl:variable>
  522. <!-- debug -->
  523. <xsl:if test=" number($debug) &gt; 2">
  524. <variant><xsl:attribute name="variant" select="$variant"/>
  525. <xsl:attribute name="cur_bit" select="$bit"/>
  526. <xsl:attribute name="best_cost" select="$best_cost"/>
  527. <xsl:attribute name="best_variant" select="$best_variant"/>
  528. <xsl:copy-of select="$cand_to_calc"/>
  529. </variant>
  530. </xsl:if>
  531. <xsl:variable name="calc_cost_way">
  532. <xsl:call-template name="calc_cost_way">
  533. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  534. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  535. </xsl:call-template>
  536. </xsl:variable>
  537. <xsl:variable name="cost_sum">
  538. <costs>
  539. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  540. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  541. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  542. <xsl:copy-of select="$calc_cost_way"/>
  543. </costs>
  544. </xsl:variable>
  545. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  546. <xsl:variable name="best">
  547. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  548. <xsl:choose>
  549. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  550. <best>
  551. <xsl:attribute name="best_cost" select="$cur_Price"/>
  552. <xsl:attribute name="best_variant" select="$bit"/>
  553. </best>
  554. </xsl:when>
  555. <xsl:otherwise>
  556. <best>
  557. <xsl:attribute name="best_cost" select="$best_cost"/>
  558. <xsl:attribute name="best_variant" select="$best_variant"/>
  559. </best>
  560. </xsl:otherwise>
  561. </xsl:choose>
  562. </xsl:variable>
  563. <xsl:if test=" number($debug) &gt; 3 ">
  564. <xsl:copy-of select="$best"/>
  565. <xsl:message>#688 (C$<xsl:value-of select="$cost_sum/costs/@Cable_Price"/>+P$<xsl:value-of select="$cost_sum/costs/@PE_Price"/> =<xsl:value-of select="$cost_sum/costs/@Price"/>) v:<xsl:value-of select="$variant"/>; b:<xsl:value-of select="$bit"/>; bestV=<xsl:value-of select="$best_variant"/>; bestC=<xsl:value-of select="$best_cost"/> </xsl:message>
  566. </xsl:if>
  567. <xsl:choose>
  568. <xsl:when test="$bit = $max_bit">
  569. <koniec_wariantow>
  570. <xsl:message>#410 OK - cost:<xsl:value-of select="$best_cost"/>; bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  571. <xsl:attribute name="best_variant" select="$best_variant"/>
  572. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  573. <xsl:variable name="cand_to_calc_best">
  574. <xsl:for-each select="$candidates/bp:Path_Point">
  575. <!--<xsl:sort select="@distance"/>-->
  576. <bp:Path_Point>
  577. <!--<xsl:attribute name="bit" select="$bit"/>-->
  578. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  579. <xsl:copy-of select="@*"/>
  580. <xsl:copy-of select="bp:Path_Point"/>
  581. </bp:Path_Point>
  582. </xsl:for-each>
  583. </xsl:variable>
  584. <xsl:variable name="show_cables">
  585. <xsl:call-template name="calc_cost_way">
  586. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  587. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  588. <xsl:with-param name="show_cables" select="1"/>
  589. </xsl:call-template>
  590. </xsl:variable>
  591. <xsl:for-each select="$candidates/bp:Path_Point">
  592. <!--<xsl:sort select="number(@distance)"/>-->
  593. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  594. <bp:Path_Point>
  595. <xsl:attribute name="bit" select="$best_variant"/>
  596. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  597. <xsl:copy-of select="@*"/>
  598. <xsl:attribute name="Price" select="$best_cost"/>
  599. <xsl:copy-of select="bp:Path_Point"/>
  600. </bp:Path_Point>
  601. </xsl:if>
  602. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  603. <bp:Path_Point_Cable>
  604. <xsl:attribute name="bit" select="$best_variant"/>
  605. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  606. <xsl:copy-of select="@*"/>
  607. <xsl:attribute name="Price" select="$best_cost"/>
  608. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  609. <!-- todo do jakiego Join zostal przybity -->
  610. <xsl:copy-of select="bp:Path_Point"/>
  611. <!-- <xsl:if test="$debug">-->
  612. <debug_show_cables>
  613. <xsl:copy-of select="$show_cables/cost[@ID_Join= current()/@ID_Join]"/>
  614. </debug_show_cables>
  615. <!--</xsl:if>-->
  616. </bp:Path_Point_Cable>
  617. </xsl:if>
  618. </xsl:for-each>
  619. </koniec_wariantow>
  620. </xsl:when>
  621. <xsl:otherwise>
  622. <!--<xsl:if test="$variant &lt; 10 ">--><!-- debug limit -->
  623. <xsl:call-template name="calculate_optimum">
  624. <xsl:with-param name="candidates" select="$candidates"/>
  625. <xsl:with-param name="max_bit" select="$max_bit"/>
  626. <xsl:with-param name="variant" select="$variant + 1"/>
  627. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  628. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  629. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  630. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  631. </xsl:call-template>
  632. <!--</xsl:if>-->
  633. </xsl:otherwise>
  634. </xsl:choose>
  635. </xsl:template>
  636. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  637. <xsl:param name="cand_to_calc" required="yes"/>
  638. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  639. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  640. <xsl:variable name="candidates_merged_with_poprzednie">
  641. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  642. <bp:Path_Point>
  643. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  644. <xsl:copy-of select="@*"/>
  645. <xsl:attribute name="distance_Neigh" select="0"/>
  646. </bp:Path_Point>
  647. </xsl:for-each>
  648. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  649. <bp:Path_Point>
  650. <xsl:copy-of select="@*"/>
  651. <xsl:attribute name="distance_Neigh" select="0"/>
  652. </bp:Path_Point>
  653. </xsl:for-each>
  654. <!-- dorzucenie Crossed -->
  655. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  656. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  657. <xsl:variable name="PathCrossFirst" select="position() = 1"/>
  658. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  659. <!--<xsl:message>#681: PathsCrossed up $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>; @NeighJoin_way_up_len=<xsl:value-of select="@NeighJoin_way_up_len"/></xsl:message>-->
  660. <bp:Path_Point>
  661. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  662. <xsl:attribute name="bin_pos" select="1"/>
  663. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  664. <xsl:choose>
  665. <xsl:when test="$PathCrossLast">
  666. <!--<xsl:message>adding distance to local from:<xsl:value-of select="number(parent::node()/@distance)"/>; to:<xsl:value-of select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>; </xsl:message>-->
  667. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>
  668. </xsl:when>
  669. <xsl:when test="$PathCrossFirst">
  670. <!--<xsl:message>reducing distance to local:from:<xsl:value-of select="number(parent::node()/@distance)"/>; to: <xsl:value-of select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>; </xsl:message>-->
  671. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>
  672. </xsl:when>
  673. <xsl:otherwise>
  674. <xsl:message terminate="yes">#720 dowiazanie Crossed w srodku grupy</xsl:message>
  675. </xsl:otherwise>
  676. </xsl:choose>
  677. <xsl:attribute name="pos" select="-1"/>
  678. </bp:Path_Point>
  679. </xsl:for-each>
  680. </xsl:for-each>
  681. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  682. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  683. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  684. <!--<xsl:message>#681: PathsCrossed dwn $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_dn_len"/>; @distance=<xsl:value-of select="@NeighJoin_way_dn_len"/>; </xsl:message>-->
  685. <bp:Path_Point>
  686. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  687. <xsl:attribute name="bin_pos" select="1"/>
  688. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  689. <xsl:choose>
  690. <xsl:when test="$PathCrossLast">
  691. <xsl:message>adding distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>; </xsl:message>
  692. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>
  693. </xsl:when>
  694. <xsl:otherwise>
  695. <xsl:message>reducing distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>; </xsl:message>
  696. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>
  697. </xsl:otherwise>
  698. </xsl:choose>
  699. <xsl:attribute name="pos" select="-1"/>
  700. </bp:Path_Point>
  701. </xsl:for-each>
  702. </xsl:for-each>
  703. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  704. </xsl:variable>
  705. <xsl:if test="number($debug) &gt;1">
  706. <candidates_merged_with_poprzednie>
  707. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  708. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  709. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  710. </candidates_merged_with_poprzednie>
  711. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  712. </xsl:if>
  713. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  714. <xsl:sort select="number(@distance)"/>
  715. <!--<xsl:message>#764 test @distance=<xsl:value-of select="@distance"/>; z @bin_pos=<xsl:value-of select="@bin_pos"/>; @distance=<xsl:value-of select="@distance"/>;@id_path=<xsl:value-of select="@id_path"/> </xsl:message>-->
  716. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  717. <xsl:choose>
  718. <xsl:when test="@poprzednia_grupa">
  719. <cost>
  720. <xsl:attribute name="Cable_Price" select="0"/>
  721. <xsl:attribute name="PE_Price" select="0"/>
  722. <xsl:attribute name="Price" select="0"/>
  723. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  724. </cost>
  725. </xsl:when>
  726. <!--<xsl:when test="number(string-length(@bin_pos))=0">
  727. <xsl:message>#768 debug @bin_pos=<xsl:value-of select="@bin_pos"/>; </xsl:message>
  728. </xsl:when>-->
  729. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  730. <xsl:variable name="way_up_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &lt; current()/number(@distance )]/number(@ID_Join))"/>
  731. <!--<xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>-->
  732. <xsl:variable name="way_up_len" >
  733. <xsl:choose>
  734. <xsl:when test="$way_up_id">
  735. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/>
  736. </xsl:when>
  737. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  738. </xsl:choose>
  739. </xsl:variable>
  740. <xsl:variable name="way_dn_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &gt; current()/number(@distance) ]/number(@ID_Join)) " />
  741. <!--<xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join =$way_dn_id ]/@ID_Join"/>-->
  742. <xsl:variable name="way_dn_len">
  743. <xsl:choose>
  744. <xsl:when test="$way_dn_id">
  745. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  746. </xsl:when>
  747. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  748. </xsl:choose>
  749. </xsl:variable>
  750. <xsl:choose><!-- czy w gore czy w dol -->
  751. <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') -->
  752. <cost>
  753. <xsl:variable name="Cable_Price_sum">
  754. <xsl:choose>
  755. <xsl:when test="number(@point_count) &gt; 0 ">
  756. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  757. </xsl:when>
  758. <xsl:otherwise>
  759. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  760. </xsl:otherwise>
  761. </xsl:choose>
  762. </xsl:variable>
  763. <!-- todo @point_count -->
  764. <xsl:if test="$show_cables">
  765. <xsl:attribute name="choosed" select="'down'"/>
  766. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  767. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  768. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  769. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  770. <xsl:attribute name="PE_Price" select="0"/>
  771. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  772. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  773. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  774. </xsl:if>
  775. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  776. </cost>
  777. </xsl:when>
  778. <xsl:otherwise>
  779. <cost>
  780. <xsl:variable name="Cable_Price_sum">
  781. <xsl:choose>
  782. <xsl:when test="number(@point_count) &gt; 0 ">
  783. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  784. </xsl:when>
  785. <xsl:otherwise>
  786. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  787. </xsl:otherwise>
  788. </xsl:choose>
  789. </xsl:variable>
  790. <xsl:if test="$show_cables or $debug">
  791. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  792. <xsl:attribute name="PE_Price" select="0"/>
  793. <xsl:attribute name="choosed" select="'up'"/>
  794. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  795. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  796. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  797. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  798. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  799. </xsl:if>
  800. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  801. </cost>
  802. </xsl:otherwise>
  803. </xsl:choose>
  804. </xsl:when>
  805. <xsl:otherwise>
  806. <cost>
  807. <xsl:attribute name="Cable_Price" select="0"/>
  808. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  809. <xsl:attribute name="Price" select="$PE_Price"/>
  810. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  811. </cost>
  812. </xsl:otherwise>
  813. </xsl:choose>
  814. </xsl:for-each>
  815. </xsl:template>
  816. </xsl:stylesheet>