userFunctions.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. #include "userFunctions.h"
  2. #include "freeTrajInfo.h"
  3. void getIniRefTraj(cmscp_trajInfo** refTraj, cmscp_setup* setup)
  4. {
  5. int i, ij, k, numPhase, iphase, numMesh, maxNumNode, isOutput, isIntegOver, numState, numControl, numParameter, cnt, length, integNumState, integNumControl;
  6. double outStepSize, integStepSize, newState[8], oldState[8], u[2], * stateK, * controlK, outTime, tempWork[37], path[5], * statePhaseKm1f, * meshNode, * integState0, * integStatef, * integControl0, * integControlf, * time;
  7. cmscp_dimension* dimension;
  8. cmscp_mesh** mesh;
  9. cmscp_auxdata* auxdata;
  10. cmscp_scales* scales;
  11. cmscp_integTraj** integTraj;
  12. // 问题维数
  13. dimension = setup->dimension;
  14. numPhase = setup->numPhase;
  15. mesh = setup->mesh;
  16. auxdata = (cmscp_auxdata*)setup->auxdata;
  17. scales = auxdata->scales;
  18. // 存储积分轨迹的变量
  19. integTraj = (cmscp_integTraj**)malloc(numPhase * sizeof(cmscp_integTraj*));
  20. // 第1段:调姿
  21. iphase = 0;
  22. outStepSize = 5.0 / scales->time; // 输出数据的步长,每经过outputStep输出一个数据
  23. integStepSize = 1 / scales->time; // 积分步长
  24. // 分配积分轨迹的空间
  25. maxNumNode = 500;
  26. numState = 8;
  27. numControl = 2;
  28. integTraj[iphase] = (cmscp_integTraj*)malloc(sizeof(cmscp_integTraj));
  29. integTraj[iphase]->state = (demat*)malloc(sizeof(demat));
  30. integTraj[iphase]->state->m = numState;
  31. integTraj[iphase]->state->n = maxNumNode;
  32. integTraj[iphase]->state->v = (double*)malloc(numState * maxNumNode * sizeof(double));
  33. integTraj[iphase]->control = (demat*)malloc(sizeof(demat));
  34. integTraj[iphase]->control->m = numControl;
  35. integTraj[iphase]->control->n = maxNumNode;
  36. integTraj[iphase]->control->v = (double*)malloc(numControl * maxNumNode * sizeof(double));
  37. integTraj[iphase]->time = (double*)malloc(maxNumNode * sizeof(double));
  38. // 初始状态和控制输入
  39. copyFloatVec(auxdata->x0, oldState, 8, 0);
  40. u[0] = 0.0;
  41. u[1] = 0.0;
  42. // 保存初始点参数
  43. cnt = 0;
  44. stateK = integTraj[iphase]->state->v;
  45. controlK = integTraj[iphase]->control->v;
  46. copyFloatVec(oldState, stateK, numState, 0);
  47. copyFloatVec(u, controlK, numControl, 0);
  48. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  49. outTime = oldState[numState - 1] + outStepSize;
  50. isOutput = 0;
  51. // 动力学积分
  52. isIntegOver = 0;
  53. while (isIntegOver == 0)
  54. {
  55. // 控制输入
  56. u[0] = 0.0;
  57. u[1] = 0.0;
  58. // 更新状态
  59. computeInteg(newState, dynInteg2, oldState, u, NULL, auxdata, 8, 2, 0, 5, tempWork, integStepSize, 3);
  60. copyFloatVec(newState, oldState, numState, 0);
  61. dynInteg2(NULL, path, oldState, u, NULL, auxdata);
  62. // 积分结束标志位
  63. if (fabs(oldState[numState - 1] - auxdata->x0[7]) > 30 / scales->time || oldState[numState - 1] > 2000 / scales->time)
  64. {
  65. isIntegOver = 1;
  66. }
  67. // 更新输出标志位
  68. if ((fabs(outTime - oldState[numState - 1]) <= 0.5 * integStepSize) || isIntegOver)
  69. {
  70. isOutput = 1;
  71. outTime = outTime + outStepSize;
  72. }
  73. // 保存状态、控制和约束值
  74. if (isOutput == 1)
  75. {
  76. cnt = cnt + 1;
  77. stateK = stateK + numState;
  78. controlK = controlK + numControl;
  79. copyFloatVec(oldState, stateK, numState, 0);
  80. copyFloatVec(u, controlK, numControl, 0);
  81. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  82. isOutput = 0;
  83. if (isIntegOver == 1)
  84. {
  85. integTraj[iphase]->length = cnt + 1;
  86. }
  87. }
  88. }
  89. // 第2段:调姿
  90. iphase = 1;
  91. outStepSize = 5.0 / scales->time; // 输出数据的步长,每经过outputStep输出一个数据
  92. integStepSize = 1 / scales->time; // 积分步长
  93. // 分配积分轨迹的空间
  94. maxNumNode = 500;
  95. numState = 8;
  96. numControl = 2;
  97. integTraj[iphase] = (cmscp_integTraj*)malloc(sizeof(cmscp_integTraj));
  98. integTraj[iphase]->state = (demat*)malloc(sizeof(demat));
  99. integTraj[iphase]->state->m = numState;
  100. integTraj[iphase]->state->n = maxNumNode;
  101. integTraj[iphase]->state->v = (double*)malloc(numState * maxNumNode * sizeof(double));
  102. integTraj[iphase]->control = (demat*)malloc(sizeof(demat));
  103. integTraj[iphase]->control->m = numControl;
  104. integTraj[iphase]->control->n = maxNumNode;
  105. integTraj[iphase]->control->v = (double*)malloc(numControl * maxNumNode * sizeof(double));
  106. integTraj[iphase]->time = (double*)malloc(maxNumNode * sizeof(double));
  107. // 初始状态和控制输入
  108. statePhaseKm1f = integTraj[iphase - 1]->state->v + (integTraj[iphase - 1]->length - 1) * integTraj[iphase - 1]->state->m;
  109. copyFloatVec(statePhaseKm1f, oldState, numState, 0);
  110. u[0] = 1.0 * auxdata->phiT0;
  111. u[1] = 1.0 * auxdata->psiT0;
  112. // 保存初始点参数
  113. cnt = 0;
  114. stateK = integTraj[iphase]->state->v;
  115. controlK = integTraj[iphase]->control->v;
  116. copyFloatVec(oldState, stateK, numState, 0);
  117. copyFloatVec(u, controlK, numControl, 0);
  118. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  119. outTime = oldState[numState - 1] + outStepSize;
  120. isOutput = 0;
  121. // 动力学积分
  122. isIntegOver = 0;
  123. while (isIntegOver == 0)
  124. {
  125. // 控制输入
  126. u[0] = 1.0 * auxdata->phiT0;
  127. u[1] = 1.0 * auxdata->psiT0;
  128. // 更新状态
  129. computeInteg(newState, dynInteg1, oldState, u, NULL, auxdata, 8, 2, 0, 5, tempWork, integStepSize, 3);
  130. copyFloatVec(newState, oldState, numState, 0);
  131. dynInteg1(NULL, path, oldState, u, NULL, auxdata);
  132. // 积分结束标志位
  133. if (fabs(oldState[3] - statePhaseKm1f[3]) > 360 / scales->speed || path[0] < 100 * 1000 / scales->length || oldState[3] > 7100 / scales->speed || oldState[numState - 1] > 2000 / scales->time)
  134. {
  135. isIntegOver = 1;
  136. }
  137. // 更新输出标志位
  138. if ((fabs(outTime - oldState[numState - 1]) <= 0.5 * integStepSize) || isIntegOver)
  139. {
  140. isOutput = 1;
  141. outTime = outTime + outStepSize;
  142. }
  143. // 保存状态、控制和约束值
  144. if (isOutput == 1)
  145. {
  146. cnt = cnt + 1;
  147. stateK = stateK + numState;
  148. controlK = controlK + numControl;
  149. copyFloatVec(oldState, stateK, numState, 0);
  150. copyFloatVec(u, controlK, numControl, 0);
  151. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  152. isOutput = 0;
  153. if (isIntegOver == 1)
  154. {
  155. integTraj[iphase]->length = cnt + 1;
  156. }
  157. }
  158. }
  159. // 第3段:调姿
  160. iphase = 2;
  161. outStepSize = 5.0 / scales->time; // 输出数据的步长,每经过outputStep输出一个数据
  162. integStepSize = 1 / scales->time; // 积分步长
  163. // 分配积分轨迹的空间
  164. maxNumNode = 500;
  165. numState = 8;
  166. numControl = 2;
  167. integTraj[iphase] = (cmscp_integTraj*)malloc(sizeof(cmscp_integTraj));
  168. integTraj[iphase]->state = (demat*)malloc(sizeof(demat));
  169. integTraj[iphase]->state->m = numState;
  170. integTraj[iphase]->state->n = maxNumNode;
  171. integTraj[iphase]->state->v = (double*)malloc(numState * maxNumNode * sizeof(double));
  172. integTraj[iphase]->control = (demat*)malloc(sizeof(demat));
  173. integTraj[iphase]->control->m = numControl;
  174. integTraj[iphase]->control->n = maxNumNode;
  175. integTraj[iphase]->control->v = (double*)malloc(numControl * maxNumNode * sizeof(double));
  176. integTraj[iphase]->time = (double*)malloc(maxNumNode * sizeof(double));
  177. // 初始状态和控制输入
  178. statePhaseKm1f = integTraj[iphase - 1]->state->v + (integTraj[iphase - 1]->length - 1) * integTraj[iphase - 1]->state->m;
  179. copyFloatVec(statePhaseKm1f, oldState, numState, 0);
  180. u[0] = 0.0;
  181. u[1] = 0.0;
  182. // 保存初始点参数
  183. cnt = 0;
  184. stateK = integTraj[iphase]->state->v;
  185. controlK = integTraj[iphase]->control->v;
  186. copyFloatVec(oldState, stateK, numState, 0);
  187. copyFloatVec(u, controlK, numControl, 0);
  188. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  189. outTime = oldState[numState - 1] + outStepSize;
  190. isOutput = 0;
  191. // 动力学积分
  192. isIntegOver = 0;
  193. while (isIntegOver == 0)
  194. {
  195. // 控制输入
  196. u[0] = 0.0;
  197. u[1] = 0.0;
  198. // 更新状态
  199. computeInteg(newState, dynInteg2, oldState, u, NULL, auxdata, 8, 2, 0, 5, tempWork, integStepSize, 3);
  200. copyFloatVec(newState, oldState, numState, 0);
  201. dynInteg2(NULL, path, oldState, u, NULL, auxdata);
  202. // 积分结束标志位
  203. if (path[0] < 95 * 1000 / scales->length || oldState[numState - 1] > 2000 / scales->time)
  204. {
  205. isIntegOver = 1;
  206. }
  207. // 更新输出标志位
  208. if ((fabs(outTime - oldState[numState - 1]) <= 0.5 * integStepSize) || isIntegOver)
  209. {
  210. isOutput = 1;
  211. outTime = outTime + outStepSize;
  212. }
  213. // 保存状态、控制和约束值
  214. if (isOutput == 1)
  215. {
  216. cnt = cnt + 1;
  217. stateK = stateK + numState;
  218. controlK = controlK + numControl;
  219. copyFloatVec(oldState, stateK, numState, 0);
  220. copyFloatVec(u, controlK, numControl, 0);
  221. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  222. isOutput = 0;
  223. if (isIntegOver == 1)
  224. {
  225. integTraj[iphase]->length = cnt + 1;
  226. }
  227. }
  228. }
  229. // 第4段:正常再入段1
  230. iphase = 3;
  231. outStepSize = 4.0 / scales->time; // 输出数据的步长,每经过outputStep输出一个数据
  232. integStepSize = 1 / scales->time; // 积分步长
  233. // 分配积分轨迹的空间
  234. maxNumNode = 500;
  235. numState = 8;
  236. numControl = 1;
  237. integTraj[iphase] = (cmscp_integTraj*)malloc(sizeof(cmscp_integTraj));
  238. integTraj[iphase]->state = (demat*)malloc(sizeof(demat));
  239. integTraj[iphase]->state->m = numState;
  240. integTraj[iphase]->state->n = maxNumNode;
  241. integTraj[iphase]->state->v = (double*)malloc(numState * maxNumNode * sizeof(double));
  242. integTraj[iphase]->control = (demat*)malloc(sizeof(demat));
  243. integTraj[iphase]->control->m = numControl;
  244. integTraj[iphase]->control->n = maxNumNode;
  245. integTraj[iphase]->control->v = (double*)malloc(numControl * maxNumNode * sizeof(double));
  246. integTraj[iphase]->time = (double*)malloc(maxNumNode * sizeof(double));
  247. // 初始状态和控制输入
  248. statePhaseKm1f = integTraj[iphase - 1]->state->v + (integTraj[iphase - 1]->length - 1) * integTraj[iphase - 1]->state->m;
  249. copyFloatVec(statePhaseKm1f, oldState, numState, 0);
  250. oldState[6] = auxdata->mass2 / scales->mass;
  251. u[0] = -20.0 * d2r;
  252. // 保存初始点参数
  253. cnt = 0;
  254. stateK = integTraj[iphase]->state->v;
  255. controlK = integTraj[iphase]->control->v;
  256. copyFloatVec(oldState, stateK, numState, 0);
  257. copyFloatVec(u, controlK, numControl, 0);
  258. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  259. outTime = oldState[numState - 1] + outStepSize;
  260. isOutput = 0;
  261. // 动力学积分
  262. isIntegOver = 0;
  263. while (isIntegOver == 0)
  264. {
  265. // 控制输入
  266. u[0] = -20.0 * d2r;
  267. // 更新状态
  268. computeInteg(newState, dynInteg3, oldState, u, NULL, auxdata, 8, 2, 0, 5, tempWork, integStepSize, 3);
  269. copyFloatVec(newState, oldState, numState, 0);
  270. dynInteg3(NULL, path, oldState, u, NULL, auxdata);
  271. // 积分结束标志位
  272. if (oldState[3] < 4 * 1000 / scales->speed || oldState[numState - 1] > 2000 / scales->time)
  273. {
  274. isIntegOver = 1;
  275. }
  276. // 更新输出标志位
  277. if ((fabs(outTime - oldState[numState - 1]) <= 0.5 * integStepSize) || isIntegOver)
  278. {
  279. isOutput = 1;
  280. outTime = outTime + outStepSize;
  281. }
  282. // 保存状态、控制和约束值
  283. if (isOutput == 1)
  284. {
  285. cnt = cnt + 1;
  286. stateK = stateK + numState;
  287. controlK = controlK + numControl;
  288. copyFloatVec(oldState, stateK, numState, 0);
  289. copyFloatVec(u, controlK, numControl, 0);
  290. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  291. isOutput = 0;
  292. if (isIntegOver == 1)
  293. {
  294. integTraj[iphase]->length = cnt + 1;
  295. }
  296. }
  297. }
  298. // 第5段:正常再入段2
  299. iphase = 4;
  300. outStepSize = 5.0 / scales->time; // 输出数据的步长,每经过outputStep输出一个数据
  301. integStepSize = 1 / scales->time; // 积分步长
  302. // 分配积分轨迹的空间
  303. maxNumNode = 200;
  304. numState = 8;
  305. numControl = 1;
  306. integTraj[iphase] = (cmscp_integTraj*)malloc(sizeof(cmscp_integTraj));
  307. integTraj[iphase]->state = (demat*)malloc(sizeof(demat));
  308. integTraj[iphase]->state->m = numState;
  309. integTraj[iphase]->state->n = maxNumNode;
  310. integTraj[iphase]->state->v = (double*)malloc(numState * maxNumNode * sizeof(double));
  311. integTraj[iphase]->control = (demat*)malloc(sizeof(demat));
  312. integTraj[iphase]->control->m = numControl;
  313. integTraj[iphase]->control->n = maxNumNode;
  314. integTraj[iphase]->control->v = (double*)malloc(numControl * maxNumNode * sizeof(double));
  315. integTraj[iphase]->time = (double*)malloc(maxNumNode * sizeof(double));
  316. // 初始状态和控制输入
  317. statePhaseKm1f = integTraj[iphase - 1]->state->v + (integTraj[iphase - 1]->length - 1) * integTraj[iphase - 1]->state->m;
  318. copyFloatVec(statePhaseKm1f, oldState, numState, 0);
  319. u[0] = 20.0 * d2r;
  320. // 保存初始点参数
  321. cnt = 0;
  322. stateK = integTraj[iphase]->state->v;
  323. controlK = integTraj[iphase]->control->v;
  324. copyFloatVec(oldState, stateK, numState, 0);
  325. copyFloatVec(u, controlK, numControl, 0);
  326. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  327. outTime = oldState[numState - 1] + outStepSize;
  328. isOutput = 0;
  329. // 动力学积分
  330. isIntegOver = 0;
  331. while (isIntegOver == 0)
  332. {
  333. // 控制输入
  334. u[0] = 20.0 * d2r;
  335. // 更新状态
  336. computeInteg(newState, dynInteg3, oldState, u, NULL, auxdata, 8, 2, 0, 5, tempWork, integStepSize, 3);
  337. copyFloatVec(newState, oldState, numState, 0);
  338. dynInteg3(NULL, path, oldState, u, NULL, auxdata);
  339. // 积分结束标志位
  340. if (path[0] < 8 * 1000 / scales->length || oldState[numState - 1] > 2000 / scales->time)
  341. {
  342. isIntegOver = 1;
  343. }
  344. // 更新输出标志位
  345. if ((fabs(outTime - oldState[numState - 1]) <= 0.5 * integStepSize) || isIntegOver)
  346. {
  347. isOutput = 1;
  348. outTime = outTime + outStepSize;
  349. }
  350. // 保存状态、控制和约束值
  351. if (isOutput == 1)
  352. {
  353. cnt = cnt + 1;
  354. stateK = stateK + numState;
  355. controlK = controlK + numControl;
  356. copyFloatVec(oldState, stateK, numState, 0);
  357. copyFloatVec(u, controlK, numControl, 0);
  358. integTraj[iphase]->time[cnt] = stateK[numState - 1];
  359. isOutput = 0;
  360. if (isIntegOver == 1)
  361. {
  362. integTraj[iphase]->length = cnt + 1;
  363. }
  364. }
  365. }
  366. // 插值获取参考轨迹
  367. for (iphase = 0; iphase < numPhase; iphase++)
  368. {
  369. numMesh = mesh[iphase]->num;
  370. numState = dimension->phase[iphase]->state;
  371. numControl = dimension->phase[iphase]->control;
  372. numParameter = dimension->phase[iphase]->parameter;
  373. meshNode = mesh[iphase]->node;
  374. length = integTraj[iphase]->length;
  375. integNumState = integTraj[iphase]->state->m;
  376. integState0 = integTraj[iphase]->state->v;
  377. integStatef = integTraj[iphase]->state->v + (length - 1) * integNumState;
  378. integNumControl = integTraj[iphase]->control->m;
  379. integControl0 = integTraj[iphase]->control->v;
  380. integControlf = integTraj[iphase]->control->v + (length - 1) * integNumControl;
  381. refTraj[iphase] = (cmscp_trajInfo*)malloc(sizeof(cmscp_trajInfo));
  382. refTraj[iphase]->state = (cmscp_floatDemat*)malloc(sizeof(cmscp_floatDemat));
  383. refTraj[iphase]->state->m = numState;
  384. refTraj[iphase]->state->n = numMesh;
  385. refTraj[iphase]->state->v = (double*)malloc(numState * numMesh * sizeof(double));
  386. refTraj[iphase]->control = (cmscp_floatDemat*)malloc(sizeof(cmscp_floatDemat));
  387. refTraj[iphase]->control->m = numControl;
  388. refTraj[iphase]->control->n = numMesh;
  389. refTraj[iphase]->control->v = (double*)malloc(numControl * numMesh * sizeof(double));
  390. refTraj[iphase]->parameter = (double*)malloc(numParameter * sizeof(double));
  391. refTraj[iphase]->initialtime = integState0[numState - 1];
  392. refTraj[iphase]->finaltime = integStatef[numState - 1];
  393. denseScaPlusVec(integTraj[iphase]->time, -refTraj[iphase]->initialtime, integTraj[iphase]->time, length);
  394. denseScaV(integTraj[iphase]->time, 1.0 / (refTraj[iphase]->finaltime - refTraj[iphase]->initialtime), integTraj[iphase]->time, length);
  395. ascLinearInterp(integTraj[iphase]->time,
  396. integTraj[iphase]->state->v,
  397. length, integNumState,
  398. meshNode, numMesh, refTraj[iphase]->state->v);
  399. ascLinearInterp(integTraj[iphase]->time,
  400. integTraj[iphase]->control->v, length,
  401. integNumControl,
  402. meshNode,
  403. numMesh, refTraj[iphase]->control->v);
  404. floatVecFillin(refTraj[iphase]->parameter, numParameter, 0.0);
  405. free(integTraj[iphase]->time);
  406. free(integTraj[iphase]->control->v);
  407. free(integTraj[iphase]->control);
  408. free(integTraj[iphase]->state->v);
  409. free(integTraj[iphase]->state);
  410. free(integTraj[iphase]);
  411. }
  412. free(integTraj);
  413. // 范围限制
  414. for (iphase = 0; iphase < numPhase; iphase++)
  415. {
  416. // 每段维度
  417. numMesh = mesh[iphase]->num;
  418. numState = dimension->phase[iphase]->state;
  419. numControl = dimension->phase[iphase]->control;
  420. numParameter = dimension->phase[iphase]->parameter;
  421. meshNode = mesh[iphase]->node;
  422. // 初始时间限制
  423. if (refTraj[iphase]->initialtime > setup->bounds->phase[iphase]->initialtime->upper)
  424. {
  425. refTraj[iphase]->initialtime = setup->bounds->phase[iphase]->initialtime->upper;
  426. }
  427. else if(refTraj[iphase]->initialtime < setup->bounds->phase[iphase]->initialtime->lower)
  428. {
  429. refTraj[iphase]->initialtime = setup->bounds->phase[iphase]->initialtime->lower;
  430. }
  431. // 终端时间限制
  432. if (refTraj[iphase]->finaltime > setup->bounds->phase[iphase]->finaltime->upper)
  433. {
  434. refTraj[iphase]->initialtime = setup->bounds->phase[iphase]->finaltime->upper;
  435. }
  436. else if (refTraj[iphase]->finaltime < setup->bounds->phase[iphase]->finaltime->lower)
  437. {
  438. refTraj[iphase]->finaltime = setup->bounds->phase[iphase]->finaltime->lower;
  439. }
  440. // 状态变量限制
  441. for ( i = 0; i < numState; i++)
  442. {
  443. ij = i + numState * 0;
  444. if (refTraj[iphase]->state->v[ij] > setup->bounds->phase[iphase]->initialstate->upper[i])
  445. {
  446. refTraj[iphase]->state->v[ij] = setup->bounds->phase[iphase]->initialstate->upper[i];
  447. }
  448. else if (refTraj[iphase]->state->v[ij] < setup->bounds->phase[iphase]->initialstate->lower[i])
  449. {
  450. refTraj[iphase]->state->v[ij] = setup->bounds->phase[iphase]->initialstate->lower[i];
  451. }
  452. ij = i + numState * (numMesh -1);
  453. if (refTraj[iphase]->state->v[ij] > setup->bounds->phase[iphase]->finalstate->upper[i])
  454. {
  455. refTraj[iphase]->state->v[ij] = setup->bounds->phase[iphase]->finalstate->upper[i];
  456. }
  457. else if (refTraj[iphase]->state->v[ij] < setup->bounds->phase[iphase]->finalstate->lower[i])
  458. {
  459. refTraj[iphase]->state->v[ij] = setup->bounds->phase[iphase]->finalstate->lower[i];
  460. }
  461. for (k = 1; k < numMesh-1; k++)
  462. {
  463. ij = i + numState * k;
  464. if (refTraj[iphase]->state->v[ij] > setup->bounds->phase[iphase]->state->upper[i])
  465. {
  466. refTraj[iphase]->state->v[ij] = setup->bounds->phase[iphase]->state->upper[i];
  467. }
  468. else if (refTraj[iphase]->state->v[ij] < setup->bounds->phase[iphase]->state->lower[i])
  469. {
  470. refTraj[iphase]->state->v[ij] = setup->bounds->phase[iphase]->state->lower[i];
  471. }
  472. }
  473. }
  474. // 控制变量限制
  475. for (i = 0; i < numControl; i++)
  476. {
  477. for (k = 0; k < numMesh; k++)
  478. {
  479. ij = i + numControl * k;
  480. if (refTraj[iphase]->control->v[ij] > setup->bounds->phase[iphase]->control->upper[i])
  481. {
  482. refTraj[iphase]->control->v[ij] = setup->bounds->phase[iphase]->control->upper[i];
  483. }
  484. else if (refTraj[iphase]->control->v[ij] < setup->bounds->phase[iphase]->control->lower[i])
  485. {
  486. refTraj[iphase]->control->v[ij] = setup->bounds->phase[iphase]->control->lower[i];
  487. }
  488. }
  489. }
  490. // 静态参数变量限制
  491. for (i = 0; i < numParameter; i++)
  492. {
  493. if (refTraj[iphase]->parameter[i] > setup->bounds->phase[iphase]->parameter->upper[i])
  494. {
  495. refTraj[iphase]->parameter[i] = setup->bounds->phase[iphase]->parameter->upper[i];
  496. }
  497. else if (refTraj[iphase]->parameter[i] < setup->bounds->phase[iphase]->parameter->lower[i])
  498. {
  499. refTraj[iphase]->parameter[i] = setup->bounds->phase[iphase]->parameter->lower[i];
  500. }
  501. }
  502. }
  503. }
  504. int stopCondition(int iIter, cmscp_trajInfo** refTraj, cmscp_trajInfo** optTraj, cmscp_setup* setup)
  505. {
  506. int numPhase, iphase, numMesh, numState, j, stopFlag;
  507. double maxHeightErr, * optStateK, * refStateK;
  508. cmscp_auxdata* auxdata;
  509. cmscp_scales* scales;
  510. numPhase = setup->numPhase;
  511. auxdata = (cmscp_auxdata*)setup->auxdata;
  512. scales = auxdata->scales;
  513. maxHeightErr = 0.0;
  514. for (iphase = 0; iphase < numPhase; iphase++)
  515. {
  516. numMesh = setup->mesh[iphase]->num;
  517. numState = setup->dimension->phase[iphase]->state;
  518. for (j = 0; j < numMesh; j++)
  519. {
  520. optStateK = optTraj[iphase]->state->v + j * numState;
  521. refStateK = refTraj[iphase]->state->v + j * numState;
  522. maxHeightErr = fmax(maxHeightErr, fabs(optStateK[0] - refStateK[0]));
  523. }
  524. }
  525. maxHeightErr = maxHeightErr * scales->length;
  526. if (maxHeightErr <= 2000)
  527. {
  528. stopFlag = 1;
  529. }
  530. else if (iIter == setup->scpInfo->maxIter - 1)
  531. {
  532. stopFlag = 2;
  533. }
  534. else
  535. {
  536. stopFlag = 0;
  537. }
  538. return stopFlag;
  539. }
  540. void updateMeshInfo(int iIter, cmscp_trajInfo** refTraj, cmscp_trajInfo** optTraj, cmscp_setup* setup)
  541. {
  542. int numPhase, iphase;
  543. cmscp_mesh**newMesh, ** oldMesh;
  544. numPhase = setup->numPhase;
  545. // 网格更新
  546. setup->oldMesh = setup->mesh;
  547. setup->mesh = (cmscp_mesh**)malloc(numPhase * sizeof(cmscp_mesh*));
  548. newMesh = setup->mesh;
  549. oldMesh = setup->oldMesh;
  550. for (iphase = 0; iphase < numPhase; iphase++)
  551. {
  552. newMesh[iphase] = (cmscp_mesh*)malloc(sizeof(cmscp_mesh));
  553. newMesh[iphase]->num = oldMesh[iphase]->num;
  554. newMesh[iphase]->node = (double*)malloc(newMesh[iphase]->num * sizeof(double));
  555. copyFloatVec(oldMesh[iphase]->node, newMesh[iphase]->node, newMesh[iphase]->num, 0);
  556. }
  557. }
  558. void updateTrustInfo(int iIter, cmscp_trajInfo** refTraj, cmscp_trajInfo** optTraj, cmscp_setup* setup)
  559. {
  560. int numPhase, iphase;
  561. double delta;
  562. numPhase = setup->numPhase;
  563. if (iIter == 0)
  564. {
  565. setup->trust->merit = 1E30;
  566. }
  567. if (iIter >= 5)
  568. {
  569. if (setup->trust->merit > 1E-4)
  570. {
  571. setup->trust->merit = fabs(setup->scpInfo->obj[iIter] - setup->scpInfo->obj[iIter - 2]) / fmax(fabs(setup->scpInfo->obj[iIter]), 2);
  572. }
  573. else
  574. {
  575. setup->trust->merit = 0;
  576. }
  577. }
  578. if (setup->trust->merit <= 5E-4) {
  579. for ( iphase = 0; iphase < numPhase; iphase++)
  580. {
  581. setup->trust->phase[iphase]->hardRadius = setup->trust->phase[iphase]->hardRadius / 2;
  582. }
  583. }
  584. else
  585. {
  586. if(iIter <= 9) {
  587. for (iphase = 0; iphase < numPhase; iphase++)
  588. {
  589. setup->trust->phase[iphase]->hardRadius = 0.5 + (0.1 - 0.5) / 10 * (iIter + 1);
  590. }
  591. }
  592. }
  593. for (iphase = 0; iphase < numPhase; iphase++)
  594. {
  595. if (setup->trust->phase[iphase]->hardRadius <= 0.05)
  596. {
  597. setup->trust->phase[iphase]->hardRadius = 0.05;
  598. if (setup->trust->merit <= 1E-4 && iphase == 0)
  599. {
  600. setup->trust->model = "soft";
  601. }
  602. }
  603. }
  604. }
  605. void updateRefTraj(cmscp_trajInfo** refTraj, cmscp_trajInfo** optTraj, cmscp_setup* setup)
  606. {
  607. int iphase, numPhase, oldNumMesh, newNumMesh, numState, numControl, numParameter;
  608. double* oldMeshNode, *newMeshNode;
  609. cmscp_mesh** oldMesh, ** newMesh;
  610. cmscp_dimension* dimension;
  611. oldMesh = setup->mesh;
  612. newMesh = setup->mesh;
  613. numPhase = setup->numPhase;
  614. dimension = setup->dimension;
  615. // 插值获取参考轨迹
  616. for (iphase = 0; iphase < numPhase; iphase++)
  617. {
  618. oldNumMesh = oldMesh[iphase]->num;
  619. oldMeshNode = oldMesh[iphase]->node;
  620. newNumMesh = newMesh[iphase]->num;
  621. newMeshNode = newMesh[iphase]->node;
  622. numState = dimension->phase[iphase]->state;
  623. numControl = dimension->phase[iphase]->control;
  624. numParameter = dimension->phase[iphase]->parameter;
  625. // 释放之前的空间
  626. freeTrajInfoPhase(refTraj, setup, iphase);
  627. // 重新申请空间
  628. refTraj[iphase] = (cmscp_trajInfo*)malloc(sizeof(cmscp_trajInfo));
  629. refTraj[iphase]->state = (cmscp_floatDemat*)malloc(sizeof(cmscp_floatDemat));
  630. refTraj[iphase]->state->m = numState;
  631. refTraj[iphase]->state->n = newNumMesh;
  632. refTraj[iphase]->state->v = (double*)malloc(numState * newNumMesh * sizeof(double));
  633. refTraj[iphase]->control = (cmscp_floatDemat*)malloc(sizeof(cmscp_floatDemat));
  634. refTraj[iphase]->control->m = numControl;
  635. refTraj[iphase]->control->n = newNumMesh;
  636. refTraj[iphase]->control->v = (double*)malloc(numControl * newNumMesh * sizeof(double));
  637. refTraj[iphase]->parameter = (double*)malloc(numParameter * sizeof(double));
  638. ascLinearInterp(oldMeshNode,
  639. optTraj[iphase]->state->v,
  640. oldNumMesh, numState,
  641. newMeshNode, newNumMesh, refTraj[iphase]->state->v);
  642. ascLinearInterp(oldMeshNode,
  643. optTraj[iphase]->control->v,
  644. oldNumMesh, numControl,
  645. newMeshNode, newNumMesh, refTraj[iphase]->control->v);
  646. copyFloatVec(optTraj[iphase]->parameter, refTraj[iphase]->parameter, numParameter, 0);
  647. refTraj[iphase]->initialtime = optTraj[iphase]->initialtime;
  648. refTraj[iphase]->finaltime = optTraj[iphase]->finaltime;
  649. }
  650. // 释放旧网格
  651. for (iphase = 0; iphase < numPhase; iphase++)
  652. {
  653. free(setup->oldMesh[iphase]->node);
  654. free(setup->oldMesh[iphase]);
  655. }
  656. free(setup->oldMesh);
  657. // 释放最优轨迹
  658. freeTrajInfo(optTraj, setup, 0);
  659. }
  660. void getObjEventDepend(intDemat* dependMatrix)
  661. {
  662. // 函数功能:获取事先准备目标函数和事件函数的相关性矩阵
  663. // 输入:
  664. // dependMatrix:没有存储相关性矩阵的地址
  665. // 输出:
  666. // dependMatrix:存储相关性矩阵的地址
  667. // 谢磊:2022 / 6 / 25编写
  668. int i, j, numRow, numCol, * dependMatrixJ;
  669. // 第1段
  670. numRow = 1;
  671. numCol = 100;
  672. dependMatrix->m = numRow;
  673. dependMatrix->n = numCol;
  674. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  675. dependMatrixJ = dependMatrix->v;
  676. for (j = 0; j < numCol; j++)
  677. {
  678. for (i = 0; i < numRow; i++)
  679. {
  680. if ((i == 0 && j == 98) || (i == 0 && j == 99))
  681. {
  682. dependMatrixJ[i] = 1;
  683. }
  684. else
  685. {
  686. dependMatrixJ[i] = 0;
  687. }
  688. }
  689. dependMatrixJ = dependMatrixJ + numRow;
  690. }
  691. }
  692. void getContDepend(intDemat* dependMatrix, int iphase, cmscp_setup* setup)
  693. {
  694. // 函数功能:获取事先准备时间连续函数的相关性矩阵
  695. // 输入:
  696. // dependMatrix:没有存储相关性矩阵的地址
  697. // iphase:需要的是第几段的相关性矩阵
  698. // setup:问题的设置参数
  699. // 输出:
  700. // dependMatrix:存储相关性矩阵的地址
  701. // 谢磊:2022 / 6 / 25编写
  702. int a1[11][12] = {
  703. {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
  704. {1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  705. {1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  706. {1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0},
  707. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  708. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  709. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  710. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  711. {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  712. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0},
  713. {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
  714. };
  715. int a2[11][12] = {
  716. {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
  717. {1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  718. {1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  719. {1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0},
  720. {1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  721. {1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  722. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  723. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  724. {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  725. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0},
  726. {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
  727. };
  728. int a3[11][10] = {
  729. {0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
  730. {1, 0, 1, 1, 1, 1, 0, 0, 0, 0},
  731. {1, 0, 0, 1, 1, 1, 0, 0, 0, 0},
  732. {1, 0, 1, 1, 1, 1, 1, 0, 0, 0},
  733. {1, 0, 1, 1, 1, 1, 1, 0, 1, 0},
  734. {1, 0, 1, 1, 1, 1, 0, 0, 1, 0},
  735. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  736. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  737. {1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
  738. {1, 0, 1, 1, 0, 0, 1, 0, 0, 0},
  739. {0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
  740. };
  741. int a4[11][12] = {
  742. {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
  743. {1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  744. {1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  745. {1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
  746. {1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0},
  747. {1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0},
  748. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  749. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  750. {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  751. {1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0},
  752. {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
  753. };
  754. int i, j, numRow, numCol, numPhase, * dependMatrixJ, numState;
  755. numPhase = 5;
  756. if (iphase == 0)
  757. {
  758. // 第1段
  759. numRow = 11;
  760. numCol = 12;
  761. numState = setup->dimension->phase[iphase]->state;
  762. dependMatrix->m = numRow;
  763. dependMatrix->n = numCol;
  764. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  765. dependMatrixJ = dependMatrix->v;
  766. for (j = 0; j < numCol; j++)
  767. {
  768. for (i = 0; i < numRow; i++)
  769. {
  770. if (i < numState && i == j)
  771. {
  772. dependMatrixJ[i] = 1;
  773. }
  774. else
  775. {
  776. dependMatrixJ[i] = a2[i][j];
  777. }
  778. }
  779. dependMatrixJ = dependMatrixJ + numRow;
  780. }
  781. }
  782. else if (iphase == 1)
  783. {
  784. // 第2段
  785. numRow = 11;
  786. numCol = 12;
  787. numState = setup->dimension->phase[iphase]->state;
  788. dependMatrix->m = numRow;
  789. dependMatrix->n = numCol;
  790. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  791. dependMatrixJ = dependMatrix->v;
  792. for (j = 0; j < numCol; j++)
  793. {
  794. for (i = 0; i < numRow; i++)
  795. {
  796. if (i < numState && i == j)
  797. {
  798. dependMatrixJ[i] = 1;
  799. }
  800. else
  801. {
  802. dependMatrixJ[i] = a1[i][j];
  803. }
  804. }
  805. dependMatrixJ = dependMatrixJ + numRow;
  806. }
  807. }
  808. else if (iphase == 2)
  809. {
  810. // 第3段
  811. numRow = 11;
  812. numCol = 12;
  813. numState = setup->dimension->phase[iphase]->state;
  814. dependMatrix->m = numRow;
  815. dependMatrix->n = numCol;
  816. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  817. dependMatrixJ = dependMatrix->v;
  818. for (j = 0; j < numCol; j++)
  819. {
  820. for (i = 0; i < numRow; i++)
  821. {
  822. if (i < numState && i == j)
  823. {
  824. dependMatrixJ[i] = 1;
  825. }
  826. else
  827. {
  828. dependMatrixJ[i] = a2[i][j];
  829. }
  830. }
  831. dependMatrixJ = dependMatrixJ + numRow;
  832. }
  833. }
  834. else if (iphase == 3)
  835. {
  836. // 第4段
  837. numRow = 11;
  838. numCol = 10;
  839. numState = setup->dimension->phase[iphase]->state;
  840. dependMatrix->m = numRow;
  841. dependMatrix->n = numCol;
  842. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  843. dependMatrixJ = dependMatrix->v;
  844. for (j = 0; j < numCol; j++)
  845. {
  846. for (i = 0; i < numRow; i++)
  847. {
  848. if (i < numState && i == j)
  849. {
  850. dependMatrixJ[i] = 1;
  851. }
  852. else
  853. {
  854. dependMatrixJ[i] = a3[i][j];
  855. }
  856. };
  857. dependMatrixJ = dependMatrixJ + numRow;
  858. }
  859. }
  860. else if (iphase == 4)
  861. {
  862. // 第5段
  863. numRow = 11;
  864. numCol = 12;
  865. numState = setup->dimension->phase[iphase]->state;
  866. dependMatrix->m = numRow;
  867. dependMatrix->n = numCol;
  868. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  869. dependMatrixJ = dependMatrix->v;
  870. for (j = 0; j < numCol; j++)
  871. {
  872. for (i = 0; i < numRow; i++)
  873. {
  874. if (i < numState && i == j)
  875. {
  876. dependMatrixJ[i] = 1;
  877. }
  878. else
  879. {
  880. dependMatrixJ[i] = a4[i][j];
  881. }
  882. }
  883. dependMatrixJ = dependMatrixJ + numRow;
  884. }
  885. }
  886. }
  887. void getEndpDepend(intDemat* dependMatrix, int iphase, cmscp_setup* setup)
  888. {
  889. int a1[3][20] = {
  890. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
  891. {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  892. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0},
  893. };
  894. int a2[5][20] = {
  895. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
  896. {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  897. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0},
  898. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  899. {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  900. };
  901. int a3[4][20] = {
  902. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  903. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
  904. {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  905. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0},
  906. };
  907. int a4[4][19] = {
  908. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  909. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0},
  910. {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
  911. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0}
  912. };
  913. int a5[8][21] = {
  914. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  915. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0},
  916. {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
  917. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0},
  918. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  919. {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  920. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  921. {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  922. };
  923. int i, j, numRow, numCol, numPhase, * dependMatrixJ;
  924. numPhase = 5;
  925. if (iphase == 0)
  926. {
  927. // 第1段
  928. numRow = 3;
  929. numCol = 20;
  930. dependMatrix->m = numRow;
  931. dependMatrix->n = numCol;
  932. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  933. dependMatrixJ = dependMatrix->v;
  934. for (j = 0; j < numCol; j++)
  935. {
  936. for (i = 0; i < numRow; i++)
  937. {
  938. dependMatrixJ[i] = a1[i][j];
  939. }
  940. dependMatrixJ = dependMatrixJ + numRow;
  941. }
  942. }
  943. else if (iphase == 1)
  944. {
  945. // 第2段
  946. numRow = 5;
  947. numCol = 20;
  948. dependMatrix->m = numRow;
  949. dependMatrix->n = numCol;
  950. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  951. dependMatrixJ = dependMatrix->v;
  952. for (j = 0; j < numCol; j++)
  953. {
  954. for (i = 0; i < numRow; i++)
  955. {
  956. dependMatrixJ[i] = a2[i][j];
  957. }
  958. dependMatrixJ = dependMatrixJ + numRow;
  959. }
  960. }
  961. else if (iphase == 2)
  962. {
  963. // 第3段
  964. numRow = 4;
  965. numCol = 20;
  966. dependMatrix->m = numRow;
  967. dependMatrix->n = numCol;
  968. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  969. dependMatrixJ = dependMatrix->v;
  970. for (j = 0; j < numCol; j++)
  971. {
  972. for (i = 0; i < numRow; i++)
  973. {
  974. dependMatrixJ[i] = a3[i][j];
  975. }
  976. dependMatrixJ = dependMatrixJ + numRow;
  977. }
  978. }
  979. else if (iphase == 3)
  980. {
  981. // 第4段
  982. numRow = 4;
  983. numCol = 19;
  984. dependMatrix->m = numRow;
  985. dependMatrix->n = numCol;
  986. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  987. dependMatrixJ = dependMatrix->v;
  988. for (j = 0; j < numCol; j++)
  989. {
  990. for (i = 0; i < numRow; i++)
  991. {
  992. dependMatrixJ[i] = a4[i][j];
  993. }
  994. dependMatrixJ = dependMatrixJ + numRow;
  995. }
  996. }
  997. else if (iphase == 4)
  998. {
  999. // 第5段
  1000. numRow = 8;
  1001. numCol = 21;
  1002. dependMatrix->m = numRow;
  1003. dependMatrix->n = numCol;
  1004. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  1005. dependMatrixJ = dependMatrix->v;
  1006. for (j = 0; j < numCol; j++)
  1007. {
  1008. for (i = 0; i < numRow; i++)
  1009. {
  1010. dependMatrixJ[i] = a5[i][j];
  1011. }
  1012. dependMatrixJ = dependMatrixJ + numRow;
  1013. }
  1014. }
  1015. }
  1016. void getLinkDepend(intDemat* dependMatrix, int iphase, cmscp_setup* setup)
  1017. {
  1018. int a1[8][22] = {
  1019. {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1020. {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1021. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  1022. {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
  1023. {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
  1024. {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  1025. {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
  1026. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
  1027. };
  1028. int a2[8][22] = {
  1029. {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1030. {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1031. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  1032. {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
  1033. {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
  1034. {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  1035. {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
  1036. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
  1037. };
  1038. int a3[7][21] = {
  1039. {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1040. {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  1041. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
  1042. {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
  1043. {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  1044. {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
  1045. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  1046. };
  1047. int a4[8][22] = {
  1048. {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1049. {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1050. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1051. {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  1052. {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
  1053. {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
  1054. {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  1055. {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  1056. };
  1057. int i, j, numRow, numCol, numPhase, * dependMatrixJ;
  1058. numPhase = 5;
  1059. if (iphase == 0)
  1060. {
  1061. // 第1段
  1062. numRow = 8;
  1063. numCol = 22;
  1064. dependMatrix->m = numRow;
  1065. dependMatrix->n = numCol;
  1066. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  1067. dependMatrixJ = dependMatrix->v;
  1068. for (j = 0; j < numCol; j++)
  1069. {
  1070. for (i = 0; i < numRow; i++)
  1071. {
  1072. dependMatrixJ[i] = a1[i][j];
  1073. }
  1074. dependMatrixJ = dependMatrixJ + numRow;
  1075. }
  1076. }
  1077. else if (iphase == 1)
  1078. {
  1079. // 第2段
  1080. numRow = 8;
  1081. numCol = 22;
  1082. dependMatrix->m = numRow;
  1083. dependMatrix->n = numCol;
  1084. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  1085. dependMatrixJ = dependMatrix->v;
  1086. for (j = 0; j < numCol; j++)
  1087. {
  1088. for (i = 0; i < numRow; i++)
  1089. {
  1090. dependMatrixJ[i] = a2[i][j];
  1091. }
  1092. dependMatrixJ = dependMatrixJ + numRow;
  1093. }
  1094. }
  1095. else if (iphase == 2)
  1096. {
  1097. // 第3段
  1098. numRow = 7;
  1099. numCol = 21;
  1100. dependMatrix->m = numRow;
  1101. dependMatrix->n = numCol;
  1102. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  1103. dependMatrixJ = dependMatrix->v;
  1104. for (j = 0; j < numCol; j++)
  1105. {
  1106. for (i = 0; i < numRow; i++)
  1107. {
  1108. dependMatrixJ[i] = a3[i][j];
  1109. }
  1110. dependMatrixJ = dependMatrixJ + numRow;
  1111. }
  1112. }
  1113. else if (iphase == 3)
  1114. {
  1115. // 第4段
  1116. numRow = 8;
  1117. numCol = 22;
  1118. dependMatrix->m = numRow;
  1119. dependMatrix->n = numCol;
  1120. dependMatrix->v = (int*)malloc(numRow * numCol * sizeof(int));
  1121. dependMatrixJ = dependMatrix->v;
  1122. for (j = 0; j < numCol; j++)
  1123. {
  1124. for (i = 0; i < numRow; i++)
  1125. {
  1126. dependMatrixJ[i] = a4[i][j];
  1127. }
  1128. dependMatrixJ = dependMatrixJ + numRow;
  1129. }
  1130. }
  1131. }