I have a list of products and each product is connected to another. Each connection strength_level ranges from 1 to 10.
Product A to B strength_level=7
Product A to c strength_level=8
Product B to A strength_level=2
Product B to C strength_level=2
Product C to A strength_level=4
Product C to B strength_level=3
I want to convert this code to an equation. My code:
Foreach(products as product){
// strength variables
$outwardTotal = 0;
$inwardTotal= 0;
// Get in and out connections
$connectionToOthers = [sqlArray]
$connectionToMe = [sqlArray]
// Loop through all connections from this to other
Foreach($connectionToOthers as $outward){
$outwardTotal = $outwardTotal+ $outward['strength_level'] + 4;
}
// Loop through all connections fromt other product to this
Foreach($connectionToMe as $inwards){
$inwardTotal= $inwardTotal+ $inwards['strength_level'] + 1;
}
$outwardAvg = $outwardTotal/COUNT($connectionToOthers);
$inwardAvg= $inwardTotal/COUNT($connectionToMe);
}
$final_strength = ($outwardAvg + $inwardAvg)/(COUNT($connectionToOthers) + COUNT($connectionToMe));
I have attempted the following:https://i.stack.imgur.com/kGNRw.png where c is number of products, n outward connections and m is for inward connections and S is the strength of the connection.