Finding Energy Star washing machines with desirable properties

#include <iostream> #include <vector> #include <algorithm> using namespace std; double min(vector<double> v) { return *min_element(v.begin(), v.end()); } double max(vector<double> v) { return *max_element(v.begin(), v.end()); } double normalize(double v, vector<double> vals) { double minv = min(vals), maxv = max(vals); return (v - minv) / (maxv - minv); } struct WashingMachine { string manufacturer; string model; string load_type; // front, top float annual_energy_use_kwh_per_yr; // lower is better float integrated_modified_energy_factor; // lower is better float volume_ft3; // higher is better float annual_water_use_gallons_per_yr; // lower is better float integrated_water_factor_gallons_per_cycle_ft3; // lower is better }; int main() { vector<WashingMachine> energy_star_washing_machines = { {"Samsung", "WF56H91**A*", "Front Load", 135, 3.1, 5.6, 4429, 2.7}, {"LG", "WM9500H*A", "Front Load", 120, 3.1, 5.8, 4588, 2.7}, {"Samsung", "WF45M51**A*", "Front Load", 80, 3.0, 4.5, 3850, 2.9}, {"Samsung", "WF45N53**A*", "Front Load", 80, 3.0, 4.5, 3850, 2.9}, {"LG", "WM5000H*A", "Front Load", 105, 2.92, 4.5, 3676, 2.8}, {"LG", "WM5005H*A", "Front Load", 105, 2.92, 4.5, 3676, 2.8}, {"LG", "WM3080C*", "Front Load", 90, 2.92, 4.3, 4050, 3.2}, {"Kenmore", "592-4969*", "Front Load", 105, 2.92, 5.0, 4278, 2.9}, {"Maytag", "MHW3505F**", "Front Load", 88, 2.92, 4.4, 4116, 3.2}, {"Samsung", "WF45M55**A*", "Front Load", 105, 2.92, 4.5, 3850, 2.9}, {"Maytag", "MHW3500F**", "Front Load", 87, 2.92, 4.5, 4210, 3.2}, {"Samsung", "WF50K75**A*", "Front Load", 105, 2.92, 5.0, 4278, 2.9}, {"Samsung", "WF45K62**A*", "Front Load", 75, 2.92, 4.5, 3850, 2.9}, {"Whirlpool", "WFW7540F**", "Front Load", 88, 2.92, 4.5, 4210, 3.2}, {"Whirlpool", "WFW92HEF**", "Front Load", 89, 2.92, 4.5, 4210, 3.2}, {"Whirlpool", "WFW7590F**", "Front Load", 87, 2.92, 4.2, 3936, 3.2}, {"Whirlpool", "WFW9290F**", "Front Load", 89, 2.92, 4.2, 3936, 3.2}, {"Maytag", "MHW3500F**", "Front Load", 87, 2.92, 4.5, 4210, 3.2}, {"Whirlpool", "WFW75HEF**", "Front Load", 88, 2.92, 4.5, 4210, 3.2}, {"Maytag", "MHW8200F**", "Front Load", 89, 2.92, 4.5, 4210, 3.2}, {"Maytag", "MHW3500F**", "Front Load", 87, 2.92, 4.5, 4210, 3.2}, {"Whirlpool", "WFW9290F**", "Front Load", 89, 2.92, 4.2, 3936, 3.2}, {"Samsung", "WF45M55**A*", "Front Load", 105, 2.92, 4.5, 3850, 2.9}, {"Whirlpool", "WFW7590F**", "Front Load", 87, 2.92, 4.2, 3936, 3.2}, {"Whirlpool", "WFW92HEF**", "Front Load", 89, 2.92, 4.5, 4210, 3.2}, {"Whirlpool", "WFW7540F**", "Front Load", 88, 2.92, 4.5, 4210, 3.2}, {"Maytag", "MHW3505F**", "Front Load", 88, 2.92, 4.4, 4116, 3.2}, {"Whirlpool", "WFW90HEF**", "Front Load", 89, 2.92, 4.5, 4210, 3.2}, {"LG", "WM3085C*", "Front Load", 90, 2.92, 4.5, 4220, 3.2}, {"Samsung", "WF45N63**A*", "Front Load", 100, 2.92, 4.5, 3983, 3.0}, {"Kenmore", "4196#", "Front Load", 100, 2.92, 5.2, 4880, 3.2}, {"LG", "WM3670H*A", "Front Load", 100, 2.92, 4.5, 4220, 3.2}, {"LG", "WM3270C*", "Front Load", 90, 2.92, 4.5, 4220, 3.2}, {"Electrolux", "EFLS627****", "Front Load", 85, 2.92, 4.4, 4154, 3.2}, {"Kenmore", "4126#", "Front Load", 90, 2.92, 4.5, 4220, 3.2}, {"LG", "WM9000H*A", "Front Load", 120, 2.92, 5.2, 4880, 3.2}, {"LG", "WM3095C*", "Front Load", 100, 2.92, 4.5, 3841, 2.9}, {"LG", "WM3505C*", "Front Load", 100, 2.92, 4.5, 3841, 2.9}, {"LG", "WM3500C*", "Front Load", 100, 2.92, 4.5, 4239, 3.2}, {"Samsung", "WV55M96**A***", "Front Load", 105, 2.92, 4.5, 3850, 2.9}, {"LG", "WM3085C*", "Front Load", 90, 2.92, 4.5, 4220, 3.2}, {"Kenmore", "4107#", "Front Load", 120, 2.92, 5.2, 4880, 3.2}, {"Electrolux", "EFLS517****", "Front Load", 75, 2.92, 4.3, 4059, 3.2}, {"Samsung", "WF45N63**A*", "Front Load", 100, 2.92, 4.5, 3983, 3.0}, {"LG", "WM3080C*", "Front Load", 90, 2.92, 4.3, 4050, 3.2}, {"LG", "WM3095C*", "Front Load", 100, 2.92, 4.5, 3841, 2.9}, {"Electrolux", "EFLS627****", "Front Load", 85, 2.92, 4.4, 4154, 3.2}, {"Electrolux", "EFLS527****", "Front Load", 75, 2.92, 4.3, 4059, 3.2}, {"Samsung", "WV60M99**A***", "Front Load", 105, 2.92, 5.0, 4278, 2.9}, {"LG", "WM3505C*", "Front Load", 100, 2.92, 4.5, 3841, 2.9}, {"Electrolux", "EFLS617****", "Front Load", 85, 2.92, 4.4, 4154, 3.2}, {"Samsung", "WV55M96**A***", "Front Load", 105, 2.92, 4.5, 3850, 2.9}, {"Whirlpool", "WFW8540F**", "Front Load", 87, 2.92, 4.5, 4210, 3.2}, {"Whirlpool", "WFW85HEF**", "Front Load", 87, 2.92, 4.5, 4210, 3.2}, {"Crosley", "CFWH4084G**", "Front Load", 85, 2.92, 4.2, 3936, 3.2}, {"Samsung", "WF45K65**A*", "Front Load", 100, 2.8, 4.5, 3983, 3.0}, {"GE", "GFWR2700H***", "Front Load", 134, 2.8, 4.5, 3947, 3.0}, {"GE", "GFWR2705H***", "Front Load", 134, 2.8, 4.5, 3947, 3.0}, {"Samsung", "WF42H50**A*", "Front Load", 85, 2.8, 4.2, 3927, 3.2}, {"Samsung", "WF56H91**C*", "Front Load", 130, 2.8, 5.6, 4593, 2.8}, {"GE", "GFWR2705H***", "Front Load", 134, 2.8, 4.5, 3947, 3.0}, {"GE", "GFWR2700H***", "Front Load", 134, 2.8, 4.5, 3947, 3.0}, {"Samsung", "WF56H91**C*", "Front Load", 130, 2.8, 5.6, 4593, 2.8}, {"Kenmore", "4178#", "Front Load", 160, 2.76, 4.5, 4201, 3.2}, {"GE", "GTW810S*J***", "Top Load", 152, 2.76, 5.1, 5245, 3.5}, {"Samsung", "WF45H61**A*", "Front Load", 118, 2.76, 4.5, 4220, 3.2}, {"Amana", "NFW5800D**", "Front Load", 109, 2.76, 4.2, 3936, 3.2}, {"Kenmore", "4198#", "Front Load", 170, 2.76, 5.2, 4890, 3.2}, {"LG", "WT7900H*A", "Top Load", 150, 2.76, 5.5, 5145, 3.2}, {"LG", "WT7250C*", "Top Load", 110, 2.76, 5.0, 4720, 3.2}, {"LG", "WT7300C*", "Top Load", 110, 2.76, 5.0, 4720, 3.2}, {"GE", "GFW450S*M***", "Front Load", 116, 2.76, 4.5, 4220, 3.2}, {"GE", "GFW400S*M***", "Front Load", 113, 2.76, 4.1, 3852, 3.2}, {"GE", "GTW860S*J***", "Top Load", 152, 2.76, 5.1, 5245, 3.5}, {"LG", "WT7700H*A", "Top Load", 150, 2.76, 5.7, 5381, 3.2}, {"Electrolux", "EFLW417****", "Front Load", 60, 2.76, 4.3, 4059, 3.2}, {"GE", "GFW480S*K***", "Front Load", 153, 2.76, 4.9, 4047, 2.8}, {"GE", "GFW490R*K***", "Front Load", 153, 2.76, 4.9, 4047, 2.8}, {"Electrolux", "EFLW317****", "Front Load", 60, 2.76, 4.3, 4059, 3.2}, {"GE", "GFW430S*M***", "Front Load", 123, 2.76, 4.5, 4220, 3.2}, {"Amana", "NFW5800D**", "Front Load", 109, 2.76, 4.2, 3936, 3.2}, {"GE", "GFW430S*M***", "Front Load", 123, 2.76, 4.5, 4220, 3.2}, {"Asko", "W4114C.W.U", "Front Load", 75, 2.41, 2.7, 2478, 3.1}, {"Asko", "W4114C.T.U", "Front Load", 75, 2.41, 2.7, 2478, 3.1}, {"LG", "WT7600H*A", "Top Load", 130, 2.38, 5.2, 5643, 3.7}, {"LG", "WT1150C*", "Top Load", 140, 2.38, 4.5, 4901, 3.7}, {"LG", "WT5275C*", "Top Load", 140, 2.38, 4.5, 4901, 3.7}, {"LG", "WT7200C*", "Top Load", 130, 2.38, 5.0, 5479, 3.7}, {"LG", "WT1901C*", "Top Load", 130, 2.38, 5.0, 5479, 3.7}, {"LG", "WT7500C*", "Top Load", 130, 2.38, 5.2, 5621, 3.7}, {"Kenmore", "3143#", "Top Load", 150, 2.38, 5.0, 5479, 3.7}, {"Kenmore", "3155#", "Top Load", 130, 2.38, 5.2, 5643, 3.7}, {"LG", "WT1501C*", "Top Load", 140, 2.38, 4.5, 4901, 3.7}, {"LG", "WT5680H*A", "Top Load", 135, 2.38, 5.0, 5479, 3.7}, {"Samsung", "WA52J806*A*", "Top Load", 110, 2.38, 5.2, 5632, 3.7}, {"Samsung", "WA50K86**A*", "Top Load", 120, 2.38, 5.0, 5458, 3.7}, {"Kenmore", "3143#", "Top Load", 150, 2.38, 5.0, 5479, 3.7}, {"Maytag", "MVWB955F**", "Top Load", 197, 2.38, 6.2, 6735, 3.7}, {"Whirlpool", "WFW5090G**", "Front Load", 51, 2.38, 2.3, 2510, 3.7}, {"Whirlpool", "WFW3090G**", "Front Load", 38, 2.38, 2.0, 2150, 3.7}, {"Asko", "W2084.W.U", "Front Load", 75, 2.31, 2.0, 1728, 2.9}, {"Samsung", "WA56H90**A*", "Top Load", 194, 2.3, 5.6, 6889, 4.2}, {"Beko", "WMY 10148 C2", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Blomberg", "WM 98400 SX2", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Blomberg", "WM 98200 SX2", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Samsung", "WA48J770*A*", "Top Load", 129, 2.29, 4.8, 5476, 3.9}, {"Samsung", "WA48J777*A*", "Top Load", 129, 2.29, 4.8, 5476, 3.9}, {"Beko", "WMY 10148 W2", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Beko", "WMY 10148 C0", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Beko", "WMY 10148 W0", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Blomberg", "WM 98200 SX", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Blomberg", "WM 98400 SX", "Front Load", 82, 2.29, 2.5, 2655, 3.6}, {"Samsung", "WA52J870*A*", "Top Load", 165, 2.28, 5.2, 5784, 3.8}, {"Samsung", "WW22N685*Q*", "Front Load", 85, 2.25, 2.2, 2401, 3.7}, {"Samsung", "WW22K680*A*", "Front Load", 90, 2.25, 2.2, 2596, 4.0}, {"Bosch", "WAW285H2UC", "Front Load", 84, 2.22, 2.2, 2358, 3.7}, {"Gaggenau", "WM262700", "Front Load", 84, 2.22, 2.2, 2358, 3.7}, {"Bosch", "WAT28400UC", "Front Load", 84, 2.22, 2.2, 2294, 3.6}, {"Bosch", "WAT28402UC", "Front Load", 84, 2.22, 2.2, 2294, 3.6}, {"Bosch", "WAT28401UC", "Front Load", 84, 2.22, 2.2, 2294, 3.6}, {"Samsung", "WA48H74**A*", "Top Load", 145, 2.21, 4.8, 5476, 3.9}, {"Electrolux", "EFLS210****", "Front Load", 90, 2.13, 2.4, 2690, 3.8}, {"Kenmore", "417.4194*71*", "Front Load", 90, 2.13, 2.4, 2690, 3.8}, {"Miele", "WWF060", "Front Load", 116, 2.13, 2.3, 2467, 3.7}, {"Miele", "WWH660", "Front Load", 116, 2.13, 2.3, 2467, 3.7}, {"Miele", "WWH860", "Front Load", 116, 2.13, 2.3, 2467, 3.7}, {"GE", "WCVH4800****", "Front Load", 99, 2.1, 2.2, 2685, 4.1}, {"GE", "WCVH4800K***", "Front Load", 99, 2.1, 2.2, 2685, 4.1}, {"Beko", "WTE 7604XLW0", "Front Load", 67, 2.09, 2.0, 2013, 3.5}, {"Blomberg", "WM77120", "Front Load", 67, 2.09, 2.0, 2013, 3.5}, {"Fisher & Paykel", "WH2424F1", "Front Load", 80, 2.09, 2.4, 1982, 2.8}, {"Fisher & Paykel", "WH2424P1", "Front Load", 80, 2.09, 2.4, 1982, 2.8}, {"GE", "GTW680BSJ4WS", "Top Load", 143, 2.08, 4.6, 4906, 3.6}, {"GE", "GTW680BSJ5WS", "Top Load", 143, 2.08, 4.6, 4906, 3.6}, {"GE", "GTW680BSJ6WS", "Top Load", 143, 2.08, 4.6, 4906, 3.6}, {"GE", "GTW680BPL0DG", "Top Load", 143, 2.08, 4.6, 4906, 3.6}, {"GE", "GTW680BSJ3WS", "Top Load", 143, 2.08, 4.6, 4906, 3.6}, {"GE", "GTW680BPL1DG", "Top Load", 143, 2.08, 4.6, 4906, 3.6}, {"LG", "WM1385H*", "Front Load", 120, 2.07, 2.3, 2850, 4.2}, {"GE", "GTW490ACJ3WS", "Top Load", 133, 2.07, 4.4, 5273, 4.1}, {"GE", "GTW490ACJ2WS", "Top Load", 133, 2.07, 4.4, 5273, 4.1}, {"LG", "WM1385H*", "Front Load", 120, 2.07, 2.3, 2850, 4.2}, {"GE", "GTW490ACJ5WS", "Top Load", 133, 2.07, 4.4, 5273, 4.1}, {"GE", "GTW490ACJ5WW", "Top Load", 133, 2.07, 4.4, 5273, 4.1}, {"LG", "WM1388H*", "Front Load", 120, 2.07, 2.3, 2850, 4.2}, {"GE", "GTW490ACJ4WS", "Top Load", 133, 2.07, 4.4, 5322, 4.1}, {"GE", "GFW148S*L***", "Front Load", 80, 2.07, 2.4, 2912, 4.2}, {"GE", "GTW485ASJ5WS", "Top Load", 152, 2.06, 4.2, 5340, 4.3}, {"Samsung", "WA54M87**A*", "Top Load", 165, 2.06, 5.4, 6850, 4.3}, {"Kenmore", "2913*41*", "Top Load", 195, 2.06, 5.3, 6698, 4.3}, {"GE", "GTW755C*M***", "Top Load", 181, 2.06, 4.9, 6203, 4.3}, {"Whirlpool", "WTW8000D**", "Top Load", 196, 2.06, 5.3, 6698, 4.3}, {"Samsung", "WA52M77**A*", "Top Load", 165, 2.06, 5.2, 6596, 4.3}, {"Whirlpool", "WTW8040D**", "Top Load", 196, 2.06, 5.3, 6698, 4.3}, {"Samsung", "WA45M70**A*", "Top Load", 125, 2.06, 4.5, 5708, 4.3}, {"Whirlpool", "WTW7300D**", "Top Load", 169, 2.06, 4.8, 6076, 4.3}, {"Samsung", "WA45K71**A*", "Top Load", 125, 2.06, 4.5, 5708, 4.3}, {"Samsung", "WA45K76**A*", "Top Load", 125, 2.06, 4.5, 5708, 4.3}, {"GE", "GTW485ASJ4WS", "Top Load", 152, 2.06, 4.2, 5328, 4.3}, {"Samsung", "WA45H70**A*", "Top Load", 131, 2.06, 4.5, 5011, 3.8}, {"GE", "GTW485ASJ5WS", "Top Load", 152, 2.06, 4.2, 5340, 4.3}, {"GE", "GTW485ASJ3WS", "Top Load", 152, 2.06, 4.2, 5340, 4.3}, {"Whirlpool", "WTW8700E**", "Top Load", 251, 2.06, 5.3, 6698, 4.3}, {"LG", "WT7100C*", "Top Load", 220, 2.06, 4.5, 5721, 4.3}, {"LG", "WT7050C*", "Top Load", 180, 2.06, 4.5, 5696, 4.3}, {"Maytag", "MVWB965H**", "Top Load", 311, 2.06, 6.0, 7636, 4.3}, {"LG", "WT7100C*", "Top Load", 220, 2.06, 4.5, 5721, 4.3}, {"Samsung", "WA54M87**A*", "Top Load", 165, 2.06, 5.4, 6850, 4.3}, {"Samsung", "WA52M86**A*", "Top Load", 125, 2.06, 5.2, 6596, 4.3}, {"Samsung", "WA45K76**A*", "Top Load", 125, 2.06, 4.5, 5708, 4.3}, {"Whirlpool", "WTW7500G**", "Top Load", 212, 2.06, 4.8, 6076, 4.3}, {"Samsung", "WA45M70**A*", "Top Load", 125, 2.06, 4.5, 5708, 4.3}, {"Samsung", "WA50M74**A*", "Top Load", 125, 2.06, 5.0, 6343, 4.3}, {"Samsung", "WA45K71**A*", "Top Load", 125, 2.06, 4.5, 5708, 4.3}, {"Samsung", "WA52M77**A*", "Top Load", 165, 2.06, 5.2, 6596, 4.3}, {"GE", "GTW685B*L***", "Top Load", 150, 2.06, 4.5, 5683, 4.3}, {"Kenmore", "2613*41*", "Top Load", 169, 2.06, 4.8, 6076, 4.3}, {"Maytag", "MVWB855D**", "Top Load", 187, 2.06, 5.3, 6698, 4.3}, {"GE", "GTW755C*M***", "Top Load", 181, 2.06, 4.9, 6203, 4.3}, {"Whirlpool", "WTW7040D**", "Top Load", 169, 2.06, 4.8, 6076, 4.3}, {"Whirlpool", "WTW7000D**", "Top Load", 169, 2.06, 4.8, 6076, 4.3}, {"Maytag", "MVWB855D**", "Top Load", 187, 2.06, 5.3, 6698, 4.3}, {"Kenmore", "2913*41*", "Top Load", 195, 2.06, 5.3, 6698, 4.3}, {"Whirlpool", "WTW8040D**", "Top Load", 196, 2.06, 5.3, 6698, 4.3}, {"Maytag", "MVWB835D**", "Top Load", 187, 2.06, 5.3, 6698, 4.3}, {"Kenmore", "2813*41*", "Top Load", 195, 2.06, 5.3, 6698, 4.3}, }; vector<double> ann_energy_uses, modified_energy_factors, volumes_ft3, annual_water_uses_gallons_per_yr, integrated_water_factors_gallons_per_cycle_ft3; for(auto wm : energy_star_washing_machines) { ann_energy_uses.push_back(wm.annual_energy_use_kwh_per_yr); modified_energy_factors.push_back(wm.integrated_modified_energy_factor); volumes_ft3.push_back(wm.volume_ft3); annual_water_uses_gallons_per_yr.push_back(wm.annual_water_use_gallons_per_yr); integrated_water_factors_gallons_per_cycle_ft3.push_back(wm.integrated_water_factor_gallons_per_cycle_ft3); } vector<pair<double, string>> index_models; double energy_use_score, modified_energy_factor_score, volume_score, annual_water_use_score, integrated_water_factor_score, total_score; for(auto wm : energy_star_washing_machines) { energy_use_score = 1 - normalize(wm.annual_energy_use_kwh_per_yr, ann_energy_uses); modified_energy_factor_score = 1 - normalize(wm.integrated_modified_energy_factor, modified_energy_factors); volume_score = normalize(wm.volume_ft3, volumes_ft3); annual_water_use_score = 1 - normalize(wm.annual_water_use_gallons_per_yr, annual_water_uses_gallons_per_yr); integrated_water_factor_score = 1 - normalize(wm.integrated_water_factor_gallons_per_cycle_ft3, integrated_water_factors_gallons_per_cycle_ft3); total_score = energy_use_score + modified_energy_factor_score + volume_score + annual_water_use_score + integrated_water_factor_score; index_models.push_back(make_pair(total_score, wm.manufacturer + ", " + wm.model)); } sort(index_models.rbegin(), index_models.rend()); int show = 20; for(const pair<double, string>& p : index_models) { if(show > 0) { cout << p.first << " " << p.second << endl; show--; } } /* 3.80705 Fisher & Paykel, WH2424P1 3.80705 Fisher & Paykel, WH2424F1 3.49908 Asko, W2084.W.U 3.31765 Asko, W4114C.W.U 3.31765 Asko, W4114C.T.U 3.31669 Blomberg, WM77120 3.31669 Beko, WTE 7604XLW0 3.26117 Samsung, WF56H91**C* 3.26117 Samsung, WF56H91**C* 3.14861 Samsung, WF45K62**A* 3.14114 GE, GFW490R*K*** 3.14114 GE, GFW480S*K*** 3.13067 LG, WM5005H*A 3.13067 LG, WM5000H*A 3.12031 LG, WM9500H*A 3.11479 GE, GTW680BSJ6WS 3.11479 GE, GTW680BSJ5WS 3.11479 GE, GTW680BSJ4WS 3.11479 GE, GTW680BSJ3WS 3.11479 GE, GTW680BPL1DG */ return 0; }