How can I represent a graph problem in PDDL? - pddl

For example I have the following problem: I have a salesman agent that sells 4 products (a, b, c, and d). it has 10 costumers overall: 3 that need product a, 3 that need product b, 3 that need product c, and 1 that needs product d. not every client has a road (link) to all other clients. the agent is currently at the home of costumer 1 that needs product a and his goal is to get satisfy costumer 10 who needs product d. such that it needs to go through all the clients to get to costumer 10.
Can anyone please help?
Thanks!

You need to set up your graph as a set of 'connectivity predicates' in the init section, eg:
(adjacent l1 l2) (adjacent l2 l3) ...
This represents a connection between l1 and l2 and between l2 and l3; those could be waypoints or the locations of your customers. You then need an action that moves along the graph:
(:action move
:parameters (?from ?to - location)
:precondition (and
(adjacent ?from ?to)
(at salesman ?from))
:effect (and
(at salesman ?to)
(not (at salesman ?from)))
You then also need an action deliver that makes sure the salesman has some goods, is at a customer, and as an effect the customer has the goods (and the salesman doesn't). Then you set as the goal that all customers have the goods they want, and you should be good to go.

Related

How can I select multiple records from more that two tables

I am a complete beginner in SQL and need some help to learn. I have this learning material I found online and trying to write queries per the instructions. I did the first but got stuck on the rest of the queries. Can anyone please help me write any one of the queries below?
[]
Please help me learn how to do the rest.
b) Get aids and names of agents who have placed individual orders of at least $500 for any customer living
in Kyoto.
c) What cities do those customers live in, who enjoy discount under 10% and have ordered at least 1000
combs so far (in all their orders put together)?
d) What product names have been ordered by at least one customer based in Dallas through any agent based
in Tokyo?
e) Get the name, city, and total dollar amount of all orders placed by each customer, arranged in descending
order of the amounts.
Here is how I managed to do the first one.
a) Get pairs of all customer cids and agent aids, who live in the same city.
SELECT customer.cid, agent.aid FROM customers, agent WHERE customer.city = agent.city
RESULT
cid
aid
c001
a05
c004
a05
c002
a06
c003
a06
Try this one for b
SELECT distinct Agents.City -- Distinct becuase you dont want more then one of the same city being returned
FROM Agents
JOIN Orders
ON orders.aid = agents.aid
WHERE orders.cid = 'c002' -- Checks the orders table for any cid equal to c002

Choosing a value based on a ranking of another column

I have decent Google-Fu skills, but they've utterly failed me on this.
I'm working in PowerPivot and I'm trying to match up a product with a price point in another table. Sounds easy, right? Well each product has several price points, based on the source of the price, with a hierarchy of importance.
For Example:
Product 1 has three prices living in a Pricing Ledger:
Price 1 has an account # of A22011
Price 2 has an account # of B22011
Price 3 has an account # of C22011
Price A overrides Price B which overrides Price C
What I want to do is be able to pull the most relevant price (i.e, that with the highest rank in the hierarchy) when not all price points are being used.
I'd originally used a series of IF statements, but that's when there were only four points. We now have ten points, and that might grow, so the IF statements are an untenable solution.
I'd appreciate any help.
-Thanks-

Let employees buy products via POS

I would like to use the odoo POS also for internal use. Employees should be able to buy products for themselves. All of the costs should be charged via the payslip of every employee.
Example: A is an employee of my company X. A buys a coke (2$) from the POS. B is chief of HR at X and wants to generate the payslip of A to send him his loan (100$) for the month. Odoo should now calculate and sum up all POS expenses and then show B that A gets a loan of 98$.
I would probably do some adjustments with custom modules, however would it even be possible to set an employee as the customer in odoo?

Identifying Parent transaction on set of records in SQL

I have a list of transactions and its payments. I am looking for finding the parent payment for the transactions to identify the repeated customers. For example, I have list as below:
Transaction Payment1 Payment2 Payment3 Bucket
100 A B C P1
110 B P1
120 D E P2
130 D E F P2
140 C B P1
160 F K P2
170 C A P1
Parent Transaction is the final result. It need not be A and D always, which ever is the best in finding the Unique value, for eg: Instead of A, it can B or C if we can derive it easily.
I tried going by iterations, first comparing column 3 with col1 and col2 values and deriving the Col1 of first finding as parent. But some where it is not working at all. I have more than million transactions to derive the parent payment to identify the unique customer.
Example is for transaction 100, I used 3 different payment cards (Like Visa, Master Card, AMEX, Debit card, Gift card). I might be using any of these cards in any other transactions. For example Payment B, I used B in Transaction 110. So 100 and 110 should be under same bucket. For transaction 140 and 170, I used payments C,B & C,A. All these cards are from the same person. SO all these transactions should come under same bucket. I want to identify that bucket. Let us name all these set of transactions as P1 and if I query on P1, I should get all these transactions. Same applies to other set of transactions.
Ok thanks.. I figured out a solution, wrote a function in R, took the data in R and wrote a loop and did a logic of identifying parent transaction and put it back into database. Since it is millions of records, it is taking 2 days to execute but with accuracy.

Optimal selection for ordering multiple items (parts) from multiple suppliers (vendors)

The task here is to define the optimal (as detailed below) way of ordering items (parts) from suppliers.
The relevant parts of the table schema (with some sample data) are
Items
ID NUMBER
1 Item0001
2 Item0002
3 Item0003
Suppliers
ID NAME DELIVERY DISCOUNT
1 Supplier0001 0 0
2 Supplier0002 0 0.025
3 Supplier0003 20 0
DELIVERY is the delivery charge (in dollars) levied by that supplier on each delivery. DISCOUNT is the settlement discount (as a percentage i.e. 2.5% for ID=2 above) allowed by that supplier for on time payment.
SupplierItems
SUPPLIER_ID ITEM_ID PRICE
1 2 21.67
1 5 45.54
1 7 32.97
This is the many-to-many join between suppliers and items with the price that supplier charges for that item (in dollars). Every item has at least 1 supplier but some have more than one. A supplier may have no items.
PartsRequests
ID ITEM_ID QUANTITY LOCATION_ID ORDER_ID
1 59 4 2 (null)
2 89 5 2 (null)
3 42 4 2 (null)
This table is a request from a field site for parts to be ordered and delivered by the supplier to that site. A delivery of any number of items to a site attracts a delivery charge. When the parts are ordered, the ORDER_ID is inserted into the table so we are only concerned with those where ORDER_ID IS NULL
The question is, what is the optimal way to order these parts for each `LOCATION' where there are 3 optimal solutions that need to be presented to the user for selection.
The combination of orders with the least number of suppliers
The combination of orders with the lowest total cost i.e. The sum of QUANTITY*PRICE for each item plus the DELIVERY for each order summed over all orders ignoring DISCOUNT
As item 2 but accounting for DISCOUNT
Clearly I need to determine the combinations of orders that are available and then determining the optimal ones becomes trivial but I am a bit stuck on an efficient way to deal with building the combinations.
I have built some SQL fiddles in SQL Server 2008 with random data. This one has 100 items, 10 suppliers and 100 requests. This one has 1000 items, 50 suppliers and 250 requests. The table schema is the same.
Update
I reasoned that the solution had to be recursive and I built a nice table valued function to get but I ran into the 32 hard limit on recursion in SQL Server. I was uncomfortable with it anyway because it hinted more of a procedural language solution than a RDMS.
So I am now playing with CTE recursion.
The root query is:
SELECT DISTINCT
'' SOLUTION_ID
,LOCATION_ID
,SUPPLIER_ID
,(subquery I haven't quite worked out) SOLE_SUPPLIER
FROM PartsRequests pr
INNER JOIN
SupplierItems si ON pr.ITEM_ID=si.ITEM_ID
WHERE pr.ORDER_ID IS NULL
This gets all the suppliers that can supply the required items and is certainly a solution, probably not optimal. The subquery sets a flag if the supplier is the sole supplier of any product required for that location; if so they must be part of any solution.
The recursive part is to remove suppliers one by one by means of CTE.SUPPLIER_ID<>CTE.SUPPLIER_ID and add them if they still cover all the items. The SOLUTION_ID will be a CSV list of the suppliers removed, partly to uniquely identify each solution and partly to check against so I get combinations instead of permutations.
Still working on the details, the purpose of this update was to allow the Community to say "Yay, looks like that will work" or, alternatively "You moron, that won't work because ..."
Thanks
This is a more general answer (as in, not sql) as I think solving this problem will require something more powerful. Your first scenario is to select a minimum number of suppliers. This problem can be seen as a set cover problem as you are trying to cover all demands per site with the suppliers. This problem is already NP-complete.
Your third scenario seems to be basically the same as the second. You just have to take the discount into account in the prices, assuming you pay on time for every order.
The second scenario is at least NP-hard as I see a lot of resemblance with the facility location problem. You are trying to decide which suppliers (facilities) to use (open) to cover your orders (demands) based on their prices and delivery costs (opening costs).
Enumerating your possible solutions seems infeasible as with 10 suppliers, you have 2^10 possibilities of using them, further complicated by the distribution of demands internally.
I would suggest some dynamic programming to first select the suppliers that you have to use (=they are the only ones that deliver a specific thing), eliminating some possibilities (if the cost for supplier A +delivery cost A< cost for supplier B) and then trying to expand your set of possible solutions. Linear programming is also a valid train of thought.