예제 #1
0
파일: test_diet.py 프로젝트: spkelle2/diet
 def test_gurobi_solve(self):
     dat = input_schema.csv.create_tic_dat('diet_sample_data')
     dat.parameters['How To Make Solution']['Value'] = "Use Gurobi"
     with self.assertRaises(
             DietException,
             msg="Gurobi should not be present, causing solve to fail"):
         solve(dat)
예제 #2
0
# Read/write from Excel file. Analgous to this file. https://bit.ly/2S4Xvyo
from diet import solve, input_schema, solution_schema

dat = input_schema.xls.create_tic_dat(
    "diet.xls")  # Just look for the diet.xls file in the current directory

sln = solve(dat)

if sln:  # if the solve succeeds, write back to the current directory
    solution_schema.xls.write_file(sln, "solution.xls", allow_overwrite=True)
예제 #3
0
        ('pizza', 'calories'): 320,
        ('pizza', 'protein'): 15,
        ('pizza', 'fat'): 12,
        ('pizza', 'sodium'): 820,
        ('salad', 'calories'): 320,
        ('salad', 'protein'): 31,
        ('salad', 'fat'): 12,
        ('salad', 'sodium'): 1230,
        ('milk', 'calories'): 100,
        ('milk', 'protein'): 8,
        ('milk', 'fat'): 2.5,
        ('milk', 'sodium'): 125,
        ('ice cream', 'calories'): 330,
        ('ice cream', 'protein'): 8,
        ('ice cream', 'fat'): 10,
        ('ice cream', 'sodium'): 180
    })

solution = solve(dat)

if solution:
    print('\nCost: %g' % solution.parameters['Total Cost']['Value'])
    print('\nBuy:')
    for f, b in solution.buy_food.items():
        print('%s %g' % (f, b["Quantity"]))
    print('\nNutrition:')
    for c, n in solution.consume_nutrition.items():
        print('%s %g' % (c, n["Quantity"]))
else:
    print('\nNo solution')
예제 #4
0
파일: test_diet.py 프로젝트: spkelle2/diet
 def test_matching_dataset(self):
     dat = input_schema.csv.create_tic_dat('diet_sample_data')
     sln = solve(dat)
     self.assertTrue(
         sln.parameters['Total Cost']['Value'] == 11.828861111111111,
         msg='The matching dataset should generate the cached solution')
예제 #5
0
파일: test_diet.py 프로젝트: spkelle2/diet
 def test_bad_parameter(self):
     dat = input_schema.csv.create_tic_dat('diet_sample_data')
     dat.parameters['How To Make Solution']['Value'] = "Use Pete"
     with self.assertRaises(AssertionError,
                            msg="Bad parameters should be caught"):
         solve(dat)
예제 #6
0
파일: test_diet.py 프로젝트: spkelle2/diet
 def test_data_integrity_errors(self):
     dat = input_schema.csv.create_tic_dat('diet_dirty_sample_data')
     with self.assertRaises(AssertionError,
                            msg="A dirty dat should fail assertions"):
         solve(dat)
예제 #7
0
파일: test_diet.py 프로젝트: spkelle2/diet
 def test_different_primary_keys(self):
     dat = input_schema.csv.create_tic_dat('diet_sample_data')
     dat.foods['brocolli']['Cost'] = 2.25
     with self.assertRaises(DietException,
                            msg="Different pks should be detected"):
         solve(dat)
예제 #8
0
파일: test_diet.py 프로젝트: spkelle2/diet
 def test_different_values(self):
     dat = input_schema.csv.create_tic_dat('diet_sample_data')
     dat.foods['ice cream']['Cost'] = 1.60
     with self.assertRaises(DietException,
                            msg="Different values should be detected"):
         solve(dat)