# Upper bound algorithm how can I translate my algorithm in julia code

**URL:** <https://discourse.julialang.org/t/upper-bound-algorithm-how-can-i-translate-my-algorithm-in-julia-code/57729>\
**Category:** Optimization (Mathematical)\
**Tags:** homework\
**Created:** [March 22, 2021, 3:37pm UTC](https://discourse.julialang.org/t/upper-bound-algorithm-how-can-i-translate-my-algorithm-in-julia-code/57729 "2021-03-22T15:37:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasmine\_123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yasmine_123/32/23177_2.png) [@Yasmine\_123](https://discourse.julialang.org/u/Yasmine_123)\
**Post date:** [March 22, 2021, 3:37pm UTC](https://discourse.julialang.org/t/upper-bound-algorithm-how-can-i-translate-my-algorithm-in-julia-code/57729/1 "2021-03-22T15:37:02Z")

</div>

Hi everyone,  
I am a new user of julia.  
I should write an optimistic algorithm given the similarity parameters sij and the number of families r, partition the m product types into r families G1, …, Gr, each of size m/r, so as to maximize the total similarity index. let say that m=60 and r=6  
my idea is:  
step 1: we set an array S such that  
Sij=sij si i\<j  
Sij= -1 si ij  
we define a variable sum= 0

step 2: starting with k=1 we find w=max{Sij}  
we do sum= sum + w

step 3: if si0j0 = w then we find  
a= Max { Si0j } and b=max { Sij0 }

if a\>b we do Si0j = -1 for each j  
if a b we do Sij0 = -1 for each i

step 4:  
if k\<r we do  
k= k+1 and then back to step 2  
if k=r we continue to step 5

step 5: sum\* ((((m/r)-1))\*(m/r))/2) → is the upper bound

So basically I set to -1 every elements that’s in the same line or column depending on where is the biggest similarity with the object i0j0 so that later when looking for the maximum we can not find any value of interest in this line/column.  
And at the end we have “sum” which will be composed of the six highest similarities that are independent which means not a same object can be twice in the same family. Then you multiply it by 45 (If we are in the instance m=60 r=6). So that means we would have in each family the biggest similarities between all the elements such that it would be 45 times this similarity in the family.

Can you please help me to write down this algorithm using julia code.

Thank you in advance

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 22, 2021, 5:15pm UTC](https://discourse.julialang.org/t/upper-bound-algorithm-how-can-i-translate-my-algorithm-in-julia-code/57729/2 "2021-03-22T17:15:20Z")

</div>

Is this a homework problem? What have you tried and what problems have you encountered?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 23, 2021, 9:18am UTC](https://discourse.julialang.org/t/upper-bound-algorithm-how-can-i-translate-my-algorithm-in-julia-code/57729/3 "2021-03-23T09:18:51Z")

</div>

Please see the (draft) homework policy here:

> [@Homework policy](https://discourse.julialang.org/t/homework-policy/2342/17):
>
> First draft of homework policy, please comment. Thanks for the suggestions, I believe that I incorporated all of them. I aimed for brevity at the expense of details, as I imagine very long documents would not be read. Homework guidelines for students Make sure that you are aware of school and course policy for asking and accepting outside help with homework. It is your responsibility to make sure you adhere to these. It is OK to ask help with homework questions on this forum. Strictly speaki…
