0
$\begingroup$

I have this code:

Ind = 10; StrategiesCop = {"1DD", "1CD", "2DD", "2DC"};Populations = UndirectedGraph[Flatten[Table[i -> j, {i, 2, Ind}, {j, i - 1}]], 
VertexLabels -> Thread[Table[i, {i, 1, Ind}] -> 
 PadRight[StrategiesCop, Ind, StrategiesCop]]]

enter image description here

Then I want to make the list of EdgeWeight with the next conditions:

  1. The EdgeWeight between same labels is v+(1-v)f where f is the frequency of label, in example : 1DD-1DD -> v+(1-v)0.3

  2. v is a parametre that I can change

  3. The EdgeWeight between different labels is (1-v)

Can I make a adjacency matrix and then the lists of EdgeWeight? o How can I do it?

$\endgroup$

1 Answer 1

1
$\begingroup$

I would create a graph after EdgeWeight is constructed.

Ind = 10; StrategiesCop = {"1DD", "1CD", "2DD", "2DC"};
nodeLabel = 
  Thread[Table[i, {i, 1, Ind}] -> 
     PadRight[StrategiesCop, Ind, StrategiesCop]] // Association;
f = nodeLabel // Tally //  MapAt[ #/Ind &, {All, 2}] // 
    Map[  Apply[Rule]] // Association;
allPairs = Subsets[Range[Ind], {2}];
grouped = 
  allPairs // 
   GroupBy[  nodeLabel[# [[1 ]]] == nodeLabel[# [[2 ]]] &];
edges = grouped // Values // Catenate;
edgeWeight[v_] = Join[
   ConstantArray[ 1 - v, Length@grouped[False]]
   , grouped[True]  // Map[ (1 - v) f[ nodeLabel[# [[1 ]]]] + v &]
   ];

UndirectedGraph[ edges , EdgeWeight -> edgeWeight[v], 
 EdgeLabels -> "EdgeWeight", VertexLabels -> Normal@nodeLabel]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.