Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #ifdef MATLAB
  2. Engine *ep;
  3. mxArray *ARGS = NULL, *QCK = NULL, *MERGE = NULL, *DUAL = NULL, *QTI = NULL, *MTI = NULL, *INS = NULL;
  4.  
  5. if (!(ep = engOpen(""))) {
  6. fprintf(stderr, "\nCan't start MATLAB engine\n");
  7. return EXIT_FAILURE;
  8. }
  9.  
  10. ARGS = mxCreateNumericMatrix(maxArraySize / step, 1, mxINT32_CLASS, mxREAL);
  11. memcpy((void *)mxGetPr(ARGS), (void *)argsArray, maxArraySize / step * sizeof(int));
  12. DUAL = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
  13. for (int i = 0; i < maxArraySize / step; ++i) {
  14. for (int j = 0; j < 4; ++j) {
  15. memcpy((void *)(mxGetPr(DUAL) + i + maxArraySize / step * j), (void *)&dualpivotquickResult[i][j], sizeof(int));
  16. }
  17. }
  18. MTI = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
  19. for (int i = 0; i < maxArraySize / step; ++i) {
  20. for (int j = 0; j < 4; ++j) {
  21. memcpy((void *)(mxGetPr(MTI) + i + maxArraySize / step * j), (void *)&mergetoinsertionResult[i][j], sizeof(int));
  22. }
  23. }
  24. INS = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
  25. for (int i = 0; i < maxArraySize / step; ++i) {
  26. for (int j = 0; j < 4; ++j) {
  27. memcpy((void *)(mxGetPr(INS) + i + maxArraySize / step * j), (void *)&insertionResult[i][j], sizeof(int));
  28. }
  29. }
  30. QTI = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
  31. for (int i = 0; i < maxArraySize / step; ++i) {
  32. for (int j = 0; j < 4; ++j) {
  33. memcpy((void *)(mxGetPr(QTI
  34. ) + i + maxArraySize / step * j), (void *)&quicktoinsertionResult[i][j], sizeof(int));
  35. }
  36. }
  37. QCK = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
  38. for (int i = 0; i < maxArraySize / step; ++i) {
  39. for (int j = 0; j < 4; ++j) {
  40. memcpy((void *)(mxGetPr(QCK) + i + maxArraySize / step * j), (void *)&quickResult[i][j], sizeof(int));
  41. }
  42. }
  43. MERGE = mxCreateNumericMatrix(maxArraySize / step, 4, mxINT64_CLASS, mxREAL);
  44. for (int i = 0; i < maxArraySize / step; ++i) {
  45. for (int j = 0; j < 4; ++j) {
  46. memcpy((void *)(mxGetPr(MERGE) + i + maxArraySize / step * j), (void *)&mergeResult[i][j], sizeof(int));
  47. }
  48. }
  49.  
  50. engPutVariable(ep, "ARGS", ARGS);
  51. engPutVariable(ep, "QTI", QTI);
  52. engPutVariable(ep, "DUAL", DUAL);
  53. engPutVariable(ep, "MERGE", MERGE);
  54. engPutVariable(ep, "MTI", MTI);
  55. engPutVariable(ep, "INS", INS);
  56. engPutVariable(ep, "QCK", QCK);
  57.  
  58. engEvalString(ep, "plot(ARGS, INS(:,3),'y', ARGS,MERGE(:,3),'b', ARGS,QCK(:,3),'m', ARGS,MTI(:,3),'c', ARGS,QTI(:,3),'r', ARGS,DUAL(:,3),'g');");
  59. engEvalString(ep, "title('Time vs. number of data');");
  60. engEvalString(ep, "xlabel('Data number');");
  61. engEvalString(ep, "ylabel('Time');");
  62. engEvalString(ep, "legend insertion merge quick mergeToInsertion quickToOnsertion dualQuick");
  63. engEvalString(ep, "legend location northwest");
  64. engEvalString(ep, "figure;");
  65. engEvalString(ep, "plot(ARGS, INS(:,2),'y', ARGS,MERGE(:,2),'b', ARGS,QCK(:,2),'m', ARGS,MTI(:,2),'c', ARGS,QTI(:,2),'r', ARGS,DUAL(:,2),'g');");
  66. engEvalString(ep, "title('Swaps vs. number of data');");
  67. engEvalString(ep, "xlabel('Data number');");
  68. engEvalString(ep, "ylabel('Swaps');");
  69. engEvalString(ep, "legend insertion merge quick mergeToInsertion quickToOnsertion dualQuick");
  70. engEvalString(ep, "legend location northwest");
  71. engEvalString(ep, "figure;");
  72. engEvalString(ep, "plot(ARGS, INS(:,1),'y', ARGS,MERGE(:,1),'b', ARGS,QCK(:,1),'m', ARGS,MTI(:,1),'c', ARGS,QTI(:,1),'r', ARGS,DUAL(:,1),'g');");
  73. engEvalString(ep, "title('Compares vs. number of data');");
  74. engEvalString(ep, "xlabel('Data number');");
  75. engEvalString(ep, "ylabel('Compares');");
  76. engEvalString(ep, "legend insertion merge quick mergeToInsertion quickToOnsertion dualQuick");
  77. engEvalString(ep, "legend location northwest");
  78.  
  79. printf("Hit return to continue\n\n");
  80. fgetc(stdin);
  81.  
  82. mxDestroyArray(ARGS);
  83. mxDestroyArray(QTI);
  84. mxDestroyArray(DUAL);
  85. mxDestroyArray(MERGE);
  86. mxDestroyArray(QCK);
  87. engEvalString(ep, "close;");
  88.  
  89. engClose(ep);
  90. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement