-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from thomasbai98/yuyang-greedy
Yuyang greedy
- Loading branch information
Showing
2 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
import math | ||
import numpy as np | ||
import copy | ||
import logging | ||
from typing import Callable, Dict, List, Tuple, Union | ||
def get_level(self, curr_level,i,j): | ||
highest_level = 0 | ||
for x in range(i,i+2): | ||
for y in range(j,j+2): | ||
if curr_level[x][y]>highest_level: | ||
highest_level = curr_level[x][y] | ||
return highest_level | ||
|
||
def get_icecream(self,top_layer,curr_level,level,i,j): | ||
value = 0 | ||
amount = 0 | ||
if level==0: | ||
return 0,0 | ||
for x in range(i,i+2): | ||
for y in range(j,j+2): | ||
if curr_level[x][y]==level: | ||
amount+=1 | ||
value+=(len(self.flavor_preference)+1-self.flavor_preference.index(top_layer[i][j])) | ||
return value, amount | ||
def greedy(self, top_layer, curr_level,maxAmount): | ||
bestValue = -1.0 # best mean value of ice-cream | ||
bestPos=(-1,-1) # position of bestValue | ||
bestAmount=0 # amount of ice-cream of bestValue | ||
for i in range(23): | ||
for j in range(14): | ||
level = get_level(self,curr_level,i,j) | ||
value,amount = get_icecream(self,top_layer,curr_level,level,i,j) | ||
if (amount>0 and amount<=maxAmount): | ||
if (float(value/amount)>bestValue): | ||
bestAmount = amount | ||
bestValue = float(value/amount) | ||
bestPos = (i,j) | ||
print(bestValue*bestAmount) | ||
return bestPos, bestAmount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters