edge_paths_with_PE_controll.xsl 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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. <!-- narzucenie max ilosci grup oraz wyliczenie ile jest -->
  264. <!--<xsl:variable name="$max_combinate_groups_elements"/>-->
  265. <xsl:variable name="max_combinate_groups_elements_for_group">
  266. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/>
  267. <xsl:variable name="cost_dist_Cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ ( number(@cost_dist) &gt; number($PE_Price) ) or number(@len) &gt; ( number($PE_Price) div number($Cable_Price) ) ])"/>
  268. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt ) + 1"/>
  269. <xsl:choose>
  270. <xsl:when test="number($bit_max) &lt; number(15) "> <!-- do przyjecia przez procesor kombinacji-->
  271. <xsl:message>#296 max_combinate_groups_elements_for_group number($bit_max=<xsl:value-of select="$bit_max"/>) &lt; number(15)</xsl:message>
  272. <xsl:choose>
  273. <xsl:when test="number($elements_cnt) &gt; 20">
  274. <xsl:message>#297 narzucam fixed liczbe 40 z uwagi na $bit_max=<xsl:value-of select="$bit_max"/> &lt; 15 ilosc max = $elements_cnt=<xsl:value-of select="$elements_cnt"/>; </xsl:message>
  275. <xsl:value-of select="20"/>
  276. </xsl:when>
  277. <xsl:otherwise>
  278. <xsl:message>#302 max_combinate_groups_elements_for_group setting to current count - number($elements_cnt=<xsl:value-of select="$elements_cnt"/>); </xsl:message>
  279. <xsl:value-of select="number($elements_cnt)"/>
  280. </xsl:otherwise>
  281. </xsl:choose>
  282. </xsl:when>
  283. <xsl:otherwise>
  284. <xsl:message>#309 max_combinate_groups_elements_for_group otherwise setting to default $max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>; </xsl:message>
  285. <xsl:value-of select="$max_combinate_groups_elements"/>
  286. </xsl:otherwise>
  287. </xsl:choose>
  288. </xsl:variable>
  289. <!-- tune max bit-->
  290. <xsl:variable name="bit_max">
  291. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/>
  292. <xsl:variable name="cost_dist_Cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ ( number(@cost_dist) &gt; number($PE_Price) ) or number(@len) &gt; ( number($PE_Price) div number($Cable_Price) ) ])"/>
  293. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt ) + 1"/>
  294. <xsl:choose>
  295. <xsl:when test=" number($bit_max) = number(1)">
  296. <xsl:value-of select="2"/>
  297. </xsl:when>
  298. <xsl:when test=" number($bit_max) = number(0)">
  299. <xsl:value-of select="2"/>
  300. </xsl:when>
  301. <xsl:otherwise>
  302. <xsl:value-of select="$bit_max"/>
  303. </xsl:otherwise>
  304. </xsl:choose>
  305. </xsl:variable>
  306. <xsl:variable name="EconomicDistanceCut2">
  307. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  308. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  309. <distance2>
  310. <xsl:copy-of select="@*"/>
  311. <xsl:choose>
  312. <xsl:when test=" position() mod $max_combinate_groups_elements_for_group = 0"> <!--- minus puste sum($EconomicDistanceCut/EconomicDistanceCut/distance[ number(@pos) &lt; number(current()/@pos) ]/number(@NotPoints)) ) --><!-- nabija grupe do przeliczenia-->
  313. <xsl:attribute name="PosCut3Flag" select="1"/>
  314. </xsl:when>
  315. <xsl:otherwise>
  316. <xsl:attribute name="PosCut3Flag" select="0"/>
  317. </xsl:otherwise>
  318. </xsl:choose>
  319. <xsl:copy-of select="PathsCrossed"/>
  320. </distance2>
  321. </xsl:for-each>
  322. </EconomicDistanceCut2>
  323. </xsl:variable>
  324. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  325. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  326. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  327. <distance2>
  328. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  329. <xsl:copy-of select="@*"/>
  330. <xsl:copy-of select="PathsCrossed"/>
  331. </distance2>
  332. </xsl:for-each>
  333. </EconomicDistanceCut2>
  334. </xsl:variable>
  335. <!-- debug -->
  336. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  337. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  338. <distance2>
  339. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  340. <xsl:copy-of select="@PosCut3GrId"/>
  341. <xsl:copy-of select="@CurSumNotPoints"/>
  342. <xsl:copy-of select="@NotPoints"/>
  343. <!-\-<xsl:copy-of select="@pos"/>-\->
  344. </distance2>
  345. </xsl:for-each>
  346. </EconomicDistanceCut2>-->
  347. <!-- debug -->
  348. <!--<debug>
  349. <xsl:copy-of select="$EconomicDistanceCut2"/>
  350. </debug>-->
  351. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/><!-- liczba wezlow potencjalnych licbza PE-->
  352. <xsl:variable name="cost_dist_Cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ ( number(@cost_dist) &gt; number($PE_Price) ) or number(@len) &gt; ( number($PE_Price) div number($Cable_Price) ) ])"/>
  353. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt )"/>
  354. <!-- max licbza PE-->
  355. <xsl:message>#341Calc $cost_dist_Cnt=<xsl:value-of select="$cost_dist_Cnt"/>; $elements_cnt=<xsl:value-of select="$elements_cnt"/>; $bit_max=<xsl:value-of select="$bit_max"/> ; </xsl:message>
  356. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  357. <xsl:variable name="PointMatrixGroup">
  358. <PointMatrixGroup>
  359. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  360. <PointMatrixGroupPos>
  361. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  362. <xsl:variable name="countGr" select="count(current-group())"/>
  363. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/number(@disttopkt) ) div ( number($PE_Price) div number($Cable_Price) ) )"/>
  364. <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))"/>
  365. </xsl:message>
  366. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  367. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  368. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  369. <xsl:attribute name="id_path" select="@id_path"/>
  370. <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 -->
  371. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  372. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  373. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  374. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  375. <xsl:attribute name="countGr" select="$countGr"/>
  376. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  377. <xsl:for-each select="current-group()">
  378. <distance2>
  379. <xsl:attribute name="PosMatrGroup" select="position()"/>
  380. <xsl:copy-of select="@*"></xsl:copy-of>
  381. <xsl:copy-of select="PathsCrossed"/>
  382. </distance2>
  383. </xsl:for-each>
  384. </PointMatrixGroupPos>
  385. </xsl:for-each-group>
  386. </PointMatrixGroup>
  387. </xsl:variable>
  388. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  389. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  390. -->
  391. <!-- debug -->
  392. <xsl:if test="number($debug) &gt; 3">
  393. <debug_356>
  394. <xsl:copy-of select="$PointMatrixGroup"/>
  395. </debug_356>
  396. </xsl:if>
  397. <PointMatrixGroupPE>
  398. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  399. <xsl:for-each select="PointMatrixGroupPos">
  400. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  401. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  402. <xsl:variable name="distanceGr" select="@distanceGr"/>
  403. <PointMatrixGroup>
  404. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  405. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  406. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  407. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  408. <xsl:attribute name="len_sum" select="@len_sum"/>
  409. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  410. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  411. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  412. <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"/>;
  413. </xsl:message>
  414. <!-- ida kandydaci -->
  415. <xsl:variable name="candidates">
  416. <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 -->
  417. <!--<xsl:sort select="@cost_dist" order="descending"/>-->
  418. <bp:Path_Point>
  419. <xsl:copy-of select="@ID_Join"/>
  420. <xsl:attribute name="DebugPosPoint" select="position()"/>
  421. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  422. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  423. <xsl:attribute name="pos" select="@pos"/>
  424. <xsl:attribute name="len" select="@len"/>
  425. <xsl:attribute name="distance" select="@distance"/>
  426. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  427. <xsl:attribute name="id_path" select="@id_path"/>
  428. <xsl:attribute name="point_count" select="@point_count"/>
  429. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  430. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  431. <xsl:copy-of select="PathsCrossed"/>
  432. </bp:Path_Point>
  433. </xsl:for-each>
  434. </xsl:variable>
  435. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  436. $last = A
  437. - najprosciej przez pliki oszukujac silnik xsl
  438. - tozsamowsci $ID_Way $distanceGr
  439. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  440. -->
  441. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  442. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  443. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  444. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  445. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  446. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  447. </xsl:if>
  448. </xsl:variable>
  449. <!--<poprzednie_odpalam_liczenie_or_nie>
  450. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  451. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  452. </poprzednie_odpalam_liczenie_or_nie>-->
  453. <xsl:variable name="odpalam_liczenie_or_nie">
  454. <xsl:choose>
  455. <xsl:when test="1=1"> <!-- bylo count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1-->
  456. <odpalam_liczenie>
  457. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  458. <!--<disabled>temporary blad after #410 OK - przeliczony wariant bit=000000010000 ( nr 4095;)
  459. [xslt] #239: calc @distanceGr=23; @point_count_Pos=19;@LineStringCount ; @len_sum=177; @distanceBeg=5055; @distanceEnd=5475;
  460. [xslt]
  461. [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: ""
  462. [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>-->
  463. <xsl:variable name="IfPathsCrossed" >
  464. <xsl:choose>
  465. <xsl:when test="$candidates/bp:Path_Point/PathsCrossed[@NeighJoin_way_up_ID_Join or @NeighJoin_way_dn_ID_Join]">
  466. <xsl:message>#534 there are PathsCrossed - allow to decrease -1</xsl:message>
  467. <xsl:value-of select="0"/>
  468. </xsl:when>
  469. <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
  470. </xsl:choose>
  471. </xsl:variable>
  472. <xsl:variable name="max_possible_bit"><!-- produkuje 11111111 -->
  473. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  474. </xsl:variable>
  475. <xsl:call-template name="calculate_optimum">
  476. <xsl:with-param name="candidates" select="$candidates"/>
  477. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  478. <xsl:with-param name="max_bit" select="$bit_max_Pos"/>
  479. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  480. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  481. <xsl:with-param name="variant" select="$IfPathsCrossed"/>
  482. </xsl:call-template>
  483. </odpalam_liczenie>
  484. </xsl:when>
  485. <xsl:otherwise>
  486. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  487. <xsl:for-each select="$candidates/bp:Path_Point">
  488. <bp:Path_Point>
  489. <xsl:copy-of select="@*"/>
  490. <xsl:attribute name="bin_pos" select="1"/>
  491. </bp:Path_Point>
  492. </xsl:for-each>
  493. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  494. </xsl:otherwise>
  495. </xsl:choose>
  496. </xsl:variable>
  497. <xsl:if test="number($debug) &gt; 0">
  498. <debug423>
  499. <xsl:attribute name="liczenie_dla"/>
  500. <candidates>
  501. <xsl:copy-of select="$candidates"/>
  502. </candidates>
  503. <poprzednie_odpalam_liczenie_or_nie>
  504. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  505. </poprzednie_odpalam_liczenie_or_nie>
  506. </debug423>
  507. </xsl:if>
  508. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  509. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  510. <poprzednie_odpalam_liczenie_or_nie>
  511. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  512. <xsl:if test="position() = last()">
  513. <xsl:copy-of select="."/>
  514. </xsl:if>
  515. </xsl:for-each>
  516. <nizej_zwykly></nizej_zwykly>
  517. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  518. <xsl:if test="position() = last()">
  519. <xsl:copy-of select="."/>
  520. </xsl:if>
  521. </xsl:for-each>
  522. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  523. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  524. </poprzednie_odpalam_liczenie_or_nie>
  525. </xsl:result-document>
  526. </PointMatrixGroup>
  527. </xsl:for-each>
  528. </xsl:for-each>
  529. </PointMatrixGroupPE>
  530. <!--<PointMatrix>
  531. <xsl:attribute name="bit_max" select="$bit_max"/>
  532. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  533. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  534. <!-\-<xsl:call-template name="PE_wariant">
  535. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  536. <xsl:with-param name="bit_max" select="$bit_max"/>
  537. </xsl:call-template>-\->
  538. </PointMatrix>-->
  539. </Path>
  540. </xsl:template>
  541. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  542. <xsl:apply-templates mode="PathsCrossed"/>
  543. </xsl:template>
  544. <xsl:template match="bp:Path_Point" mode="PathsCrossed"> <!-- nie potrzebujemy kabli ! bp:Path_Point_Cable-->
  545. <xsl:copy-of select="."/>
  546. </xsl:template>
  547. <xsl:template match="*|text()" mode="PathsCrossed"/>
  548. <xsl:template name="calculate_optimum">
  549. <xsl:param name="candidates" required="yes"/>
  550. <xsl:param name="elements_cnt" required="yes"/>
  551. <xsl:param name="variant" select="1"/>
  552. <xsl:param name="max_bit" required="yes"/>
  553. <xsl:param name="max_possible_bit" required="yes"/>
  554. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  555. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  556. <!-- do jednorazowego wyzwolenia przez fukcje, aby tylko raz odjelo wariant zerowy -->
  557. <!-- znajduje kolejny korzystny wariant bit -->
  558. <xsl:variable name="variant">
  559. <xsl:choose>
  560. <xsl:when test="number($max_bit) &gt;= number($elements_cnt)">
  561. <xsl:message>#576 $max_bit <xsl:value-of select="$max_bit"/> &gt;$elements_cnt=<xsl:value-of select="$elements_cnt"/>; in $variant=<xsl:value-of select="$variant"/>;</xsl:message>
  562. <xsl:value-of select="$variant"/>
  563. </xsl:when>
  564. <xsl:when test="number($max_bit) &gt; 0">
  565. <xsl:message>#80 try to find next $max_bit <xsl:value-of select="$max_bit"/> &gt;$elements_cnt=<xsl:value-of select="$elements_cnt"/>; in $variant=<xsl:value-of select="$variant"/>;</xsl:message>
  566. <xsl:variable name="variant_found" select="bp:next_bit_max($variant,$max_bit,$elements_cnt,0)"/>
  567. <xsl:value-of select="$variant_found"/>
  568. </xsl:when>
  569. <xsl:otherwise>
  570. <xsl:value-of select="$variant"/>
  571. </xsl:otherwise>
  572. </xsl:choose>
  573. </xsl:variable>
  574. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  575. <xsl:message>... $variant_found <xsl:value-of select="$variant_found"/>; $bit=<xsl:value-of select="$bit"/></xsl:message>
  576. <xsl:variable name="cand_to_calc">
  577. <xsl:for-each select="$candidates/bp:Path_Point">
  578. <!--<xsl:sort select="number(@distance)"/>-->
  579. <bp:Path_Point>
  580. <!--<xsl:attribute name="bit" select="$bit"/>-->
  581. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  582. <xsl:copy-of select="@*"/>
  583. <!--<xsl:copy-of select="bp:Path_Point"/>-->
  584. <xsl:copy-of select="PathsCrossed"/>
  585. </bp:Path_Point>
  586. </xsl:for-each>
  587. </xsl:variable>
  588. <!-- debug -->
  589. <xsl:if test=" number($debug) &gt; 2">
  590. <variant><xsl:attribute name="variant" select="$variant"/>
  591. <xsl:attribute name="cur_bit" select="$bit"/>
  592. <xsl:attribute name="best_cost" select="$best_cost"/>
  593. <xsl:attribute name="best_variant" select="$best_variant"/>
  594. <xsl:copy-of select="$cand_to_calc"/>
  595. </variant>
  596. </xsl:if>
  597. <xsl:variable name="calc_cost_way">
  598. <xsl:call-template name="calc_cost_way">
  599. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  600. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  601. </xsl:call-template>
  602. </xsl:variable>
  603. <xsl:variable name="cost_sum">
  604. <costs>
  605. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  606. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  607. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  608. <xsl:copy-of select="$calc_cost_way"/>
  609. </costs>
  610. </xsl:variable>
  611. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  612. <xsl:variable name="best">
  613. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  614. <xsl:choose>
  615. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  616. <best>
  617. <xsl:attribute name="best_cost" select="$cur_Price"/>
  618. <xsl:attribute name="best_variant" select="$bit"/>
  619. </best>
  620. </xsl:when>
  621. <xsl:otherwise>
  622. <best>
  623. <xsl:attribute name="best_cost" select="$best_cost"/>
  624. <xsl:attribute name="best_variant" select="$best_variant"/>
  625. </best>
  626. </xsl:otherwise>
  627. </xsl:choose>
  628. </xsl:variable>
  629. <xsl:if test=" number($debug) &gt; 3 ">
  630. <xsl:copy-of select="$best"/>
  631. <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>
  632. </xsl:if>
  633. <xsl:choose>
  634. <xsl:when test="$bit = $max_possible_bit">
  635. <koniec_wariantow>
  636. <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>
  637. <xsl:attribute name="best_variant" select="$best_variant"/>
  638. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  639. <xsl:variable name="cand_to_calc_best">
  640. <xsl:for-each select="$candidates/bp:Path_Point">
  641. <!--<xsl:sort select="@distance"/>-->
  642. <bp:Path_Point>
  643. <!--<xsl:attribute name="bit" select="$bit"/>-->
  644. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  645. <xsl:copy-of select="@*"/>
  646. <xsl:copy-of select="bp:Path_Point"/>
  647. </bp:Path_Point>
  648. </xsl:for-each>
  649. </xsl:variable>
  650. <xsl:variable name="show_cables">
  651. <xsl:call-template name="calc_cost_way">
  652. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  653. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  654. <xsl:with-param name="show_cables" select="1"/>
  655. </xsl:call-template>
  656. </xsl:variable>
  657. <xsl:for-each select="$candidates/bp:Path_Point">
  658. <!--<xsl:sort select="number(@distance)"/>-->
  659. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  660. <bp:Path_Point>
  661. <xsl:attribute name="bit" select="$best_variant"/>
  662. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  663. <xsl:copy-of select="@*"/>
  664. <xsl:attribute name="Price" select="$best_cost"/>
  665. <xsl:copy-of select="bp:Path_Point"/>
  666. </bp:Path_Point>
  667. </xsl:if>
  668. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  669. <bp:Path_Point_Cable>
  670. <xsl:attribute name="bit" select="$best_variant"/>
  671. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  672. <xsl:copy-of select="@*"/>
  673. <xsl:attribute name="Price" select="$best_cost"/>
  674. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  675. <!-- todo do jakiego Join zostal przybity -->
  676. <xsl:copy-of select="bp:Path_Point"/>
  677. <!-- <xsl:if test="$debug">-->
  678. <debug_show_cables>
  679. <xsl:copy-of select="$show_cables/cost[@ID_Join= current()/@ID_Join]"/>
  680. </debug_show_cables>
  681. <!--</xsl:if>-->
  682. </bp:Path_Point_Cable>
  683. </xsl:if>
  684. </xsl:for-each>
  685. </koniec_wariantow>
  686. </xsl:when>
  687. <xsl:otherwise>
  688. <!--<xsl:if test="$variant &lt; 10 ">--><!-- debug limit -->
  689. <xsl:call-template name="calculate_optimum">
  690. <xsl:with-param name="candidates" select="$candidates"/>
  691. <xsl:with-param name="max_bit" select="$max_bit"/>
  692. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  693. <xsl:with-param name="variant" select="$variant + 1"/>
  694. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  695. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  696. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  697. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  698. </xsl:call-template>
  699. <!--</xsl:if>-->
  700. </xsl:otherwise>
  701. </xsl:choose>
  702. </xsl:template>
  703. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  704. <xsl:param name="cand_to_calc" required="yes"/>
  705. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  706. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  707. <xsl:variable name="candidates_merged_with_poprzednie">
  708. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  709. <bp:Path_Point>
  710. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  711. <xsl:copy-of select="@*"/>
  712. <xsl:attribute name="distance_Neigh" select="0"/>
  713. </bp:Path_Point>
  714. </xsl:for-each>
  715. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  716. <bp:Path_Point>
  717. <xsl:copy-of select="@*"/>
  718. <xsl:attribute name="distance_Neigh" select="0"/>
  719. </bp:Path_Point>
  720. </xsl:for-each>
  721. <!-- dorzucenie Crossed -->
  722. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  723. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  724. <xsl:variable name="PathCrossFirst" select="position() = 1"/>
  725. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  726. <!--<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>-->
  727. <bp:Path_Point>
  728. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  729. <xsl:attribute name="bin_pos" select="1"/>
  730. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  731. <xsl:choose>
  732. <xsl:when test="$PathCrossLast">
  733. <!--<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>-->
  734. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>
  735. </xsl:when>
  736. <xsl:when test="$PathCrossFirst">
  737. <!--<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>-->
  738. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>
  739. </xsl:when>
  740. <xsl:otherwise>
  741. <xsl:message terminate="no">#720 dowiazanie Crossed w srodku grupy @NeighJoin_way_up_ID_Join=<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>!</xsl:message>
  742. </xsl:otherwise>
  743. </xsl:choose>
  744. <xsl:attribute name="pos" select="-1"/>
  745. </bp:Path_Point>
  746. </xsl:for-each>
  747. </xsl:for-each>
  748. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  749. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  750. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  751. <!--<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>-->
  752. <bp:Path_Point>
  753. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  754. <xsl:attribute name="bin_pos" select="1"/>
  755. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  756. <xsl:choose>
  757. <xsl:when test="$PathCrossLast">
  758. <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>
  759. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>
  760. </xsl:when>
  761. <xsl:otherwise>
  762. <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>
  763. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>
  764. </xsl:otherwise>
  765. </xsl:choose>
  766. <xsl:attribute name="pos" select="-1"/>
  767. </bp:Path_Point>
  768. </xsl:for-each>
  769. </xsl:for-each>
  770. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  771. </xsl:variable>
  772. <xsl:if test="number($debug) &gt;1">
  773. <candidates_merged_with_poprzednie>
  774. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  775. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  776. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  777. </candidates_merged_with_poprzednie>
  778. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  779. </xsl:if>
  780. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  781. <xsl:sort select="number(@distance)"/>
  782. <!--<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>-->
  783. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  784. <xsl:choose>
  785. <xsl:when test="@poprzednia_grupa">
  786. <cost>
  787. <xsl:attribute name="Cable_Price" select="0"/>
  788. <xsl:attribute name="PE_Price" select="0"/>
  789. <xsl:attribute name="Price" select="0"/>
  790. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  791. </cost>
  792. </xsl:when>
  793. <!--<xsl:when test="number(string-length(@bin_pos))=0">
  794. <xsl:message>#768 debug @bin_pos=<xsl:value-of select="@bin_pos"/>; </xsl:message>
  795. </xsl:when>-->
  796. <xsl:when test="@bin_pos='0'"><!-- szukamy gdzie ma najblizej i za ile -->
  797. <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))"/>
  798. <!--<xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>-->
  799. <xsl:variable name="way_up_len" >
  800. <xsl:choose>
  801. <xsl:when test="$way_up_id">
  802. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/>
  803. </xsl:when>
  804. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  805. </xsl:choose>
  806. </xsl:variable>
  807. <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)) " />
  808. <!--<xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join =$way_dn_id ]/@ID_Join"/>-->
  809. <xsl:variable name="way_dn_len">
  810. <xsl:choose>
  811. <xsl:when test="$way_dn_id">
  812. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  813. </xsl:when>
  814. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  815. </xsl:choose>
  816. </xsl:variable>
  817. <xsl:choose><!-- czy w gore czy w dol -->
  818. <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') -->
  819. <cost>
  820. <xsl:variable name="Cable_Price_sum">
  821. <xsl:choose>
  822. <xsl:when test="number(@point_count) &gt; 0 ">
  823. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  824. </xsl:when>
  825. <xsl:otherwise>
  826. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  827. </xsl:otherwise>
  828. </xsl:choose>
  829. </xsl:variable>
  830. <!-- todo @point_count -->
  831. <xsl:if test="$show_cables">
  832. <xsl:attribute name="choosed" select="'down'"/>
  833. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  834. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  835. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  836. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  837. <xsl:attribute name="PE_Price" select="0"/>
  838. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  839. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  840. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  841. </xsl:if>
  842. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  843. </cost>
  844. </xsl:when>
  845. <xsl:otherwise>
  846. <cost>
  847. <xsl:variable name="Cable_Price_sum">
  848. <xsl:choose>
  849. <xsl:when test="number(@point_count) &gt; 0 ">
  850. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  851. </xsl:when>
  852. <xsl:otherwise>
  853. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  854. </xsl:otherwise>
  855. </xsl:choose>
  856. </xsl:variable>
  857. <xsl:if test="$show_cables or $debug">
  858. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  859. <xsl:attribute name="PE_Price" select="0"/>
  860. <xsl:attribute name="choosed" select="'up'"/>
  861. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  862. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  863. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  864. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  865. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  866. </xsl:if>
  867. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  868. </cost>
  869. </xsl:otherwise>
  870. </xsl:choose>
  871. </xsl:when>
  872. <xsl:otherwise>
  873. <cost>
  874. <xsl:attribute name="Cable_Price" select="0"/>
  875. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  876. <xsl:attribute name="Price" select="$PE_Price"/>
  877. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  878. </cost>
  879. </xsl:otherwise>
  880. </xsl:choose>
  881. </xsl:for-each>
  882. </xsl:template>
  883. </xsl:stylesheet>