Potreboval bych poradit
Potrebuji posilat signal z aktivnich uzlu -> hodnota vetsi jak >0 pro nekolik iteraci
Uzly mam A1, A2, I1, I2, T, R1, R2 atd....
napr.
A1 A2 I1 I2 R1 R2 T
0. iterace 1 0 0 0 0 0 0
= > posilat signal budu pouze s A1 -> (> 0)
hodnotu signalu vypocitam = (1 * hodnota A1 / pocet vystupnich hran ^ 0.5) * 0,8
= > 1. iterace sousedni hrany A1 jsou I1 I2 = 2 vystupni hrany hodnota signalu je 0,56
A1 A2 I1 I2 R1 R2 T
1. iterace 1 0 0,56 0,56 0 0 0
I1 ma sousedy R1 T ale take zpet A1
I2 ma sousedy R2 T ale take zpet A1
hodnota je 0,26
A1 A2 I1 I2 R1 R2 T
2. iterace 1, 52 0 1,13 1,13 0,26 0,26 0,52
Prosim o radu jak to nejak z automatizovat uzly a hrany mam ulozene ve strukturach. Dekuji za kazdou radu.
#use warnings;
use utf8;
use open qw( :encoding(UTF-8) :std );
use Data::Dumper;
$, = "\t";
@nodes_types = ();
%link_types = ();
%nodes = ();
@links = ();
%initial_activation = ();
%link_weights = ();
%alg_parameters = ();
################### 1. NACIST DATA ###################
open(INPUT, "<:encoding(UTF-8)", "sitparametry.txt") || die "nelze otevrit vstupni soubor!";
while (<INPUT>){
chomp;
my @radky = split(/\s+/);
if (@radky) {
if($radky[0] eq "nt"){
my $type = $radky[1];
push(@nodes_types,$type);
}
elsif($radky[0] eq "ltra"){
my $type_name = $radky[1];
my $type_of_reciprocal_link = $radky[2];
$link_types{$type_name} = $type_of_reciprocal_link; #link_types ( type name, type of reciprocal link )
}
elsif($radky[0] eq "n"){
my $nodeId = $radky[1];
my $nodeType = $radky[2];
$nodes{$nodeId} = $nodeType; #nodes (NodeID, NodeType)
}
elsif($radky[0] eq "l"){
my $initial_node = $radky[1];
my $terminal_node = $radky[2];
my $link_type = $radky[3];
@vektor_link = ($initial_node, $terminal_node, $link_type);
push(@links,[@vektor_link]); #links (initial node, terminal node, link type
}
elsif($radky[0] eq "ia"){
my $nodeId = $radky[1];
my $activation_level = $radky[2];
$initial_activation{$nodeId} = $activation_level; #initial activation (NodeID, Activation Level)
}
elsif($radky[0] eq "lw"){
my $link_type = $radky[1];
my $weight = $radky[2];
$link_weights{$link_type} = $weight; #link weights (link_type, weight)
}
elsif($radky[0] eq "Beta"){
my $value = $radky[1];
$alg_parameters{"Beta"} = $value; #Beta value
}
elsif($radky[0] eq "IterationsNo"){
my $value = $radky[1];
$alg_parameters{"IterationsNo"} = $value; #Iteration's value
}
elsif($radky[0] eq "Calibration"){
my $value = $radky[1];
$alg_parameters{"Calibration"} = $value; #Calibration's value
}
elsif($radky[0] eq "a"){
my $value = $radky[1];
$alg_parameters{"a"} = $value;
}
elsif($radky[0] eq "b"){
my $value = $radky[1];
$alg_parameters{"b"} = $value; # b value
}
elsif($radky[0] eq "c"){
my $value = $radky[1];
$alg_parameters{"c"} = $value; # c value
}
elsif($radky[0] eq "t"){
my $value = $radky[1];
$alg_parameters{"t"} = $value; # t value
}
}
}
close(INPUT);
#seznam uzlu
%list_nodes = ();
#seznam hran
@list_links = ();
foreach my $id (keys %nodes){
my $type = $nodes{$id};
my $value = $initial_activation{$id};
if (!defined $value){
$value = 0;
}
$list_nodes{$id} = {"type",$type,"value",$value};
}
print Dumper %list_nodes;
#print Dumper %list_nodes;
#print Dumper $list_nodes{"A1"}{"value"};
#print Dumper $list_nodes{"A2"}{"value"};
#print Dumper $list_nodes{"T"}{"value"};
foreach my $i (0..$#links){
my $initial_node = $links[$i][0];
my $terminal_node = $links[$i][1];
my $link_type = $links[$i][2];
my $link_weights = $link_weights{$link_type};
my $type_of_reciprocal_link = $link_types{$link_type};
my %link = ("initial_node", $initial_node, "terminal_node", $terminal_node, "link_type", $link_type, "link_weights", $link_weights);
push(@list_links, \%link);
my $link_weights = $link_weights{$type_of_reciprocal_link};
my %link = ("initial_node", $terminal_node, "terminal_node", $initial_node, "link_type", $type_of_reciprocal_link, "link_weights", $link_weights);
push(@list_links, \%link);
}
print Dumper(@list_links);
print Dumper ($list_links[0]{"initial_node"});
################### OK NACTENA DATA OK ###################
################### OK VYTVORIT VHODNOU STRUKTURU OK ###################
$type_calibration = $alg_parameters{"Calibration"};
$a = $alg_parameters{"a"};
$b = $alg_parameters{"b"};
$c = $alg_parameters{"c"};
$t = $alg_parameters{"t"};
@matice = ();
@vektor_hodnot = ();
# vytvoreni vektoru uzlu podle abecedy
@hlavicka_uzlu = ();
foreach my $node (sort keys %list_nodes){
push(@hlavicka_uzlu, $node);
}
push(@matice,[@hlavicka_uzlu]);
# vytvoreni vektoru hodnot 0. iterace
for my $i (@hlavicka_uzlu){
my $value = $list_nodes{$i}{"value"};
push(@vektor_hodnot, $value);
}
push(@matice,[@vektor_hodnot]);
print Dumper @matice;