@@ -403,11 +403,93 @@ function linear_subsys_adjmat(state::TransformationState)
403
403
linear_equations, eadj, cadj)
404
404
end
405
405
406
+ using . BipartiteGraphs: Label, BipartiteAdjacencyList
407
+ struct SystemStructurePrintMatrix < :
408
+ AbstractMatrix{Union{Label, Int, BipartiteAdjacencyList}}
409
+ bpg:: BipartiteGraph
410
+ highlight_graph:: BipartiteGraph
411
+ var_to_diff:: DiffGraph
412
+ eq_to_diff:: DiffGraph
413
+ var_eq_matching:: Union{Matching, Nothing}
414
+ end
415
+ Base. size (bgpm:: SystemStructurePrintMatrix ) = (max (nsrcs (bgpm. bpg), ndsts (bgpm. bpg)) + 1 , 5 )
416
+ function compute_diff_label (diff_graph, i)
417
+ di = i - 1 <= length (diff_graph) ? diff_graph[i - 1 ] : nothing
418
+ ii = i - 1 <= length (invview (diff_graph)) ? invview (diff_graph)[i - 1 ] : nothing
419
+ return Label (string (di === nothing ? " " : string (di, ' ↓' ),
420
+ di != = nothing && ii != = nothing ? " " : " " ,
421
+ ii === nothing ? " " : string (ii, ' ↑' )))
422
+ end
423
+ function Base. getindex (bgpm:: SystemStructurePrintMatrix , i:: Integer , j:: Integer )
424
+ checkbounds (bgpm, i, j)
425
+ if i <= 1
426
+ return (Label .((" #" , " ∂ₜ" , " eq" , " ∂ₜ" , " v" )))[j]
427
+ elseif j == 2
428
+ return compute_diff_label (bgpm. eq_to_diff, i)
429
+ elseif j == 4
430
+ return compute_diff_label (bgpm. var_to_diff, i)
431
+ elseif j == 1
432
+ return i - 1
433
+ elseif j == 3
434
+ return BipartiteAdjacencyList (i - 1 <= nsrcs (bgpm. bpg) ?
435
+ 𝑠neighbors (bgpm. bpg, i - 1 ) : nothing ,
436
+ bgpm. highlight_graph != = nothing &&
437
+ i - 1 <= nsrcs (bgpm. highlight_graph) ?
438
+ Set (𝑠neighbors (bgpm. highlight_graph, i - 1 )) :
439
+ nothing ,
440
+ bgpm. var_eq_matching != = nothing &&
441
+ (i - 1 <= length (invview (bgpm. var_eq_matching))) ?
442
+ invview (bgpm. var_eq_matching)[i - 1 ] : unassigned)
443
+ elseif j == 5
444
+ return BipartiteAdjacencyList (i - 1 <= ndsts (bgpm. bpg) ?
445
+ 𝑑neighbors (bgpm. bpg, i - 1 ) : nothing ,
446
+ bgpm. highlight_graph != = nothing &&
447
+ i - 1 <= ndsts (bgpm. highlight_graph) ?
448
+ Set (𝑑neighbors (bgpm. highlight_graph, i - 1 )) :
449
+ nothing ,
450
+ bgpm. var_eq_matching != = nothing &&
451
+ (i - 1 <= length (bgpm. var_eq_matching)) ?
452
+ bgpm. var_eq_matching[i - 1 ] : unassigned)
453
+ else
454
+ @assert false
455
+ end
456
+ end
457
+
406
458
function Base. show (io:: IO , mime:: MIME"text/plain" , s:: SystemStructure )
407
- @unpack graph = s
408
- S = incidence_matrix (graph, Num (Sym {Real} (:× )))
409
- print (io, " Incidence matrix:" )
410
- show (io, mime, S)
459
+ @unpack graph, solvable_graph, var_to_diff, eq_to_diff = s
460
+ if ! get (io, :limit , true ) || ! get (io, :mtk_limit , true )
461
+ print (io, " SystemStructure with " , length (graph. fadjlist), " equations and " ,
462
+ isa (graph. badjlist, Int) ? graph. badjlist : length (graph. badjlist),
463
+ " variables\n " )
464
+ Base. print_matrix (io,
465
+ SystemStructurePrintMatrix (complete (graph),
466
+ complete (solvable_graph),
467
+ complete (var_to_diff),
468
+ complete (eq_to_diff), nothing ))
469
+ else
470
+ S = incidence_matrix (graph, Num (Sym {Real} (:× )))
471
+ print (io, " Incidence matrix:" )
472
+ show (io, mime, S)
473
+ end
474
+ end
475
+
476
+ struct MatchedSystemStructure
477
+ structure:: SystemStructure
478
+ var_eq_matching:: Matching
479
+ end
480
+
481
+ function Base. show (io:: IO , mime:: MIME"text/plain" , ms:: MatchedSystemStructure )
482
+ s = ms. structure
483
+ @unpack graph, solvable_graph, var_to_diff, eq_to_diff = s
484
+ print (io, " Matched SystemStructure with " , length (graph. fadjlist), " equations and " ,
485
+ isa (graph. badjlist, Int) ? graph. badjlist : length (graph. badjlist),
486
+ " variables\n " )
487
+ Base. print_matrix (io,
488
+ SystemStructurePrintMatrix (complete (graph),
489
+ complete (solvable_graph),
490
+ complete (var_to_diff),
491
+ complete (eq_to_diff),
492
+ complete (ms. var_eq_matching, nsrcs (graph))))
411
493
end
412
494
413
495
end # module
0 commit comments