Ejemplo n.º 1
0
 def test_parameters_pd(self):
     schema = test_schema + "_parameters_pd"
     pdf = PanDatFactory(parameters=[["Key"], ["Value"]])
     pdf.add_parameter("Something", 100)
     pdf.add_parameter("Different",
                       'boo',
                       strings_allowed='*',
                       number_allowed=False)
     dat = TicDatFactory(**pdf.schema()).TicDat(
         parameters=[["Something", float("inf")], ["Different", "inf"]])
     dat = TicDatFactory(**pdf.schema()).copy_to_pandas(
         dat, drop_pk_columns=False)
     pdf.pgsql.write_schema(self.engine, schema)
     pdf.pgsql.write_data(dat, self.engine, schema)
     dat_ = pdf.pgsql.create_pan_dat(self.engine, schema)
     self.assertTrue(pdf._same_data(dat, dat_))
Ejemplo n.º 2
0
    input_schema.set_data_type("iris",
                               fld,
                               inclusive_min=False,
                               inclusive_max=False,
                               min=0,
                               max=float("inf"))
input_schema.set_data_type("iris",
                           'Species',
                           number_allowed=False,
                           strings_allowed='*')

# the number of clusters is our only parameter, but using a parameters table makes it easy to add more as needed
input_schema.add_parameter("Number of Clusters",
                           default_value=4,
                           inclusive_min=False,
                           inclusive_max=False,
                           min=0,
                           max=float("inf"),
                           must_be_int=True)
# ---------------------------------------------------------------------------------

# ------------------------ define the output schema -------------------------------
solution_schema = PanDatFactory(
    iris=[[],
          [
              'Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width',
              'Species', 'Cluster ID'
          ]])

# ---------------------------------------------------------------------------------
Ejemplo n.º 3
0
    plants=[["Name"], []],
    warehouses=[["Name"], ["Max Assignment Capacity", "Fixed Cost"]],
    customers=[["Name"], []],
    products=[["Name"], ["Warehouse Volume"]],
    demand=[["Customer", "Product"], ["Demand"]],
    supply=[["Plant", "Product"], ["Supply"]],
    plant_to_warehouse_costs=[["Plant", "Warehouse", "Product"], ["Cost"]],
    warehouse_to_customer_costs=[["Warehouse", "Customer", "Product"],
                                 ["Cost"]],
    warehouse_to_customer_distances=[["Warehouse", "Customer"], ["Distance"]],
    parameters=[["Parameter"], ["Value"]])

input_schema.add_parameter("Number of Warehouses",
                           default_value=4,
                           inclusive_min=False,
                           inclusive_max=False,
                           min=0,
                           max=float("inf"),
                           must_be_int=True)
input_schema.add_parameter("High Service Distance",
                           default_value=0,
                           inclusive_min=True,
                           inclusive_max=True,
                           min=0,
                           max=float("inf"),
                           must_be_int=False)
input_schema.add_parameter("Maximum Average Service Distance",
                           default_value=float("inf"),
                           inclusive_min=True,
                           inclusive_max=True,
                           min=0,
Ejemplo n.º 4
0
                           min=0,
                           max=float("inf"),
                           inclusive_min=False,
                           inclusive_max=False,
                           must_be_int=True)

input_schema.add_data_row_predicate(
    "roster_requirements",
    predicate=lambda row: row["Max Num Starters"] >= row["Min Num Starters"])
input_schema.add_data_row_predicate(
    "roster_requirements",
    predicate=lambda row: row["Max Num Reserve"] >= row["Min Num Reserve"])

input_schema.add_parameter("Starter Weight",
                           default_value=1.2,
                           min=0,
                           max=float("inf"),
                           inclusive_min=False,
                           inclusive_max=False)
input_schema.add_parameter("Reserve Weight",
                           default_value=0.9,
                           min=0,
                           max=float("inf"),
                           inclusive_min=False,
                           inclusive_max=False)
input_schema.add_parameter("Maximum Number of Flex Starters",
                           default_value=float("inf"),
                           min=0,
                           max=float("inf"),
                           inclusive_min=True,
                           inclusive_max=True)
# ---------------------------------------------------------------------------------
Ejemplo n.º 5
0
# to and from .csv files.
#
# Command line interface works like this
#    python simple_datetime_solver.py -i sample_data -o solution_directory
#
# This is a very simple app that demos datetime functionality that might be useful for a routing application.
# A parameter defines the start of the model, and each order has a "Deliver By" time requirement. The solution
# (which is just diagnostic information) is the time elapsed (in days) between the start time of the model and the
# "Delvery By" time for each order

from ticdat import PanDatFactory, standard_main
# ------------------------ define the input schema --------------------------------
input_schema = PanDatFactory(parameters=[["Name"], ["Value"]],
                             orders=[["Name"], ["Deliver By"]])
input_schema.set_data_type("orders", "Deliver By", datetime=True)
input_schema.add_parameter("Start Of Model", "Jan 1 2019 8 AM", datetime=True)
# ---------------------------------------------------------------------------------

# ------------------------ define the output schema -------------------------------
solution_schema = PanDatFactory(
    time_to_deliver=[["Name"], ["Maximum Time To Deliver"]])

# ---------------------------------------------------------------------------------


# ------------------------ create a solve function --------------------------------
def solve(dat):
    assert input_schema.good_pan_dat_object(dat)
    assert not input_schema.find_duplicates(dat)
    assert not input_schema.find_data_type_failures(
        dat)  # "Delvery By" will be a datetime.datetime
Ejemplo n.º 6
0
input_schema = PanDatFactory (
    parameters=[["Parameter"], ["Value"]],
    load_amounts=[["Amount"],[]],
    number_of_one_way_trips=[["Number"],[]],
    amount_leftover=[["Amount"], []])

input_schema.set_data_type("load_amounts", "Amount", min=0, max=float("inf"),
                           inclusive_min=False, inclusive_max=False)

input_schema.set_data_type("number_of_one_way_trips", "Number", min=0, max=float("inf"),
                           inclusive_min=False, inclusive_max=False, must_be_int=True)

input_schema.set_data_type("amount_leftover", "Amount", min=0, max=float("inf"),
                           inclusive_min=True, inclusive_max=False)

input_schema.add_parameter("One Way Price", default_value=2.25, min=0, max=float("inf"), inclusive_min=True,
                           inclusive_max=False)
input_schema.add_parameter("Amount Leftover Constraint", default_value="Upper Bound", number_allowed=False,
                           strings_allowed=["Equality", "Upper Bound", "Upper Bound With Leftover Multiple Rule"])
# ---------------------------------------------------------------------------------


# ------------------------ define the output schema -------------------------------
solution_schema = PanDatFactory(
    load_amount_details=[["Number One Way Trips", "Amount Leftover", "Load Amount"],
                           ["Number Of Visits"]],
    load_amount_summary=[["Number One Way Trips", "Amount Leftover"],["Number Of Visits"]])
# ---------------------------------------------------------------------------------


# ------------------------ create a solve function --------------------------------
def solve(dat):