Skip to content

Commit

Permalink
Fix confusion with order origin/destination nodes in arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Apr 26, 2024
1 parent 8f397a5 commit 4528c5f
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 286 deletions.
20 changes: 10 additions & 10 deletions data/examples/Howard2.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
{ "id": 3, "caption": "T3", "x": 734, "y": 406, "angle": 0 }
],
"arcs": [
{ "from": "P0", "to": "T0" },
{ "from": "T0", "to": "P1", "duration": 5 },
{ "from": "P1", "to": "T1" },
{ "from": "T1", "to": "P2", "duration": 3 },
{ "from": "P2", "to": "T2" },
{ "from": "T2", "to": "P0", "duration": 5 },
{ "from": "T0", "to": "P3", "duration": 1 },
{ "from": "P3", "to": "T3" },
{ "from": "T3", "to": "P4", "duration": 1 },
{ "from": "P4", "to": "T2" }
{ "from": "P3", "to": "T0" },
{ "from": "P1", "to": "T0" },
{ "from": "T0", "to": "P0", "duration": 5 },
{ "from": "P0", "to": "T2" },
{ "from": "T2", "to": "P2", "duration": 3 },
{ "from": "P2", "to": "T1" },
{ "from": "T1", "to": "P1", "duration": 5 },
{ "from": "T2", "to": "P4", "duration": 1 },
{ "from": "P4", "to": "T3" },
{ "from": "T3", "to": "P3", "duration": 1 }
]
}
]
Expand Down
8 changes: 4 additions & 4 deletions data/examples/SemiHoward.teg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TimedEventGraph 3 5

1 0: 0 1
0 1: 1 0
0 2: 0 0
1 2: 1 0
0 1: 0 1
1 0: 1 0
2 0: 0 0
2 1: 1 0
2 2: 2 1
24 changes: 12 additions & 12 deletions data/examples/SemiNetherlands.teg
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
TimedEventGraph 8 12

1 0: 61 2
3 1: 81 1
0 2: 58 1
5 2: 0 0
2 3: 86 2
4 3: 69 2
3 4: 69 1
6 4: 36 1
4 5: 35 1
1 6: 0 0
7 6: 58 1
5 7: 61 1
0 1: 61 2
1 3: 81 1
2 0: 58 1
2 5: 0 0
3 2: 86 2
3 4: 69 2
4 3: 69 1
4 6: 36 1
5 4: 35 1
6 1: 0 0
6 7: 58 1
7 5: 61 1
Binary file removed doc/pics/Circuit01.png
Binary file not shown.
Binary file removed doc/pics/EventGraph01.png
Binary file not shown.
5 changes: 3 additions & 2 deletions src/Net/Algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ CriticalCycleResult findCriticalCycle(Net const& net)
Transition& from = *reinterpret_cast<Transition*>(&(p.arcsIn[0]->from));
Transition& to = *reinterpret_cast<Transition*>(&(p.arcsOut[0]->to));

IJ.push_back(int(to.id)); // Transposed is needed
IJ.push_back(int(from.id));
IJ.push_back(int(to.id));
T.push_back(p.arcsIn[0]->duration);
N.push_back(double(p.tokens));
}
Expand Down Expand Up @@ -501,7 +501,7 @@ CriticalCycleResult findCriticalCycle(Net const& net)
Node* t1 = &p.arcsOut[0]->to;
assert(t0->type == Node::Type::Transition);
assert(t1->type == Node::Type::Transition);
if ((t0->id == from) && (t1->id == to))
if ((t1->id == from) && (t0->id == to))
{
result.arcs.push_back(p.arcsIn[0]);
result.arcs.push_back(p.arcsOut[0]);
Expand All @@ -524,6 +524,7 @@ CriticalCycleResult findCriticalCycle(Net const& net)
}

result.success = true;
//std::cout << result.message.str().c_str() << "\n";
return result;
}

Expand Down
53 changes: 42 additions & 11 deletions tests/EventGraphTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,72 @@ TEST(TestEventGraph, TestToSysLinNoInputNoOutput)
ASSERT_EQ(toSysLin(net, D, A, B, C), true);
//
// j
// i | . . . . . | | . . . . 5 |
// | 5 . . . . | | . . . . . |
// D = | . 3 . 1 . |, A = | . . . . . |
// | 1 . . . . | | . . . . . |
// | . . . . . | | . . 0 . . |
// i | . 5 . 1 . | | . . . . . |
// | . . 3 . . | | . . . . . |
// D = | . . . . . |, A = | . . . . 5 |
// | . . 1 . . | | . . . . . |
// | . . . . . | | 0 . . . . |
//
ASSERT_EQ(D.i.size(), 4u);
ASSERT_EQ(D.j.size(), 4u);
ASSERT_EQ(D.d.size(), 4u);
ASSERT_EQ(D.N, 5u);
ASSERT_EQ(D.M, 5u);
ASSERT_THAT(D.i, UnorderedElementsAre(2u, 3u, 4u, 3u));
ASSERT_THAT(D.j, UnorderedElementsAre(1u, 2u, 1u, 4u));
ASSERT_THAT(D.d, UnorderedElementsAre(5.0, 3.0, 1.0, 1.0));
ASSERT_THAT(D.i, ElementsAre(1u, 2u, 1u, 4u));
ASSERT_THAT(D.j, ElementsAre(4u, 3u, 2u, 3u));
ASSERT_THAT(D.d, ElementsAre(1.0, 3.0, 5.0, 1.0));
SparseMatrix<double>::display_for_julia = true;
SparseMatrix<double>::display_as_dense = false;
std::stringstream ssD; ssD << D;
ASSERT_STREQ(ssD.str().c_str(), "[1, 2, 1, 4], [4, 3, 2, 3], MP([1, 3, 5, 1]), 5, 5");
SparseMatrix<double>::display_as_dense = true;
ssD.str(""); ssD << D;
ASSERT_STREQ(ssD.str().c_str(), ". 5 . 1 . \n. . 3 . . \n. . . . . \n. . 1 . . \n. . . . . \n");

ASSERT_EQ(A.i.size(), 2u);
ASSERT_EQ(A.j.size(), 2u);
ASSERT_EQ(A.d.size(), 2u);
ASSERT_EQ(A.N, 5u);
ASSERT_EQ(A.M, 5u);
ASSERT_THAT(A.i, UnorderedElementsAre(5u, 1u));
ASSERT_THAT(A.j, UnorderedElementsAre(3u, 5u));
ASSERT_THAT(A.d, UnorderedElementsAre(0.0, 5.0));
ASSERT_THAT(A.i, ElementsAre(5u, 3u));
ASSERT_THAT(A.j, ElementsAre(1u, 5u));
ASSERT_THAT(A.d, ElementsAre(0.0, 5.0));
SparseMatrix<double>::display_for_julia = true;
SparseMatrix<double>::display_as_dense = false;
std::stringstream ssA; ssA << A;
ASSERT_STREQ(ssA.str().c_str(), "[5, 3], [1, 5], MP([0, 5]), 5, 5");
SparseMatrix<double>::display_as_dense = true;
ssA.str(""); ssA << A;
// FIXME trailing white space not proper
// FIXME 0 not displayed
// ASSERT_STREQ(ssA.str().c_str(), ". . . . . \n. . . . . \n. . . . 5 \n. . . . . \n0 . . . . \n");
ASSERT_STREQ(ssA.str().c_str(), ". . . . . \n. . . . . \n. . . . 5 \n. . . . . \n. . . . . \n");

ASSERT_EQ(B.i.size(), 0u);
ASSERT_EQ(B.j.size(), 0u);
ASSERT_EQ(B.d.size(), 0u);
ASSERT_EQ(B.N, 0u);
ASSERT_EQ(B.M, 5u);
SparseMatrix<double>::display_for_julia = true;
SparseMatrix<double>::display_as_dense = false;
std::stringstream ssB; ssB << B;
ASSERT_STREQ(ssB.str().c_str(), "[], [], MP([]), 5, 0");
SparseMatrix<double>::display_as_dense = true;
ssB.str(""); ssB << B;
ASSERT_STREQ(ssB.str().c_str(), "\n\n\n\n\n"); // FIXME not proper

ASSERT_EQ(C.i.size(), 0u);
ASSERT_EQ(C.j.size(), 0u);
ASSERT_EQ(C.d.size(), 0u);
ASSERT_EQ(C.N, 5u);
ASSERT_EQ(C.M, 0u);
SparseMatrix<double>::display_for_julia = true;
SparseMatrix<double>::display_as_dense = false;
std::stringstream ssC; ssC << C;
ASSERT_STREQ(ssC.str().c_str(), "[], [], MP([]), 0, 5");
SparseMatrix<double>::display_as_dense = true;
ssC.str(""); ssC << C;
ASSERT_STREQ(ssC.str().c_str(), "");
}

//------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 4528c5f

Please sign in to comment.