You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.9 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "main.h"
  10. #include <Eigen/Geometry>
  11. template<typename Scalar,int Size> void homogeneous(void)
  12. {
  13. /* this test covers the following files:
  14. Homogeneous.h
  15. */
  16. typedef Matrix<Scalar,Size,Size> MatrixType;
  17. typedef Matrix<Scalar,Size,1, ColMajor> VectorType;
  18. typedef Matrix<Scalar,Size+1,Size> HMatrixType;
  19. typedef Matrix<Scalar,Size+1,1> HVectorType;
  20. typedef Matrix<Scalar,Size,Size+1> T1MatrixType;
  21. typedef Matrix<Scalar,Size+1,Size+1> T2MatrixType;
  22. typedef Matrix<Scalar,Size+1,Size> T3MatrixType;
  23. VectorType v0 = VectorType::Random(),
  24. ones = VectorType::Ones();
  25. HVectorType hv0 = HVectorType::Random();
  26. MatrixType m0 = MatrixType::Random();
  27. HMatrixType hm0 = HMatrixType::Random();
  28. hv0 << v0, 1;
  29. VERIFY_IS_APPROX(v0.homogeneous(), hv0);
  30. VERIFY_IS_APPROX(v0, hv0.hnormalized());
  31. hm0 << m0, ones.transpose();
  32. VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);
  33. VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
  34. hm0.row(Size-1).setRandom();
  35. for(int j=0; j<Size; ++j)
  36. m0.col(j) = hm0.col(j).head(Size) / hm0(Size,j);
  37. VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
  38. T1MatrixType t1 = T1MatrixType::Random();
  39. VERIFY_IS_APPROX(t1 * (v0.homogeneous().eval()), t1 * v0.homogeneous());
  40. VERIFY_IS_APPROX(t1 * (m0.colwise().homogeneous().eval()), t1 * m0.colwise().homogeneous());
  41. T2MatrixType t2 = T2MatrixType::Random();
  42. VERIFY_IS_APPROX(t2 * (v0.homogeneous().eval()), t2 * v0.homogeneous());
  43. VERIFY_IS_APPROX(t2 * (m0.colwise().homogeneous().eval()), t2 * m0.colwise().homogeneous());
  44. VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2,
  45. v0.transpose().rowwise().homogeneous() * t2);
  46. m0.transpose().rowwise().homogeneous().eval();
  47. VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t2,
  48. m0.transpose().rowwise().homogeneous() * t2);
  49. T3MatrixType t3 = T3MatrixType::Random();
  50. VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t3,
  51. v0.transpose().rowwise().homogeneous() * t3);
  52. VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t3,
  53. m0.transpose().rowwise().homogeneous() * t3);
  54. // test product with a Transform object
  55. Transform<Scalar, Size, Affine> aff;
  56. Transform<Scalar, Size, AffineCompact> caff;
  57. Transform<Scalar, Size, Projective> proj;
  58. Matrix<Scalar, Size, Dynamic> pts;
  59. Matrix<Scalar, Size+1, Dynamic> pts1, pts2;
  60. aff.affine().setRandom();
  61. proj = caff = aff;
  62. pts.setRandom(Size,internal::random<int>(1,20));
  63. pts1 = pts.colwise().homogeneous();
  64. VERIFY_IS_APPROX(aff * pts.colwise().homogeneous(), (aff * pts1).colwise().hnormalized());
  65. VERIFY_IS_APPROX(caff * pts.colwise().homogeneous(), (caff * pts1).colwise().hnormalized());
  66. VERIFY_IS_APPROX(proj * pts.colwise().homogeneous(), (proj * pts1));
  67. VERIFY_IS_APPROX((aff * pts1).colwise().hnormalized(), aff * pts);
  68. VERIFY_IS_APPROX((caff * pts1).colwise().hnormalized(), caff * pts);
  69. pts2 = pts1;
  70. pts2.row(Size).setRandom();
  71. VERIFY_IS_APPROX((aff * pts2).colwise().hnormalized(), aff * pts2.colwise().hnormalized());
  72. VERIFY_IS_APPROX((caff * pts2).colwise().hnormalized(), caff * pts2.colwise().hnormalized());
  73. VERIFY_IS_APPROX((proj * pts2).colwise().hnormalized(), (proj * pts2.colwise().hnormalized().colwise().homogeneous()).colwise().hnormalized());
  74. }
  75. void test_geo_homogeneous()
  76. {
  77. for(int i = 0; i < g_repeat; i++) {
  78. CALL_SUBTEST_1(( homogeneous<float,1>() ));
  79. CALL_SUBTEST_2(( homogeneous<double,3>() ));
  80. CALL_SUBTEST_3(( homogeneous<double,8>() ));
  81. }
  82. }
HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Set-Cookie: i_like_gitea=e5197b345cc2c5ac; Path=/; HttpOnly; SameSite=Lax Set-Cookie: _csrf=cpkOT0lvRqQwk1NAG49XC-5YlJM6MTczNjUxNzA3MTY3NzQ1NzA1Mg; Path=/; Expires=Sat, 11 Jan 2025 13:51:11 GMT; HttpOnly; SameSite=Lax Set-Cookie: macaron_flash=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax X-Frame-Options: SAMEORIGIN Date: Fri, 10 Jan 2025 13:51:15 GMT Transfer-Encoding: chunked ce2a sp/tempest - tempest - Gitea: Git with a cup of tea
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.2 KiB

  1. // CSMA/CD protocol - probabilistic version of kronos model (3 stations)
  2. // gxn/dxp 04/12/01
  3. mdp
  4. // note made changes since cannot have strict inequalities
  5. // in digital clocks approach and suppose a station only sends one message
  6. // simplified parameters scaled
  7. const int sigma=1; // time for messages to propagate along the bus
  8. const int lambda=30; // time to send a message
  9. // actual parameters
  10. const int N = 2; // number of processes
  11. const int K = 4; // exponential backoff limit
  12. const int slot = 2*sigma; // length of slot
  13. const int M = 15 ; // max number of slots to wait
  14. //const int lambda=782;
  15. //const int sigma=26;
  16. //----------------------------------------------------------------------------------------------------------------------------
  17. // the bus
  18. module bus
  19. b : [0..2];
  20. // b=0 - idle
  21. // b=1 - active
  22. // b=2 - collision
  23. // clocks of bus
  24. y1 : [0..sigma+1]; // time since first send (used find time until channel sensed busy)
  25. y2 : [0..sigma+1]; // time since second send (used to find time until collision detected)
  26. // a sender sends (ok - no other message being sent)
  27. [send1] (b=0) -> (b'=1);
  28. [send2] (b=0) -> (b'=1);
  29. // a sender sends (bus busy - collision)
  30. [send1] (b=1|b=2) & (y1<sigma) -> (b'=2);
  31. [send2] (b=1|b=2) & (y1<sigma) -> (b'=2);
  32. // finish sending
  33. [end1] (b=1) -> (b'=0) & (y1'=0);
  34. [end2] (b=1) -> (b'=0) & (y1'=0);
  35. // bus busy
  36. [busy1] (b=1|b=2) & (y1>=sigma) -> (b'=b);
  37. [busy2] (b=1|b=2) & (y1>=sigma) -> (b'=b);
  38. // collision detected
  39. [cd] (b=2) & (y2<=sigma) -> (b'=0) & (y1'=0) & (y2'=0);
  40. // time passage
  41. [time] (b=0) -> (y1'=0); // value of y1/y2 does not matter in state 0
  42. [time] (b=1) -> (y1'=min(y1+1,sigma+1)); // no invariant in state 1
  43. [time] (b=2) & (y2<sigma) -> (y1'=min(y1+1,sigma+1)) & (y2'=min(y2+1,sigma+1)); // invariant in state 2 (time until collision detected)
  44. endmodule
  45. //----------------------------------------------------------------------------------------------------------------------------
  46. // model of first sender
  47. module station1
  48. // LOCAL STATE
  49. s1 : [0..5];
  50. // s1=0 - initial state
  51. // s1=1 - transmit
  52. // s1=2 - collision (set backoff)
  53. // s1=3 - wait (bus busy)
  54. // s1=4 - successfully sent
  55. // LOCAL CLOCK
  56. x1 : [0..max(lambda,slot)];
  57. // BACKOFF COUNTER (number of slots to wait)
  58. bc1 : [0..M];
  59. // COLLISION COUNTER
  60. cd1 : [0..K];
  61. // start sending
  62. [send1] (s1=0) -> (s1'=1) & (x1'=0); // start sending
  63. [busy1] (s1=0) -> (s1'=2) & (x1'=0) & (cd1'=min(K,cd1+1)); // detects channel is busy so go into backoff
  64. // transmitting
  65. [time] (s1=1) & (x1<lambda) -> (x1'=min(x1+1,lambda)); // let time pass
  66. [end1] (s1=1) & (x1=lambda) -> (s1'=4) & (x1'=0); // finished
  67. [cd] (s1=1) -> (s1'=2) & (x1'=0) & (cd1'=min(K,cd1+1)); // collision detected (increment backoff counter)
  68. [cd] !(s1=1) -> (s1'=s1); // add loop for collision detection when not important
  69. // set backoff (no time can pass in this state)
  70. // probability depends on which transmission this is (cd1)
  71. [] s1=2 & cd1=1 -> 1/2 : (s1'=3) & (bc1'=0) + 1/2 : (s1'=3) & (bc1'=1) ;
  72. [] s1=2 & cd1=2 -> 1/4 : (s1'=3) & (bc1'=0) + 1/4 : (s1'=3) & (bc1'=1) + 1/4 : (s1'=3) & (bc1'=2) + 1/4 : (s1'=3) & (bc1'=3) ;
  73. [] s1=2 & cd1=3 -> 1/8 : (s1'=3) & (bc1'=0) + 1/8 : (s1'=3) & (bc1'=1) + 1/8 : (s1'=3) & (bc1'=2) + 1/8 : (s1'=3) & (bc1'=3) + 1/8 : (s1'=3) & (bc1'=4) + 1/8 : (s1'=3) & (bc1'=5) + 1/8 : (s1'=3) & (bc1'=6) + 1/8 : (s1'=3) & (bc1'=7) ;
  74. [] s1=2 & cd1=4 -> 1/16 : (s1'=3) & (bc1'=0) + 1/16 : (s1'=3) & (bc1'=1) + 1/16 : (s1'=3) & (bc1'=2) + 1/16 : (s1'=3) & (bc1'=3) + 1/16 : (s1'=3) & (bc1'=4) + 1/16 : (s1'=3) & (bc1'=5) + 1/16 : (s1'=3) & (bc1'=6) + 1/16 : (s1'=3) & (bc1'=7) + 1/16 : (s1'=3) & (bc1'=8) + 1/16 : (s1'=3) & (bc1'=9) + 1/16 : (s1'=3) & (bc1'=10) + 1/16 : (s1'=3) & (bc1'=11) + 1/16 : (s1'=3) & (bc1'=12) + 1/16 : (s1'=3) & (bc1'=13) + 1/16 : (s1'=3) & (bc1'=14) + 1/16 : (s1'=3) & (bc1'=15) ;
  75. // wait until backoff counter reaches 0 then send again
  76. [time] (s1=3) & (x1<slot) -> (x1'=x1+1); // let time pass (in slot)
  77. [time] (s1=3) & (x1=slot) & (bc1>0) -> (x1'=1) & (bc1'=bc1-1); // let time pass (move slots)
  78. [send1] (s1=3) & (x1=slot) & (bc1=0) -> (s1'=1) & (x1'=0); // finished backoff (bus appears free)
  79. [busy1] (s1=3) & (x1=slot) & (bc1=0) -> (s1'=2) & (x1'=0) & (cd1'=min(K,cd1+1)); // finished backoff (bus busy)
  80. // once finished nothing matters
  81. [time] (s1>=4) -> (x1'=0);
  82. endmodule
  83. //----------------------------------------------------------------------------------------------------------------------------
  84. // construct further stations through renaming
  85. module station2=station1[s1=s2,x1=x2,cd1=cd2,bc1=bc2,send1=send2,busy1=busy2,end1=end2] endmodule
  86. //----------------------------------------------------------------------------------------------------------------------------
  87. // reward structure for expected time
  88. rewards "time"
  89. [time] true : 1;
  90. endrewards
  91. //----------------------------------------------------------------------------------------------------------------------------
  92. // labels/formulae
  93. label "all_delivered" = s1=4&s2=4;
  94. label "one_delivered" = s1=4|s2=4;
  95. label "collision_max_backoff" = (cd1=K & s1=1 & b=2)|(cd2=K & s2=1 & b=2);
0