-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTuGamesAux.wl
1020 lines (814 loc) · 38.6 KB
/
TuGamesAux.wl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* ::Package:: *)
(* :Title: TuGamesAux.m *)
(* Release Date: 13.03.2024 *)
(* Version: 3.1.4 *)
(* :Context: TuGamesAux` *)
(* :Summary:
This package provides some auxiliary functions to the package TuGames.m.
*)
(* :Author:
Holger Ingmar Meinhardt
Department of Economics
University of Karlsruhe (KIT)
E-Mail: [email protected]
*)
(* :Package Version: 3.1.4 *)
(*
:Mathematica Version: 12.x, 13.x, 14.x
*)
(* :Sources:
Maschler JET, 13, pp. 184-192.
*)
(*:Keywords:
Extracting the coefficient from an LP. Solving the primal and dual problem.
*)
(* :History:
Version 1.1
The following functions have been added:
ContestedGarment[],TalmudicRule[].
Version 1.3
The following functions have been added:
Angle[],LieBracket[]
Version 1.5
The following functions have been added:
AssignmentProblem[],GenProfitMatrix[],AdjointMatrix[],HermitianMatrixQ[].
Some code adjustment and clean up.
Version 1.6
The following functions have been added:
GetCardinalityGame[],SymGameType2[],SymGameType3[],SymGameType4[],SymGameSizeK[],Coal2Dec[].
HermitianMatrixQ[] - has been renamed due to a name conflict to IsHermitianMatrixQ[].
ModestBankruptcy[] - has changed its behavior, only two input arguments are allowed.
GreedyBankruptcy[] - has changed its behavior, only two input arguments are allowed.
TalmudicRule[] - has changed its behavior, only two input arguments are allowed.
Version 1.7
SelectPart[] - Superfluous, has been removed.
AssignSymVal[] - Superfluous, has been removed.
LPtoMatrix[] - has been modified to clean up and to simplify the code.
Version 1.8
LPtoMatrix[] - fixes incorrect computation due to wrong order into the boundary vector.
Version 2.2
Transcription of the old option rules to the new ones invented by Mathematica 8.x.
This package is now exclusively dedicated to Mathematica version 8.x and higher.
Version 2.3:
Change protected command SubsetQ[] to SubSetQ[] from the VertexEnum package. Order is
reversed to SubsetQ[] which is new in Mathematica version 10.x.
Version 2.5.4:
Adding the function Sets2Dec[] that transcribes a set of coalitions into its unique integer
representations. Moreover, we add the function BalancedSystemQ[] that should check if a collection
of sets is balanced. However, use it with care, it returns for n=>4 incorrect results probably due to
a bug within the DualLinearProgramming. For an example see ChangeLog.
Version 2.6.0:
Performing some code maintenance.
Version 3.0.0:
Not anymore backward compatible to Mathematica versions smaller than 12 due to the port
to the new collection of algorithms for solving convex problems introduced in version 12.
Version 3.0.1:
Some minor bug fixes. Improving performance of functions revised in Version 3.
Version 3.0.2 and later:
See ChangeLog.
*)
BeginPackage["TUG`TuGamesAux`"];
Angle::usage =
"Angle[x_vec,y_vec] computes the angle of the two vectors x and y.";
AssignmentProblem::usage =
"AssignmentProblem[buyers, sellers, profitmat] determines the characteristic values from an
assignment problem. These values can be used to define the corresponding assignment game.";
AirportProblem::usage =
"AirportProblem[cost,nj] computes the associated airport cost game from (cost,nj).
The sum of nj should not exceed 48 players.";
BalancedSystemQ::usage =
"{bcQ,cfs}=BalancedSystemQ[coll,T] checks whether the collection of sets 'coll' is balanced.
It returns a True or False on the first return value, at the second position the weights of
the balanced collection are returned.";
WeaklyBalancedSystemQ::usage =
"bcQ=WeaklyBalancedSystemQ[coll,b0,T] checks whether the collection of sets 'coll' in connection with
a set of single coalitions b0 -- could be empty -- is weakly balanced. It returns a True or False.";
GenProfitMatrix::usage =
"GenProfitMatrix[valuation_buyers,valuation_sellers] generates a profit matrix for an assignment
problem by the list of valuation of buyers and sellers.";
ComplementaryMarket::usage =
"ComplementaryMarket[Tlist,Plist_,Qlist,opts] computes the coalitional values of a market situation with complementary goods. See Maschler JET, 13, pp. 184-192. The set P can be understood as manufactures and Q as workers. The set T is the player set with P union Q.";
CostLocationGame::usage =
"CostLocationGame[dmpts,refvc,p,q,fixedCost,opts] computes from a facility location situation constituted by a list of demand points, a symbolic reference vector like (x1,x2,...,xn), a pq-norm, and a fixed cost value of the associated cost location game. For the PQ-norm, the default values are p=2 and q=1 (Euclidean norm), and for the fixed cost, the default value is set to zero. These input arguments are optional. Mandatory, are the demand points, and a reference point. Demand points must be selected from positive orthant. Return values are the coalitional cost values, and for each coalition larger than 2, the barycenter of the associated polyhedron in which the new facility built up by this coalition is located. Permissible Methods are: {Automatic, NelderMead, DifferentialEvolution,SimulatedAnnealing} passed as string characters. Selecting a Method invokes the function NMinArg. As its third output argument the savings game of the cost location game is returned.";
ProductGame::usage =
"ProductGame[wghs] computes from weights vector the characteristic values and Harsanyi dividends of a product game.";
ProbabilityGame::usage =
"ProbabilityGame[wghs] computes from weights vector the characteristic values of a probability game.";
DualProbabilityGame::usage =
"DualProbabilityGame[wghs] computes from weights vector the characteristic values of a dual probability game.";
ContestedGarment::usage =
"ContestGarment[Estate,{d1,d2}] computes a solution for a contested garment or two-creditor modest
bankruptcy problem.";
TalmudicRule::usage =
"TalmudicRule[Estate,{d1,d2,d3,...,dn}] computes a solution for a contested garment or n-creditor modest
bankruptcy problem. The solution coincides with the nucleolus of the corresponding bankruptcy game.";
GreedyBankruptcy::usage =
"GreedyBankruptcy[Estate,claims] computes the coalitional values for a greedy bankruptcy game.";
LPtoMatrix::usage =
"LPtoMatrix[zf, const, var] extracts the coefficient from an LP. Where 'zf' is the objective function,
'const' is the linear constraint set and 'var' is set of variables.";
AdjointMatrix::usage=
"AdjointMatrix[mat_List] computes the conjugate transpose of the matrix 'mat'.";
IsHermitianMatrixQ::usage:=
"IsHermitianMatrixQ[mat_List] checks whether a square matrix is self adjoint.";
ModestBankruptcy::usage =
"ModestBankruptcy[Estate,claims] computes the coalitional values for a modest bankruptcy game.";
GetCardinalityGame::usage =
"GetCardinalityGame[T,k] assigns a worth of zero to a coalition of size=<k<Length[T].
Larger coalition will be assigned according to its cardinality. The resultant vector can be
used to define a game.";
SymGameSizeK::usage =
"SymGameSize2[T,k,val] constructs a symmetric game where a cycle of coalitions of size k getting
a worth of 'val' and the grand coalition gets 2*val. The value k must be an integer between
2 and Length[T]. Remind that T is the player set.";
SymGameType2::usage =
"SymGameType2[T,S,val] constructs a game where all coalitions of size 2 satisfying
Intersection[S,Complement[T,S]] getting a worth of 'val', the grand coalition gets 2*val,
and otherwise zero. Coalition S must have size not less than 2.";
SymGameType3::usage =
"SymGameType3[T,S,val] constructs a game where all coalitions of size 3 satisfying
Intersection[S,Complement[T,S]] getting a worth of 'val', the grand coalition gets 2*val,
and otherwise zero. Coalition S must have size not less than 3.";
SymGameType4::usage =
"SymGameType4[T,S,val] constructs a game where all coalitions of size 4 satisfying
Intersection[S,Complement[T,S]] getting a worth of 'val', the grand coalition gets 2*val,
and otherwise zero. Coalition S must have size not less than 4.";
SolvePrimal::usage =
"SolvePrimal[zf, const, var] solves a primal problem.";
SolveDual::usage =
"SolveDual[zf, const, var] solves the corresponding dual problem.";
EuclidianDistance::usage =
"EuclidianDistance[liste,refliste] computes the Euclidian distance of the vector 'liste' w.r.t.
the vector 'refliste'.";
PQNorm::usage =
"PQNorm[liste,refliste,p,q] computes the PQ-norm of the vector 'liste' w.r.t.
the vector 'refliste'. The default is p=2, q=1, i.e., the Euclidean norm.";
NearRingQ::usage =
"NearRingQ[list,T] checks if the collection of sets is a near ring.";
LieBracket::usage =
"LieBracket[mat01,mat02] computes the commutator of the (nXn)-matrices mat01 and mat02.";
Coal2Dec::usage =
"Coal2Dec[n_Integer] converts the set of proper coalitions to its unique integer representations.";
Sets2Dec::usage =
"Sets2Dec[list] converts a collection of coalitions to its unique integer representations.";
RStirlingNumber::usage=
"RStirlingNumber[r,n,k] computes the r-associated Stirling number of the second kind.";
SortVecDecOrder::usage =
"SortVecDecOrder[vec] order vec into a non-increasing order. See Eq. (5.11) page 82 Peleg and Sudhoelter (2007).";
(* :Options: *)
Options[AssignmentProblem] := {Verbose -> False};
Options[BalancedSystemQ] := {Method-> RevisedSimplex};
Options[ComplementaryMarket] := {MarketParameter -> (1/2)};
Options[WeaklyBalancedSystemQ] := {Method-> RevisedSimplex};
Options[CostLocationGame] = {Method -> Automatic};
(* :Error Messages: *)
(* :One Argument: *)
AdjointMatrix::argerr="One argument was expected.";
Coal2Dec::argerr="One argument was expected.";
IsHermitianMatrixQ::argerr="One argument was expected.";
Sets2Dec::argerr="One argument was expected.";
SortVecDecOrder::argerr="One argument was expected.";
ProductGame::argerr="One argument was expected.";
ProbabilityGame::argerr="One argument was expected.";
DualProbabilityGame::argerr="One argument was expected.";
(* :Two Arguments: *)
Angle::argerr="Two arguments were expected.";
AirportProblem::argerr="Two arguments were expected.";
BalancedSystemQ::argerr="Two arguments were expected.";
ContestedGarment::argerr="Two arguments were expected.";
CostLocationGame::argerr="Two arguments were expected.";
EuclidianDistance::argerr="Two arguments were expected.";
GenProfitMatrix::argerr="Two arguments were expected.";
GreedyBankruptcy::argerr="Two arguments were expected.";
GetCardinalityGame::argerr="Two arguments were expected.";
LieBracket::argerr="Two arguments were expected.";
ModestBankruptcy::argerr="Two arguments were expected.";
NearRingQ::argerr="Two arguments were expected.";
PQNorm::argerr="Two arguments were expected.";
TalmudicRule::argerr="Two arguments were expected.";
(* :Three Arguments: *)
AssignmentProblem::argerr="Three arguments were expected.";
ComplementaryMarket::argerr="Three arguments were expected.";
LPtoMatrix::argerr="Three arguments were expected.";
RStirlingNumber::argerr="Three arguments were expected.";
SolveDual::argerr="Three arguments were expected.";
SolvePrimal::argerr="Three arguments were expected.";
SymGameSizeK::argerr="Three arguments were expected.";
SymGameType2::argerr="Three arguments were expected.";
SymGameType3::argerr="Three arguments were expected.";
SymGameType4::argerr="Three arguments were expected.";
WeaklyBalancedSystemQ::argerr="Three arguments were expected.";
Begin["`Private`"];
Which[$OperatingSystem === "Unix", Needs["TUG`vertex`VertexEnum`"],
$OperatingSystem === "Windows", Needs["TUG`vertex`VertexEnum`"],
$OperatingSystem === "MacOSX", Needs["TUG`vertex`VertexEnum`"],
True, Needs["VertexEnum`"]
];
Angle[args___]:=(Message[Angle::argerr];$Failed);
Angle[x_?VectorQ, y_?VectorQ] := ArcCos[Divide[x.y,(Norm[x, 2] Norm[y, 2])]]/Degree // N;
(*Extracting the coefficients from an LP *)
LPtoMatrix[args___]:=(Message[LPtoMatrix::argerr];$Failed);
LPtoMatrix[obf_, const_List, var_List]:=
Module[{zf, coemat, coebv, greq, lseq, eqeq, grout, lsout, eqout, ext1,
ext2, ext3, bv01, bv02, bv03, nbv01, bvec,ar,ps,rl},
zf = Coefficient[obf, var];
(* ineq = Simplify[const]; *)
coemat = Coefficient[#[[1]], var] & /@ const;
coebv = Last[#] & /@ const;
greq = Position[const, GreaterEqual];
eqeq = Position[const, Equal];
lseq = Position[const, LessEqual];
grout = Outer[List, First[#] & /@ greq];
eqout = Outer[List, First[#] & /@ eqeq];
lsout = Outer[List, First[#] & /@ lseq];
ext1 = If[SameQ[grout,{}], grout, Extract[coebv, grout]];
ext2 = If[SameQ[eqout,{}], eqout, Extract[coebv, eqout]];
ext3 = If[SameQ[lsout,{}], lsout, Extract[coebv, lsout]];
bv01 = If[SameQ[ext1, {}], ext1,
Flatten[MapThread[List, {{#}, {1}}]] & /@ ext1];
bv02 =
If[SameQ[ext2,{}], ext2,
Flatten[MapThread[List, {{#}, {0}}]] & /@ ext2];
bv03 =
If[SameQ[ext3,{}], ext3,
Flatten[MapThread[List, {{#}, {-1}}]] & /@ ext3];
bv01 = If[SameQ[bv01,{}], {bv01}, bv01 ];
nbv01 = If[SameQ[bv02,{}], bv01, AppendTo[bv01, bv02]; FlattenAt[bv01,Length[bv01]]];
nbv01 = If[SameQ[bv03,{}], nbv01, AppendTo[nbv01, bv03]; FlattenAt[nbv01,Length[nbv01]]];
bvec = DeleteCases[nbv01,{}];
ar = Array[{0,0} &,Length[bvec]];
ps = Flatten[{grout,eqout,lsout}];
rl = MapThread[Rule,{ps,bvec}];
bvec = ReplacePart[ar,rl];
{zf, coemat, bvec}
];
SolvePrimal[args___]:=(Message[SolvePrimal::argerr];$Failed);
SolvePrimal[zf_,eq_List,var_List, bd_:{}, opts:OptionsPattern[LinearOptimization]] :=
Module[{obf, cmat, bvect, res, nzf, rl},
{obf, cmat, bvect} = LPtoMatrix[zf, eq, var];
cmat = SparseArray[cmat];
(* res = LinearProgramming[obf, cmat, bvect, bd,opts]; *) (*second solution??? *)
bv=-First[#] &/@ bvect;
eqm=cmat[[1]];
beq=bv[[1]];
{res,nzf}=LinearOptimization[obf,{cmat,bv},{{eqm},{beq}},{"PrimalMinimizer", "PrimalMinimumValue"},Method->"Automatic"];
rl = MapThread[Rule, {var, res}];
Prepend[{rl}, nzf]
];
SolveDual[args___]:=(Message[SolveDual::argerr];$Failed);
SolveDual[zf_, eq_List, var_List, bd_:{},opts:OptionsPattern[LinearOptimization]]:=
Module[{obf, cmat, bvect, tobf, eqm, beq, res, nzf, yvar, dim,rl},
{obf, cmat, bvect} = LPtoMatrix[zf,eq, var];
tobf = First[#] & /@ bvect;
eqm=cmat[[1]];
beq=tobf[[1]];
cmat = SparseArray[cmat];
{res,nzf}=LinearOptimization[obf,{cmat,-tobf},{{eqm},{-beq}},{"DualMaximizer", "DualMaximumValue"},Method->"Automatic"];
dim = Dimensions[cmat];
yvar = Global`y[#] & /@ Table[i, {i, First[dim]}];
rl = MapThread[Rule, {yvar, First[res]}];
Prepend[{rl}, nzf]
];
(* Near Ring *)
NearRingQ[args___]:=(Message[NearRingQ::argerr];$Failed);
NearRingQ[set_List,T1_] := Module[{boolval},
boolval = Which[Depth[set] === 3, CheckNearRing[set,set,T1],
Depth[set] === 4, CheckNearRing[#,#,T1] & /@ set,
True, DisplayMessNearRing[set]];
Return[boolval]
];
CheckNearRing[Univers_List, RestSet_List, T2_, prevres_:{}] :=
Module[{fi, restuni, res, allres},
fi = Flatten[Take[RestSet, 1]];
res = NearRingDef[fi, #, T2, Univers] & /@ RestSet;
restuni = Delete[RestSet, 1];
allres = FlattenAt[Append[res, prevres], Length[res] + 1];
Which[Length[restuni] === 0, Apply[And, allres], True,
CheckNearRing[Univers, restuni, T2, allres]]
];
NearRingDef[A_, B_, R1_,Univers_List] := Module[{},
SameQ[Union[A, B],R1] || SameQ[Intersection[A, B], {}] || (Length[Position[Univers, Union[A, B]]] != 0 &&
Length[Position[Univers, Intersection[A, B]]] != 0)
];
DisplayMessNearRing[set_List] := (Print["Depth is equal to ", Depth[set]];
Print["The collection of sets must be of depth 3 or 4."];
Print["Usage: NearRi[set]"]);
(* Airport Cost Allocation Problem *)
AirportProblem[args___]:=(Message[AirportProblem::argerr];$Failed);
AirportProblem[cost_List,nj_List]:=Module[{tmv,evc,clv},
tmv=Total[nj];
(* Checking if the game is not too large. *)
If[SameQ[LessEqual[Total[nj],48],True],
evc=ArrayFlatten[Table[Array[cost[[i]] & ,nj[[i]]],{i,1,Length[nj]}],1];
clv=Max[#] &/@ Subsets[evc];
clv /. clv[[1]]->0,
Print["Game is too large! Should not exceed 48 Players!"];
Return[{}];
]
];
(* Market Situation *)
teilm[T_List]:=Sort[Flatten /@ Distribute[({{}, {#1}} &) /@ T, List]];
ComplementaryMarket[args___]:=(Message[ComplementaryMarket::argerr];$Failed);
ComplementaryMarket[T_List,P_List,Q_List,opts:OptionsPattern[ComplementaryMarket]]:= Module[{em,param,coal,val},
em = Intersection[P,Q];
Which[Length[em] != 0, Print["The sets P and Q are not disjoint."]; Return[],
True,
param = OptionValue[MarketParameter];
coal = Subsets[T];
val = Min[Length[Intersection[#, P]], a Length[Intersection[#, Q]]] & /@ coal;
val /. a -> param
]
];
(* Cost Location Game *)
PQNorm[args___]:=(Message[PQNorm::argerr];$Failed);
PQNorm[liste_, refliste_,p_:2,q_:1]:=
Which[Depth[liste] == 3, PQNormDist[#, refliste,p,q] & /@ liste,
Depth[liste] == 2, PQNormDist[liste, refliste,p,q],
True,DisplayPQNrm[liste]];
PQNormDist[liste_, refliste_,p_:2,q_:1]:= Power[Total[ MapThread[Power[#1 - #2, p] &, {liste, refliste}]], (q/p)];
DisplayPQNrm[liste_]:=(
Print["Depth is equal to ",Depth[liste]];
Print["Usage: PQNorm[liste,refliste,p,q]"];
Print["Input format of the variable 'liste' is not correct."];
Print["The variable 'liste' must be a list."]
);
CostLocationGame[args___]:=(Message[CostLocationGame::argerr];$Failed);
CostLocationGame[dmpts_, refvc_,p_:2,q_:1,fixed_:0]:=Block[{st,nb,pos,smvc,cdco,tvc,avvc,objvl},
st = Range[First[Dimensions[dmpts]]];
nb=1+Length[st];
pos=Outer[List,Drop[Subsets[st],nb]];
cdco=Length[#] &/@ pos;
smvc=Total[Extract[dmpts,#]] &/@ pos;
avvc=smvc/cdco;
tvc=Extract[dmpts,#] &/@ pos;
objvl=Total[#] &/@ Table[PQNorm[N[tvc[[i]]],avvc[[i]],p,q],{i,Length[avvc]}];
PrependTo[objvl,Array[0 &,nb-1]];
objvl=Flatten[objvl]+fixed;
{PrependTo[objvl,0], avvc, CostSavings[objvl,st]}
];
CostLocationGame[dmpts_, refvc_,p_:2,q_:1,fixed_:0,opts:OptionsPattern[CostLocationGame]]:=Module[{mthd,st,refpt,nrmlist,nb,pos,objli,zeros,nonneg,slvprb,optsol,objvl},
mthd=OptionValue[Method];
st = Range[First[Dimensions[dmpts]]];
refpt = x[#] &/@ Range[Length[refvc]];
nrmlist=PQNorm[#,refpt,p,q] &/@ N[dmpts];
nb=1+Length[st];
pos=Outer[List,Drop[Subsets[st],nb]];
objli=Total[Extract[nrmlist,#]] &/@ pos;
zeros=Array[0 &, Length[refpt]];
nonneg=Apply[And,MapThread[GreaterEqual,{refpt,zeros}]];
(* slvprb=NMinimize[Prepend[{nonneg},#],refpt,Method->mthd] &/@ objli;*)
slvprb=NArgMin[Prepend[{nonneg},#],refpt,Method->mthd] &/@ objli;
(* optsol=Last[#] &/@ slvprb; *)
optsol=MapThread[Rule,{refpt,#}] &/@ slvprb;
objvl=MapThread[ReplaceAll,{objli,optsol}];
PrependTo[objvl,Array[0 &,nb-1]];
objvl=Flatten[objvl]+fixed;
{PrependTo[objvl,0], refpt /. optsol, CostSavings[objvl,st]}
];
CostSavings[costvec_List,T_List] := Block[{cs},
MapThread[SetDelayed[c[#1], #2] &, {Subsets[T], costvec}];
cs=(Total[c[{#}] & /@ #] - c[#]) & /@ Subsets[T];
Flatten[{0,Drop[cs,1]}]
];
(* Example for calling different solvers.
a1={0,0};
a2={1/2,Sqrt[3]/2};
a3={1,0};
xx={x1,x2};
dmpts={a1,a2,a3};
cval2=CostLocationGame[dmpts,xx,2,4,5/24,Method->#] &/@ {"Automatic", "NelderMead", "DifferentialEvolution", "SimulatedAnnealing"}
*)
(* Product Game *)
ProductGame[args___]:=(Message[ProductGame::argerr];$Failed);
ProductGame[wghs_List]:=Module[{xlis,pval,chval,ylis,hdval},
xlis = Subsets[wghs];
pval=Apply[Times,#] &/@ xlis;
chval=pval-1;
ylis =Subsets[wghs-1];
hdval=Apply[Times,#] &/@ ylis;
{chval,hdval} (*characteristic values and Harsanyi dividends. *)
];
(* Probability Game *)
ProbabilityGame[args___]:=(Message[ProbabilityGame::argerr];$Failed);
ProbabilityGame[wghs_List]:=Module[{xlis,pval,chval},
If[Apply[And,GreaterEqual[#,0] &/@ wghs] && Apply[And,LessEqual[#,1] &/@ wghs],
xlis = Subsets[wghs];
pval=Apply[Times,1-#] &/@ xlis;
chval=1-pval,Print["The weights must lie between zero and one."]]
];
DualProbabilityGame[args___]:=(Message[DualProbabilityGame::argerr];$Failed);
DualProbabilityGame[wghs_List]:=Module[{xlis,pval,dpval,chval},
If[Apply[And,GreaterEqual[#,0] &/@ wghs] && Apply[And,LessEqual[#,1] &/@ wghs],
xlis = Subsets[wghs];
pval=Apply[Times,1-#] &/@ xlis;
dpval=Apply[Times,1-#] &/@ Reverse[xlis];
chval=(1-pval)*dpval,Print["The weights must lie between zero and one."]]
];
(* Bankruptcy Situation *)
x[S_List]:= Plus @@ x /@ S;
ModestBankruptcy[args___]:=(Message[ModestBankruptcy::argerr];$Failed);
ModestBankruptcy[E_?NumberQ,claims_List]:= Module[{lc,T,asscl,compset,vecval},
lc=Length[claims];
T=Range[lc];
asscl = MapThread[Rule,{x /@ T,claims}];
compset = Reverse[Subsets[T]];
vecval = Max[0, E - x[#]] &/@ compset;
vecval /.asscl
];
GreedyBankruptcy[args___]:=(Message[GreedyBankruptcy::argerr];$Failed);
GreedyBankruptcy[E_?NumberQ,claims_List]:= Module[{lc,T,asscl,vecval},
lc=Length[claims];
T=Range[lc];
asscl = MapThread[Rule,{x /@ T,claims}];
vecval = Min[E, x[#]] &/@ Subsets[T];
vecval /.asscl
];
ContestedGarment[args___]:=(Message[ContestedGarment::argerr];$Failed);
ContestedGarment[Estate_?NumberQ, Claims_List] :=
Module[{clset, extdset, award, param},
clset = If[Length[Claims] === 2, Map[x[#] &, Range[2]], ErrorMessage; Return[]];
extdset = {clset, Reverse[clset]};
award = MapThread[(E - Max[0, E - #1] - Max[0, E - #2])/2 + Max[0, E - #2] &, extdset];
param = MapThread[Rule, {{E, clset[[1]], clset[[2]]}, {Estate, Claims[[1]], Claims[[2]]}}];
award /. param
];
ErrorMessage := (Print["The Contested Garment Problem is a two-Creditor Bankruptcy Problem."];
Print["A Claims List of the Length of two is expexted like: ", "{d1,d2}"];);
TalmudicRule[args___]:=(Message[TalmudicRule::argerr];$Failed);
TalmudicRule[Estate_?NumberQ, Claims_List] :=
Module[{clvar, sumcl, param, eqsys, nclsum,sol, sol01},
clvar = Map[x[#] &, Range[Length[Claims]]];
sumcl = Total[ clvar];
param = MapThread[Rule, {clvar, Claims}];
nclsum = sumcl /. param;
eqsys =
If[Greater[(1/2)*nclsum, Estate],
Min[\[Lambda], (1/2)*#] & /@ Claims,
Max[(# - \[Lambda]), (1/2)*#] & /@ Claims];
sol = Reduce[Total[ eqsys] == Estate, \[Lambda]];
sol01 = MapThread[Rule, {{\[Lambda]}, {sol[[2]]}}];
eqsys /. sol01
];
(* Assignment Problem *)
(* User interface *)
GenProfitMatrix[args___]:=(Message[GenProfitMatrix::argerr];$Failed);
GenProfitMatrix[valOfbuyers_List, valOfsellers_List] := Module[{prfij,valmat},
If[SameQ[First[Dimensions[valOfsellers]],First[Dimensions[valOfbuyers]]],
Which[SameQ[VectorQ[valOfbuyers],True],
valmat = Map[valOfbuyers - # &, valOfsellers];
prfij = Map[Max[0,#]&,#] & /@ valmat;
Transpose[prfij],
SameQ[MatrixQ[valOfbuyers],True],
valmat=valOfbuyers - valOfsellers;
prfij = Map[Max[0,#]&,#] & /@ valmat,
True, Print["Valuation of buyers is neither a vector nor a matrix."];
],
Print["Input data format is not correct. It must be symmetric."];
Print["Valuation of buyers must be a vector or a matrix of dimension: ", First[Dimensions[valOfsellers]] ];
]
];
AssignmentProblem[args___]:=(Message[AssignmentProblem::argerr];$Failed);
AssignmentProblem[buyers_List, sellers_List, profmat_List, opts:OptionsPattern[AssignmentProblem]] :=
Module[{bplayer, splayer, extprofmat},
vrb = OptionValue[Verbose];
Which[First[buyers] >= First[sellers], MessIdenticalPlayerSet;,
True,
{bplayer, splayer, extprofmat} =
If[Length[buyers] != Length[sellers],
MessInsertDummy;
ExtAssProb[buyers, sellers, profmat],
{buyers, sellers, profmat}];
AssignmentVal[bplayer, splayer, extprofmat, opts]
]
];
MessIdenticalPlayerSet := (Print[ "The set of buyers and sellers is identical."];
Print["Or the set of buyers and sellers is mixed up."];
Print["Rename at least the set of sellers"];
Print["Or put the set of buyers and sellers in correct order."]);
MessInsertDummy:=Print["Inserting dummy buyers/sellers to extend the asymmetric assignment problem into a symmetric one. "];
ExtAssProb[buyers_List, sellers_List, profmat_List] :=
Module[{newby, newsel, extmat},
{newby, newsel} = NewPlayerSet[buyers, sellers];
extmat = FillMatrix[profmat];
{newby, newsel, extmat}
];
NewPlayerSet[buyers_List, sellers_List] := Module[{bplayer, splayer},
Which[Length[buyers] > Length[sellers], \
splayer = Range[Length[buyers] + 1, 2Length[buyers]]; {buyers, splayer},
Length[buyers] < Length[sellers],
bplayer = Range[1, Length[sellers]];
splayer = Range[Length[bplayer] + 1, 2Length[bplayer]];
{bplayer, splayer},
True, {buyers, sellers}
]
];
FillMatrix[profmat_List] := Module[{dm},
dm = Dimensions[profmat];
Which[dm[[1]] > dm[[2]], ClmsFillZeros[profmat, dm[[1]], dm[[2]]],
dm[[1]] < dm[[2]], RwsFillZeros[profmat, dm[[1]], dm[[2]]],
True, profmat
]
];
ClmsFillZeros[profmat_List, rws_, clms_] := Module[{zromat, nwmat},
zromat = Table[Table[0, {i, rws}], {i, rws - clms}];
nwmat = FlattenAt[Append[Transpose[profmat], zromat], -1];
Transpose[nwmat]
];
RwsFillZeros[profmat_List, rws_, clms_] := Module[{zromat, nwmat},
zromat = Table[Table[0, {i, clms}], {i, clms - rws}];
nwmat = FlattenAt[Append[profmat, zromat], -1];
nwmat
];
AssignmentVal[bplayer_List, splayer_List, assmat_List, opts:OptionsPattern[AssignmentProblem]] := Module[{cmg,matchpl,T1},
vrb = OptionValue[Verbose];
Clear[T1];
T1= Union[bplayer, splayer];
cmg = Teilmg[T1];
Which[SubSetQ[#, bplayer], Set[v[#], 0],
SubSetQ[#, splayer], Set[v[#], 0],
True, matchpl = MatchPairs[bplayer, splayer,#, opts];
MaxProfit[matchpl, assmat, bplayer, splayer, opts]] & /@ cmg
];
(* Borrowed from M. Carter *)
Teilmg[T_List] :=Sort[Flatten /@ Distribute[{{},{#}} & /@ T, List]];
(* Main functions to compute the characteristic function values for an Assignment game. *)
MatchPairs[ bplayer_List, splayer_List, subst_List, opts:OptionsPattern[AssignmentProblem]] :=
Module[{vrb,intcob, intcos, permcb, extcob, extcos, mptprs,rvmp},
vrb = OptionValue[Verbose];
intcob = Intersection[subst, bplayer];
intcos = Intersection[subst, splayer];
If[SameQ[vrb,True],
Print["intcob=",intcob];
Print["intcos=",intcos];,
True];
Which[Length[intcob] > Length[intcos],
If[Length[intcos] === 1,
extcos = Flatten[Table[intcos, {i, Length[intcob]}]];
mptprs = MapThread[List, {intcob, extcos}];
If[vrb === True, Print["mptprs=", mptprs];,True];
Split[mptprs, Length[mptprs]],
{extcob,extcos} = ExtPlayerSet[intcob, intcos];
If[SameQ[vrb,True],
Print["extcob=", extcob];
Print["extcos=", extcos];,
True];
mptprs = MatchingPairs[extcos, extcob];
If[SameQ[vrb,True], Print["mptprs=", mptprs];,True];
Map[Reverse[#] &,#] & /@ mptprs ],
Length[intcob] < Length[intcos],
If[Length[intcob] === 1,
extcob = Flatten[Table[intcob, {i, Length[intcos]}]];
mptprs = MapThread[List, {intcos, extcob}];
rvmp = Reverse[#] & /@ mptprs;
Split[rvmp, Length[rvmp]],
{extcob,extcos} = ExtPlayerSet[intcob, intcos];
If[SameQ[vrb,True],
Print["extcob=", extcob];
Print["extcos=", extcos];,
True];
MatchingPairs[extcob, extcos]],
Length[intcob] == Length[intcos],
Which[Length[intcob] === 1, Flatten[{intcob, intcos}],
Length[intcob] === (Length[Union[bplayer, splayer]]/2),
permcb = Permutations[intcob];
MapThread[List, {#, intcos}] & /@ permcb,
True,
{extcob,extcos} = ExtPlayerSet[intcob, intcos];
If[SameQ[vrb,True],
Print["extcob=", extcob];
Print["extcos=", extcos];,
True];
mptprs = MatchingPairs[extcos, extcob];
If[SameQ[vrb,True], Print["mptprs=", mptprs];,True];
Map[Reverse[#] &,#] & /@ mptprs ]
]
];
ExtPlayerSet[intcob_List,intcos_List]:=Module[{extcob,extcos},
extcob = Flatten[Table[intcob, {i, 2}]];
extcos = Flatten[Table[intcos, {i, 2}]];
{extcob,extcos}
];
MatchingPairs[extbuyer_List, extseller_List] := Module[{tkmin, nwsl, nwbuy,mptab},
tkmin = Min[Length[extbuyer], Length[extseller]];
nwsl = Table[Take[extseller, {i, i + (tkmin/2) - 1}], {i, (Length[extseller]/2)}];
nwbuy = If[OddQ[(Length[extbuyer]/2)] === True,
Table[Take[extbuyer, {i, i + (Length[extbuyer]/2) - 1}], {i, (Length[extbuyer]/2)}],
Table[Take[extbuyer, {i, i + (tkmin/2)-1}], {i, (Length[extbuyer]/2)}]];
mptab = Table[MapThread[List, {nwbuy[[i]], #}] & /@ nwsl, {i, Length[nwbuy]}];
Apply[Join, mptab]
];
MaxProfit[matchli_List, assmat_List, bplayer_List, splayer_List, opts:OptionsPattern[AssignmentProblem]] :=
Module[{vrb,matchmat, profitmat, profitli},
vrb = OptionValue[Verbose];
If[SameQ[vrb,True], Print["matpl=", matchli];, True];
Clear[Global`beta];
matchmat = Thread[List[#,splayer]] & /@ bplayer;
profitmat = Map[Global`beta, #] & /@ matchmat;
MapThread[Set[#1, #2] &, {profitmat, assmat}];
profitli = Which[Depth[matchli] === 2, Global`beta[matchli] ,
Depth[matchli] === 3, Global`beta[#] & /@ {matchli},
Depth[matchli] === 5, Table[Table[Global`beta[#] & /@ matchli[[j, i]], {i, Length[matchli[[j]]]}], {j, Length[matchli]}],
True, Table[Global`beta[#] & /@ matchli[[i]], {i, Length[matchli]}]];
If[SameQ[vrb,True], Print["prfli=", profitli];, True];
Which[Depth[matchli] <= 3, Max[Total[ profitli]],
Depth[matchli] === 5, Max[Table[Total[ #] & /@ profitli[[i]], {i, Length[profitli]}]],
True, Max[Total[ #] & /@ profitli]]
];
(* Euclidean Distance, Spelling Euclidian is not protected! *)
EuclidianDistance[args___]:=(Message[EuclidianDistance::argerr];$Failed);
EuclidianDistance[liste_,refliste_]:=
Which[Depth[liste] == 3, EuclidianDist[#, refliste] & /@ liste,
Depth[liste] == 2, EuclidianDist[liste, refliste],
True,DisplayEuk[liste]];
EuclidianDist[liste_, refliste_] := N[Power[Total[ MapThread[Power[#1 - #2, 2] &, {liste, refliste}]], (1/2)]];
DisplayEuk[liste_]:=(
Print["Depth is equal to ",Depth[liste]];
Print["Usage: EuclidianDistance[liste,refliste]"];
Print["Input format of the variable 'liste' is not correct."];
Print["The variable 'liste' must be a list."]
);
(* Assigning symmetric values *)
AssignValues[univers_List, alp_List] := Module[{},
Which[Length[alp] != 0,
Which[First[univers] === First[alp], Global`\[Alpha],
Length[First[univers]] <= 4, Global`\[Lambda], True, Global`\[Sigma]],
True,
Which[Length[First[univers]] == 5,Global`\[Theta],
Length[First[univers]] == 6, Global`\[Phi],
Length[First[univers]] >= 7,
If[Length[First[univers]] === 7, Global`\[Beta],
v[First[univers]] = Global`\[Gamma]], True, Global`\[Sigma]]]];
Coal2Dec[args___]:=(Message[Coal2Dec::argerr];$Failed);
Coal2Dec[n_Integer]:=Module[{T,ps,prs,xp,sxp},
T=Range[n];
ps=Subsets[T];
prs=Delete[ps,1];
xp=prs-1;
sxp=(2^#)&/@xp;
Total[#]&/@ sxp
];
Sets2Dec[args___]:=(Message[Sets2Dec::argerr];$Failed);
Sets2Dec[sets_List]:=Module[{xp,sxp},
xp=sets-1;
sxp=(2^#)&/@xp;
Total[#]&/@ sxp
];
BalancedSystemQ[args___]:=(Message[BalancedSystemQ::argerr];$Failed);
BalancedSystemQ[coll_List, T_List, opts:OptionsPattern[BalancedSystemQ]] :=
Module[{mthd,zvec, ovec, pos, mat, tmat, smat, d1, d2, veco, zf, bv, yineq, yeq, cf, rs, bq, bcQ},
mthd=OptionValue[Method];
zvec = Array[0 &, Length[T]];
ovec = Array[1 &, Length[T]];
pos = Outer[List, #] & /@ coll;
mat = ReplacePart[zvec, 1, #] & /@ pos;
tmat = Transpose[mat];
{d1, d2} = Dimensions[tmat];
veco = Table[1, {i, d2}];
(*max Problem*)
zf = -tmat.veco;
AppendTo[mat, ovec];
bv = Array[0 &, d2 + 1];
smat = SparseArray[mat];
{{yineq,yeq},res}=LinearOptimization[zf,{smat,bv},{{ovec},{0}},{"ConstraintSensitivity","PrimalMinimizer"},Method->mthd];
cf = (Delete[-yineq, -1] + 1);
rs = tmat.cf;
bq = Round[res];
(*
Print["bq=",bq];
Print["cf=",cf/First[rs]];
*)
bcQ = FreeQ[bq, _?Positive] && FreeQ[bq, _?Negative] && Apply[And, NumberQ[#] & /@ bq];
If[SameQ[bcQ, True], {bcQ, cf/First[rs]},
{bcQ, Array[Indeterminate &, Length[T]]}]
];
WeaklyBalancedSystemQ[args___]:=(Message[WeaklyBalancedSystemQ::argerr];$Failed);
WeaklyBalancedSystemQ[coll_List, b0_List,T_List, opts:OptionsPattern[BalancedSystemQ]] :=
Module[{mthd,zvec, ovec, coll0,pos0, pos, mat,tmat, smat, d1, d2, veco, zf, bv, yineq, yeq, bq},
mthd=OptionValue[Method];
zvec = Array[0 &, Length[T]];
ovec = Array[1 &, Length[T]];
coll0=Complement[coll,b0];
pos0 = Outer[List, #] & /@ coll0;
mat0 = ReplacePart[zvec, 1, #] & /@ pos0;
tmat = Transpose[mat0];
{d1, d2} = Dimensions[tmat];
veco = Table[1, {i, d2}];
(*max Problem*)
zf = -tmat.veco;
pos = Outer[List, #] & /@ coll;
mat = ReplacePart[zvec, 1, #] & /@ pos;
AppendTo[mat, ovec];
tmat = Transpose[mat];
{d1, d2} = Dimensions[tmat];
bv = Array[0 &, d2];
smat = SparseArray[mat];
{{yineq,yeq},res}=LinearOptimization[zf,{smat,bv},{{ovec},{0}},{"ConstraintSensitivity","PrimalMinimizer"},Method->mthd];
bq = Round[res];
FreeQ[bq, _?Positive] && FreeQ[bq, _?Negative] && Apply[And, NumberQ[#] & /@ bq]
];
GetCardinalityGame[args___]:=(Message[GetCardinalityGame::argerr];$Failed);
GetCardinalityGame[T_List,k_Integer]:=Module[{cos},
cos = Subsets[T];
If[LessEqual[Length[#], k],0,Length[#]] & /@ cos
];
SymGameSizeK[args___]:=(Message[SymGameSizeK::argerr];$Failed);
SymGameSizeK[T_List,k_Integer,val_Integer]:=Module[{lt2,sbs,rl,tkr,srl},
lt2=Length[T]/2;
sbs=Subsets[T];
Set[v[#],0]& /@ sbs;
v[T]=lt2*val;
rl=RotateLeft[T,#] & /@ T;
tkr=Take[#,-k] & /@ rl;
srl=Sort[#] & /@ tkr;
Set[v[#],val]& /@ srl;
v[#] & /@ sbs
];
SymGameType2[args___]:=(Message[SymGameType2::argerr];$Failed);
SymGameType2[T_List,S_List,val_Integer]:=Module[{S2,sbs,csb,asv,cl2,cw},
S2=Complement[T,S];
sbs=Subsets[T];
cl2=If[SameQ[Length[#],2],#,{}] & /@ sbs;
cl2=DeleteCases[cl2,{}];
csb=Complement[Drop[sbs,-1],cl2];
v[T]=2*val;
asv=Thread[AssValToCoal2[#[[1]],#[[2]],val,S,S2]] & /@ cl2;
cw=v[#]& /@ sbs;
MapThread[Set[v[#1],#2] &,{cl2,asv}];
Set[v[#],0]& /@ csb;
v[#] & /@ sbs
];
SymGameType3[args___]:=(Message[SymGameType3::argerr];$Failed);
SymGameType3[T_List,S_List,val_Integer]:=Module[{S2,sbs,csb,asv,cl3,cw},
S2=Complement[T,S];
sbs=Subsets[T];
cl3=If[SameQ[Length[#],3],#,{}] & /@ sbs;
cl3=DeleteCases[cl3,{}];
csb=Complement[Drop[sbs,-1],cl3];
v[T]=2*val;
asv=Thread[AssValToCoal3[#[[1]],#[[2]],#[[3]],val,S,S2]] & /@ cl3;
cw=v[#]& /@ sbs;
MapThread[Set[v[#1],#2] &,{cl3,asv}];
Set[v[#],0]& /@ csb;
v[#] & /@ sbs
];
SymGameType4[args___]:=(Message[SymGameType4::argerr];$Failed);
SymGameType4[T_List,S_List,val_Integer]:=Module[{S2,sbs,csb,asv,cl4,cw},
S2=Complement[T,S];
sbs=Subsets[T];
cl4=If[SameQ[Length[#],4],#,{}] & /@ sbs;
cl4=DeleteCases[cl4,{}];
csb=Complement[Drop[sbs,-1],cl4];
v[T]=2*val;
asv=Thread[AssValToCoal4[#[[1]],#[[2]],#[[3]],#[[4]],val,S,S2]] & /@ cl4;
cw=v[#]& /@ sbs;
MapThread[Set[v[#1],#2] &,{cl4,asv}];
Set[v[#],0]& /@ csb;
v[#] & /@ sbs
];
AssValToCoal2[i_Integer,j_Integer,val_Integer,S1_List,S2_List]:=Module[{},
Which[SameQ[(i!=j),True],
If[(MemberQ[S1,i] && MemberQ[S1,j]),v[{i,j}]=val,0],
True, Print["NAN"];
]
];
AssValToCoal3[i_Integer,j_Integer,k_Integer,val_Integer,S1_List,S2_List]:=Module[{},
Which[SameQ[(i!=j!=k),True],
If[(MemberQ[S1,i] && MemberQ[S1,j] && MemberQ[S2,k]),v[{i,j,k}]=val,0],
True, Print["NAN"];
]
];
AssValToCoal4[i_Integer,j_Integer,k_Integer,l_Integer,val_Integer,S1_List,S2_List]:=Module[{},
Which[SameQ[(i!=j!=k!=l),True],
If[(MemberQ[S1,i] && MemberQ[S1,j] && MemberQ[S2,k] && MemberQ[S2,l]),v[{i,j,k,l}]=val,0],
True, Print["NAN"];
]
];
(* Lie Groups *)
LieBracket[args___]:=(Message[LieBracket::argerr];$Failed);
LieBracket[mat01_?ListQ,mat02_?ListQ]:= mat01.mat02 - mat02.mat01;
(* Linear Algebra *)
(* Inspired by StackExchange: https://math.stackexchange.com/questions/4266981/a-simple-case-of-euclidean-space-vector *)
SortVecDecOrder[args___]:=(Message[SortVecDecOrder::argerr];$Failed);
SortVecDecOrder[vec_List]:=Block[{lv,T1,pws,szp,it,pos},
lv=Length[vec];
T1=Range[lv];
pws=Drop[Subsets[T1],1];
szp=Length[#] &/@ pws;
it=Extract[pws,Position[szp,#]] &/@ T1;
pos=Outer[List,#] &/@ it;
Map[Max[Min[Extract[vec,#]] &/@ #] &, pos]
];
(* Borrowed from WolframMathWorld *)
AdjointMatrix[args___]:=(Message[AdjointMatrix::argerr];$Failed);
AdjointMatrix[mat_List] := (Conjugate@Transpose@mat);
IsHermitianMatrixQ[args___]:=(Message[IsHermitianMatrixQ::argerr];$Failed);