# Efficient Strategies Algorithms for Resource Allocation Problems
## Appendix A.2.3 Simulating Strategies with Heterogeneous Resources  
For strategies simulation from propositions 2 and 3 we are going to consider Code A6.  
Code A6: Calculation of the complexity of the strategy simulation algorithm for heterogeneous resources  
```
staticvoidsimulerResourcesHeterogenes(int...champ_val){ if(champ_val.length=0){ champ_val=newint[BATTLEFIELDS]; for(inti=0;i<BATTLEFIELDS;i++){ champ_val[i]=1; } } intgain,egalite,defaite; intcompteur_j1,compteur_j2; Ressource[]ressources=[newResource(2),newResource(),newResource(2), newResource(5),newResource(),newResource(),newResource(),newResource(),newResource(),newResource()); for(int[i]st:strategies.values(){ Stringkey=Strategie.getKey(st); strategiesResourcesHeterogenes.put(key,Strategie.changeStrategieAleatoire(st,ressources)); } for(int[]stg:strategies.values()){ Stringkey=Strategie.getKey(stg); stg=strategiesResourcesHeterogenes.get(key); gain=0; egalite=0; defaire=0; for(int[]sta:strategiesResourcesHeterogenes.values()){ computeur_j1=0; compteur_j2=0; for(inti=0;i<stg.length;i++){ if(stg[i]>sta[i]) computeur_j1+=champ_val[i]; elseif(stg[i]<sta[i]) computeur_j2+=champ_val[i]; } if(compteur_j1>compteur_j2) gain++; elseif(compteur_j1<compteur_j2) defaire++; else else++; } int[]tab={gain,egalite-1,defaite}; commbat.put(key,tab); }
```  
To make complexity analysis, we divided the algorithm into 4 parts as follows:  
```
(1) (\(lines\)14\(to\)18):\(\theta(nbs)\times(E)\)where(E)=[\(\theta(nb)+\theta(nb\_soldats\times nb\_soldats\times nb\times nbw)\)]
2 (\(from\)line\(28\)to\(line\)33):\(\theta(nb)\)
3 (\(from\)line\(25\)to\(line\)40):\(\theta(nbs)\times(2)=\theta(nbs)\times\theta(nb)\)
4 (\(from\)line\(19\)to\(line\)43):\(\theta(nbs)\times(3)=\theta(nbs)\times\theta(nbs)\times\theta(nb)\)
```  
Finally, the complexity of the algorithm is as follows:  
```
(1)+(4):\(\theta(nbs\times nb\_soldats\times nb\_soldats\times nb\times nbw)+\theta( nbs)\times\theta(nbs)\times\theta(nb)=\theta(nbs\times nb\_soldats\times nb\times nbw)\)
```  
The complexity of this algorithm is (C6): \(\theta(nbs\times nb\_soldats\times nb\_soldats\times nb\times nbw)\)  
Appendix A.2.4. Generating New Strategy with Heterogeneous Resources in a Random Manner  
The source code A7 above is the algorithm for \"\(changeStrategieAleatoire\)\" method used to convert a strategy into a new strategy with the values of heterogeneous resources randomly.  
```
publicstaticint[]changerStrategieAleatoire(intstrat,Resource[]ressources){ int[]intintle=strat.length; int[]newStrat=newint[tainle]; r=newrandom(); intvalue=0; booleanfind; List<Integer>used=newArrayList<Integer>(); for(inti=0;i<tainle;i++){ value=0; for(intj=0;j<strat[i];j++){ find=false; intui; do{ ui=r.nextint(ressources.length); if(!used.contains((Integer))ui){ value+=resources[ui].getValue(); used.add(ui); find=true; } while(!find); } newStrat[i]=value; returnnewStrat;
```  
Let us consider this complexity analysis:  
\(\theta(nb)\times\theta(nb\_solats)\times\theta(nbw)\times\theta(nb\_solats)= \theta(nb\_solats\times nb\_solats\times nb\times nbw)\): (E)  
The complexity (C7): \(\theta(nb\_solats\times nb\_solats\times nb\times nbw)\).  
Generating Arbitrarily New Strategy with Heterogeneous Resources  
The algorithm in code Code A8 does almost the same thing as that shown in Code A7. However, the first one generates strategies arbitrarily.  
```
staticint[]changerStrategieArbitraire(intstrat,Resource[]ressources, int[]intstrategieChoise){ int[]newStrat=newint[tainle]; for(intj=0;j<tainle;j++){ intvalue=0; for(intk=0;k<strategieChoise[j].length;k++){ value+=resources[strategieChoise[j][k].getValue(); } newStrat[j]=value; } returnnewStrat; }
```  
Here is the complexity of algorithm: \(\theta(nb)\times\theta(nb\_solats)=\theta(nb\times nb\_solats)\)  
The complexity is (C8) = \(\theta(nb\times nb\_solats)\)