edge_paths_with_PE_controll.xsl 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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(3) "> <!-- 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 20 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:when test="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"><!-- jak jest kolejny nr grupy to tez moze nie byc potrzebny wezel! -->
  470. <xsl:message>#505 Zakladamy, ze moze nie byc potrzebny wezel w tej grupie, bo jest poprzednia grupa w danych w tej petli!</xsl:message>
  471. <xsl:value-of select="0"/>
  472. </xsl:when>
  473. <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
  474. </xsl:choose>
  475. </xsl:variable>
  476. <xsl:variable name="max_possible_bit"><!-- produkuje 11111111 -->
  477. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  478. </xsl:variable>
  479. <!-- tune -->
  480. <xsl:variable name="bit_max_Pos">
  481. <xsl:choose>
  482. <xsl:when test="number(@len_sum) &gt; ( number($PE_Price) div number($Cable_Price) ) and number($bit_max_Pos) &lt; 2">
  483. <xsl:value-of select=" round( (number(@len_sum)) div ( number($PE_Price) div number($Cable_Price) ) + 2 )"/> <!-- jak droga dluzsza od jedn kosztu, to przynajmniej tyle bin_max ile takich odcinkow-->
  484. </xsl:when>
  485. <xsl:when test="number($bit_max_Pos) &lt; 2">
  486. <xsl:value-of select="2"/>
  487. </xsl:when>
  488. <xsl:otherwise><xsl:value-of select="round(number($bit_max_Pos))"/></xsl:otherwise>
  489. </xsl:choose>
  490. </xsl:variable>
  491. <xsl:call-template name="calculate_optimum">
  492. <xsl:with-param name="candidates" select="$candidates"/>
  493. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  494. <xsl:with-param name="max_bit" select="$bit_max_Pos"/>
  495. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  496. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  497. <xsl:with-param name="variant" select="$IfPathsCrossed"/>
  498. </xsl:call-template>
  499. </odpalam_liczenie>
  500. </xsl:when>
  501. <xsl:otherwise>
  502. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  503. <xsl:for-each select="$candidates/bp:Path_Point">
  504. <bp:Path_Point>
  505. <xsl:copy-of select="@*"/>
  506. <xsl:attribute name="bin_pos" select="1"/>
  507. </bp:Path_Point>
  508. </xsl:for-each>
  509. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  510. </xsl:otherwise>
  511. </xsl:choose>
  512. </xsl:variable>
  513. <xsl:if test="number($debug) &gt; 0">
  514. <debug423>
  515. <xsl:attribute name="liczenie_dla"/>
  516. <candidates>
  517. <xsl:copy-of select="$candidates"/>
  518. </candidates>
  519. <poprzednie_odpalam_liczenie_or_nie>
  520. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  521. </poprzednie_odpalam_liczenie_or_nie>
  522. </debug423>
  523. </xsl:if>
  524. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  525. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  526. <poprzednie_odpalam_liczenie_or_nie>
  527. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  528. <xsl:if test="position() = last()">
  529. <xsl:copy-of select="."/>
  530. </xsl:if>
  531. </xsl:for-each>
  532. <nizej_zwykly></nizej_zwykly>
  533. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  534. <xsl:if test="position() = last()">
  535. <xsl:copy-of select="."/>
  536. </xsl:if>
  537. </xsl:for-each>
  538. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  539. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  540. </poprzednie_odpalam_liczenie_or_nie>
  541. </xsl:result-document>
  542. </PointMatrixGroup>
  543. </xsl:for-each>
  544. </xsl:for-each>
  545. </PointMatrixGroupPE>
  546. <!--<PointMatrix>
  547. <xsl:attribute name="bit_max" select="$bit_max"/>
  548. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  549. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  550. <!-\-<xsl:call-template name="PE_wariant">
  551. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  552. <xsl:with-param name="bit_max" select="$bit_max"/>
  553. </xsl:call-template>-\->
  554. </PointMatrix>-->
  555. </Path>
  556. </xsl:template>
  557. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  558. <xsl:apply-templates mode="PathsCrossed"/>
  559. </xsl:template>
  560. <xsl:template match="bp:Path_Point" mode="PathsCrossed"> <!-- nie potrzebujemy kabli ! bp:Path_Point_Cable-->
  561. <xsl:copy-of select="."/>
  562. </xsl:template>
  563. <xsl:template match="*|text()" mode="PathsCrossed"/>
  564. <xsl:template name="calculate_optimum">
  565. <xsl:param name="candidates" required="yes"/>
  566. <xsl:param name="elements_cnt" required="yes"/>
  567. <xsl:param name="variant" select="1"/>
  568. <xsl:param name="max_bit" required="yes"/>
  569. <xsl:param name="max_possible_bit" required="yes"/>
  570. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  571. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  572. <!-- do jednorazowego wyzwolenia przez fukcje, aby tylko raz odjelo wariant zerowy -->
  573. <!-- znajduje kolejny korzystny wariant bit , trzeba to wyzwolic jak jest wiecej jedynek-->
  574. <xsl:variable name="variant">
  575. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  576. <xsl:variable name="digits">
  577. <xsl:for-each select="1 to string-length($bit)">
  578. <xsl:if test="substring($bit,.,1) = '1'">
  579. <xsl:value-of select="number(1)"/>
  580. </xsl:if>
  581. </xsl:for-each>
  582. </xsl:variable>
  583. <xsl:choose>
  584. <xsl:when test=" string-length($digits) &gt; number($max_bit)">
  585. <xsl:choose>
  586. <xsl:when test="$variant = 0">
  587. <xsl:value-of select="$variant"/><!-- dla sprawdzenia wzajemnych relacji CrossWays -->
  588. </xsl:when>
  589. <xsl:when test="$bit = $max_possible_bit">
  590. <xsl:value-of select="$variant"/><!-- osiagnieto max -->
  591. <xsl:message>#627 Osiagnieto MAX $bit<xsl:value-of select="$bit"/>; = $max_possible_bit=<xsl:value-of select="$max_possible_bit"/>;</xsl:message>
  592. </xsl:when>
  593. <xsl:when test="number($max_bit) &gt;= number($elements_cnt)">
  594. <xsl:message>#576 olac $max_bit <xsl:value-of select="$max_possible_bit"/> &gt;$elements_cnt=<xsl:value-of select="$elements_cnt"/>; in $variant=<xsl:value-of select="$variant"/>;</xsl:message>
  595. <xsl:value-of select="number($variant)"/>
  596. </xsl:when>
  597. <xsl:when test="number($max_bit) &gt; 0">
  598. <xsl:if test="$variant mod 2048 = 0 ">
  599. <xsl:message>#80 try to find next $bit=<xsl:value-of select="$bit"/>; $max_possible_bit=<xsl:value-of select="$max_possible_bit"/>; $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>
  600. </xsl:if>
  601. <!--<xsl:variable name="variant_found" select="bp:next_bit_max(number($variant),$max_bit,$max_possible_bit,0)"/>-->
  602. <xsl:variable name="variant_found">
  603. <xsl:call-template name="bp:next_bit_max">
  604. <xsl:with-param name="variant" select="$variant"/>
  605. <xsl:with-param name="bit_limit" select="$max_bit"/> <!-- like 6 -->
  606. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/><!-- like 1111111 -->
  607. <xsl:with-param name="loop" select="0"/>
  608. </xsl:call-template>
  609. </xsl:variable>
  610. <xsl:value-of select="$variant_found"/>
  611. <xsl:message>#648 we found next propos new $variant_found=<xsl:value-of select="$variant_found"/> $bit of that: <xsl:value-of select="bp:decimalToBitFill($variant_found,$elements_cnt)"/>; from $max_bit=<xsl:value-of select="$max_bit"/>;</xsl:message>
  612. </xsl:when>
  613. <xsl:otherwise>
  614. <xsl:value-of select="number($variant)"/>
  615. </xsl:otherwise>
  616. </xsl:choose>
  617. </xsl:when>
  618. <xsl:otherwise><xsl:value-of select="$variant"/></xsl:otherwise>
  619. </xsl:choose>
  620. </xsl:variable>
  621. <xsl:variable name="bit">
  622. <xsl:choose><!-- funkcja nearest possible bit moze zwrocic zero! -->
  623. <xsl:when test=" string-length($variant) &gt; 0"><xsl:value-of select="string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/></xsl:when>
  624. <xsl:otherwise><xsl:value-of select="$max_possible_bit"/></xsl:otherwise>
  625. </xsl:choose>
  626. </xsl:variable>
  627. <xsl:if test=" string-length($bit) = 0"><xsl:message>#650 zerowy $bit ! nie moze byc tak!</xsl:message></xsl:if>
  628. <xsl:if test="$variant mod 2048 = 0 ">
  629. <xsl:message>...#625 $variant curr found <xsl:value-of select="$variant"/>; $max_bit=<xsl:value-of select="$max_bit"/>; $bit=<xsl:value-of select="$bit"/>, $elements_cnt=<xsl:value-of select="$elements_cnt"/>;</xsl:message>
  630. </xsl:if>
  631. <xsl:variable name="cand_to_calc">
  632. <xsl:for-each select="$candidates/bp:Path_Point">
  633. <!--<xsl:sort select="number(@distance)"/>-->
  634. <bp:Path_Point>
  635. <!--<xsl:attribute name="bit" select="$bit"/>-->
  636. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  637. <xsl:copy-of select="@*"/>
  638. <!--<xsl:copy-of select="bp:Path_Point"/>-->
  639. <xsl:copy-of select="PathsCrossed"/>
  640. </bp:Path_Point>
  641. </xsl:for-each>
  642. </xsl:variable>
  643. <!-- debug -->
  644. <xsl:if test=" number($debug) &gt; 2">
  645. <variant><xsl:attribute name="variant" select="$variant"/>
  646. <xsl:attribute name="cur_bit" select="$bit"/>
  647. <xsl:attribute name="best_cost" select="$best_cost"/>
  648. <xsl:attribute name="best_variant" select="$best_variant"/>
  649. <xsl:copy-of select="$cand_to_calc"/>
  650. </variant>
  651. </xsl:if>
  652. <xsl:variable name="calc_cost_way">
  653. <xsl:call-template name="calc_cost_way">
  654. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  655. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  656. </xsl:call-template>
  657. </xsl:variable>
  658. <xsl:variable name="cost_sum">
  659. <costs>
  660. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  661. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  662. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  663. <xsl:copy-of select="$calc_cost_way"/>
  664. </costs>
  665. </xsl:variable>
  666. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  667. <xsl:variable name="best">
  668. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  669. <xsl:choose>
  670. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  671. <best>
  672. <xsl:attribute name="best_cost" select="$cur_Price"/>
  673. <xsl:attribute name="best_variant" select="$bit"/>
  674. </best>
  675. </xsl:when>
  676. <xsl:otherwise>
  677. <best>
  678. <xsl:attribute name="best_cost" select="$best_cost"/>
  679. <xsl:attribute name="best_variant" select="$best_variant"/>
  680. </best>
  681. </xsl:otherwise>
  682. </xsl:choose>
  683. </xsl:variable>
  684. <xsl:if test=" number($debug) &gt; 3 ">
  685. <xsl:copy-of select="$best"/>
  686. <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>
  687. </xsl:if>
  688. <xsl:choose>
  689. <xsl:when test="$bit = $max_possible_bit">
  690. <koniec_wariantow>
  691. <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>
  692. <xsl:if test=" not(contains($best_variant,'1'))"><xsl:message> #739 :-) Prawdopodobnie wykorzystano wezly z poprzedniej grupy lub drogi! </xsl:message></xsl:if>
  693. <xsl:attribute name="best_variant" select="$best_variant"/>
  694. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  695. <xsl:variable name="cand_to_calc_best">
  696. <xsl:for-each select="$candidates/bp:Path_Point">
  697. <!--<xsl:sort select="@distance"/>-->
  698. <bp:Path_Point>
  699. <!--<xsl:attribute name="bit" select="$bit"/>-->
  700. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  701. <xsl:copy-of select="@*"/>
  702. <xsl:copy-of select="bp:Path_Point"/>
  703. </bp:Path_Point>
  704. </xsl:for-each>
  705. </xsl:variable>
  706. <xsl:variable name="show_cables">
  707. <xsl:call-template name="calc_cost_way">
  708. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  709. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  710. <xsl:with-param name="show_cables" select="1"/>
  711. </xsl:call-template>
  712. </xsl:variable>
  713. <xsl:for-each select="$candidates/bp:Path_Point">
  714. <!--<xsl:sort select="number(@distance)"/>-->
  715. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  716. <bp:Path_Point>
  717. <xsl:attribute name="bit" select="$best_variant"/>
  718. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  719. <xsl:copy-of select="@*"/>
  720. <xsl:attribute name="Price" select="$best_cost"/>
  721. <xsl:copy-of select="bp:Path_Point"/>
  722. </bp:Path_Point>
  723. </xsl:if>
  724. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  725. <bp:Path_Point_Cable>
  726. <xsl:attribute name="bit" select="$best_variant"/>
  727. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  728. <xsl:copy-of select="@*"/>
  729. <xsl:attribute name="Price" select="$best_cost"/>
  730. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  731. <!-- todo do jakiego Join zostal przybity -->
  732. <xsl:copy-of select="bp:Path_Point"/>
  733. <!-- <xsl:if test="$debug">-->
  734. <debug_show_cables>
  735. <xsl:copy-of select="$show_cables/cost[@ID_Join= current()/@ID_Join]"/>
  736. </debug_show_cables>
  737. <!--</xsl:if>-->
  738. </bp:Path_Point_Cable>
  739. </xsl:if>
  740. </xsl:for-each>
  741. </koniec_wariantow>
  742. </xsl:when>
  743. <xsl:otherwise>
  744. <!--<xsl:if test="$variant &lt; 10 ">--><!-- debug limit -->
  745. <xsl:call-template name="calculate_optimum">
  746. <xsl:with-param name="candidates" select="$candidates"/>
  747. <xsl:with-param name="max_bit" select="$max_bit"/>
  748. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  749. <xsl:with-param name="variant" select="$variant + 1"/>
  750. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  751. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  752. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  753. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  754. </xsl:call-template>
  755. <!--</xsl:if>-->
  756. </xsl:otherwise>
  757. </xsl:choose>
  758. </xsl:template>
  759. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  760. <xsl:param name="cand_to_calc" required="yes"/>
  761. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  762. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  763. <xsl:variable name="candidates_merged_with_poprzednie">
  764. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  765. <bp:Path_Point>
  766. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  767. <xsl:copy-of select="@*"/>
  768. <xsl:attribute name="distance_Neigh" select="0"/>
  769. </bp:Path_Point>
  770. </xsl:for-each>
  771. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  772. <bp:Path_Point>
  773. <xsl:copy-of select="@*"/>
  774. <xsl:attribute name="distance_Neigh" select="0"/>
  775. </bp:Path_Point>
  776. </xsl:for-each>
  777. <!-- dorzucenie Crossed -->
  778. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  779. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  780. <xsl:variable name="PathCrossFirst" select="position() = 1"/>
  781. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  782. <!--<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>-->
  783. <bp:Path_Point>
  784. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  785. <xsl:attribute name="bin_pos" select="1"/>
  786. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  787. <xsl:choose>
  788. <xsl:when test="$PathCrossLast">
  789. <!--<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>-->
  790. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>
  791. </xsl:when>
  792. <xsl:when test="$PathCrossFirst">
  793. <!--<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>-->
  794. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>
  795. </xsl:when>
  796. <xsl:otherwise>
  797. <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>
  798. </xsl:otherwise>
  799. </xsl:choose>
  800. <xsl:attribute name="pos" select="-1"/>
  801. </bp:Path_Point>
  802. </xsl:for-each>
  803. </xsl:for-each>
  804. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  805. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  806. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  807. <!--<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>-->
  808. <bp:Path_Point>
  809. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  810. <xsl:attribute name="bin_pos" select="1"/>
  811. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  812. <xsl:choose>
  813. <xsl:when test="$PathCrossLast">
  814. <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>
  815. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>
  816. </xsl:when>
  817. <xsl:otherwise>
  818. <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>
  819. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>
  820. </xsl:otherwise>
  821. </xsl:choose>
  822. <xsl:attribute name="pos" select="-1"/>
  823. </bp:Path_Point>
  824. </xsl:for-each>
  825. </xsl:for-each>
  826. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  827. </xsl:variable>
  828. <xsl:if test="number($debug) &gt;1">
  829. <candidates_merged_with_poprzednie>
  830. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  831. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  832. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  833. </candidates_merged_with_poprzednie>
  834. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  835. </xsl:if>
  836. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  837. <xsl:sort select="number(@distance)"/>
  838. <!--<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>-->
  839. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  840. <xsl:choose>
  841. <xsl:when test="@poprzednia_grupa">
  842. <cost>
  843. <xsl:attribute name="Cable_Price" select="0"/>
  844. <xsl:attribute name="PE_Price" select="0"/>
  845. <xsl:attribute name="Price" select="0"/>
  846. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  847. </cost>
  848. </xsl:when>
  849. <!--<xsl:when test="number(string-length(@bin_pos))=0">
  850. <xsl:message>#768 debug @bin_pos=<xsl:value-of select="@bin_pos"/>; </xsl:message>
  851. </xsl:when>-->
  852. <xsl:when test="@bin_pos='0'"><!-- szukamy gdzie ma najblizej i za ile -->
  853. <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))"/>
  854. <!--<xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>-->
  855. <xsl:variable name="way_up_len" >
  856. <xsl:choose>
  857. <xsl:when test="$way_up_id">
  858. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/>
  859. </xsl:when>
  860. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  861. </xsl:choose>
  862. </xsl:variable>
  863. <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)) " />
  864. <!--<xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join =$way_dn_id ]/@ID_Join"/>-->
  865. <xsl:variable name="way_dn_len">
  866. <xsl:choose>
  867. <xsl:when test="$way_dn_id">
  868. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  869. </xsl:when>
  870. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  871. </xsl:choose>
  872. </xsl:variable>
  873. <xsl:choose><!-- czy w gore czy w dol -->
  874. <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') -->
  875. <cost>
  876. <xsl:variable name="Cable_Price_sum">
  877. <xsl:choose>
  878. <xsl:when test="number(@point_count) &gt; 0 ">
  879. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  880. </xsl:when>
  881. <xsl:otherwise>
  882. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  883. </xsl:otherwise>
  884. </xsl:choose>
  885. </xsl:variable>
  886. <!-- todo @point_count -->
  887. <xsl:if test="$show_cables">
  888. <xsl:attribute name="choosed" select="'down'"/>
  889. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  890. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  891. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  892. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  893. <xsl:attribute name="PE_Price" select="0"/>
  894. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  895. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  896. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  897. </xsl:if>
  898. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  899. </cost>
  900. </xsl:when>
  901. <xsl:otherwise>
  902. <cost>
  903. <xsl:variable name="Cable_Price_sum">
  904. <xsl:choose>
  905. <xsl:when test="number(@point_count) &gt; 0 ">
  906. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  907. </xsl:when>
  908. <xsl:otherwise>
  909. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  910. </xsl:otherwise>
  911. </xsl:choose>
  912. </xsl:variable>
  913. <xsl:if test="$show_cables or $debug">
  914. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  915. <xsl:attribute name="PE_Price" select="0"/>
  916. <xsl:attribute name="choosed" select="'up'"/>
  917. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  918. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  919. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  920. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  921. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  922. </xsl:if>
  923. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  924. </cost>
  925. </xsl:otherwise>
  926. </xsl:choose>
  927. </xsl:when>
  928. <xsl:otherwise>
  929. <cost>
  930. <xsl:attribute name="Cable_Price" select="0"/>
  931. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  932. <xsl:attribute name="Price" select="$PE_Price"/>
  933. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  934. </cost>
  935. </xsl:otherwise>
  936. </xsl:choose>
  937. </xsl:for-each>
  938. </xsl:template>
  939. </xsl:stylesheet>