Repeating nodes on a search tree? (AI) - search

I am doing the following question:
Consider the 3-puzzle problem, where the board is a 2X2 matrix. There are three tiles numbered 1,2, and 3, and there is one blank tile. There are four operators that move the blank up, down, left, or right. The start and goal states are given in the following figure. With the help of search trees, show how a path to the goal can be found using:
a. depth first search (3 marks)
b. breadth first search (3 marks)
c. A* search with the heuristic being the sum of the number of moves and the number of misplaced tiles. (3 marks)
If a search method does not find a solution, explain why it does not.
(2 marks)
START state
2 3
1 _
GOAL state
1 2
3 _
Obviously as you move to one state from another, you can move from that state to a new one or to the state that you have just moved from (due to the nature of the operators), in the search tree do we re-state the nodes that we have already branched from? In other words, if you are at stage 4 would you re-state a node at stage 3?

You should keep a table of visited states to know not to go there again.

Related

Excel 365 Getting a Drop down with right Parent for Child

I have a family tree with 4 generations. I have put them into named groups of Parent and Child, for a child in 1st generation becomes a Parent in 2nd generation and so forth.
I can easily, pending some rules, decide what Parent resides in 1st generation and a list of Children from Parent.
When you work with this for a while you start to recognise a system of Children in the 4th generation, and you then just select that Child and from that choise I can then select (XLOOKUP, VLOOKUP) who is the Parent of selected Child.
My problem comes when my children Peter, Joe, Beatrice, Jim, Joe suddenly gets an overlap. The 2 Joes which normally have 2 different parents now only have 1, due to LOOKUP only finding the first solution.
I can easily make a FILTER of which Parents are linked to a Child, and list them seperately but I need that FILTER inside a Data Validation (Drop Down). I have tried the INDIRECT solution and it didn't work as intended. FILTER(Parent;Child=D5)
The function I'm using right now is XLOOKUP(D1;Child;Parent;"not found";0;1) , that works brilliantly when the family tree is straight up and clear. I select the Child, it finds the Parent, which in turn find the (Grand)Parent, etc. When I do find a Joe it returns the Parent of the 1st Joe in the system, messing up the family trees.
Optimally I would have a Drop Down of the possible Parents of this Joe and then the family tree would continue.
(There's a client and level of IP involved. The specific word is 'Other' and several trees are using the word to describe a group of products. Due to IP I can't change any names or make it Joe 1, Joe 2, etc)
I have 1000s of rows of this, when I've selected a family/product-line for a row that row is done. I can't feasible allocate that Drop Down out. The filter needs to be incl in the Drop Down/Data validation menu. Each time the client returns with a new Workbook, I'd prefer I just copy-paste the logic and easily covering the 1000s of rows.
4 generations and 5 families. If for each generation there'd be a drop down of Parents for a Child, that would solve for those families with a Joe.
TRANSPOSE(FILTER(Parent;Child=D1))
Actually the solution was a support outsider, but not column, but rather row wise.
But what about the indetermined length of possible parents?
That is where the spill functionality comes in. Data validation with just the first cell, and reference finished with a #. The # makes it a spill. =C1#
But a Data validation is normally vertical, how do you turn it?
Excel does that by auto.

Match and Conditional Formatting from Matrix Table

I am looking for some decent help with my matrix table, and is there a good or best approach to properly match dependent instances in certain matrix using drop downs.
This picture represents my matrix table (Picture 1):
As you can see there are a lot of instances, but horizontally and vertically they got the same number of "headers". Those "1`s" are representing not compatibility in my case but lets call it simply "match". That is on one sheet that is gonna be populated with some new values from time to time.
On another sheet which is actually sheet for showing the data and their compatibility possibilities is equipped with drop downs. There you got "Groups (Group1, Group2...)" in a sense of main parts and "dependent groups (AA1, BB2..)" as small components that are part of main parts. To avoid misunderstanding here you have explanations, I used for the sake of this example fictional values:
Groups aka. Main Parts
Dependent groups aka. components
As you can see beneath, is my fictional table but exactly the same concept as I should use in my real case.
I PUT AN EXPLANATION IN THE PICTURE 2 SO YOU CAN FOLLOW ALONG AND SEE EXACTLY WHERE/WHAT I DID!
What I used firstly there are =match functions, one for vertical position (A3) and one for horizontal (B4). This boolean row is done using =or(index) but reffering to the match positions as you can see. And from there I should use true/false for coloring my group boxes in a case compatibility is possible - thats all the science.
So, my question is if there is another approach to this problem? As you can see I have 3 different rows of functions at one place, or imagine if I will have more "groups" that can rise in many more rows and calculations.
Picture 2
EDITED:
This is screenshot of the original sheet, I just hid some rows that were with Infos that is reason the number is not consistent. As you can see it is almost the same as dummy example I provided above. Underneath every "box" you got three rows of calculations as I mentioned before. The two times number "2" that you see here is the position of some value that I found using =match function, one is for horizontal and another for vertical lookup. In this case it is model type, 070FX is position 2, 100FX is 3 and 200FX is 4th position in the matrix table, and so on for all the other groups. And those groups (Model, Endpoint, Gas sensor...) are defined separately on another sheet where I had to make unique list and dependent list so I can reference those to my drop down list.
EDIT Nr 4! So this formula I used for true/false:
=SUMPRODUCT(('0359-matrix'!$A$2:$A$101=F10)*(('0359-matrix'!$B$1:$CW$1=$B$10)+('0359-matrix'!$B$1:$CW$1=$C$10)+('0359-matrix'!$B$1:$CW$1=$D$10)+('0359-matrix'!$B$1:$CW$1=$E$10)+('0359-matrix'!$B$1:$CW$1=$F$10)+('0359-matrix'!$B$1:$CW$1=$G$10)+('0359-matrix'!$B$1:$CW$1=$H$10)+('0359-matrix'!$B$1:$CW$1=$I$10)+('0359-matrix'!$B$1:$CW$1=$J$10)+('0359-matrix'!$B$1:$CW$1=$K$10)+('0359-matrix'!$B$1:$CW$1=$L$10)+('0359-matrix'!$B$1:$CW$1=$M$10)+('0359-matrix'!$B$1:$CW$1=$N$10)+('0359-matrix'!$B$1:$CW$1=$O$10)+('0359-matrix'!$B$1:$CW$1=$P$10)+('0359-matrix'!$B$1:$CW$1=$Q$10)+('0359-matrix'!$B$1:$CW$1=F13)+('0359-matrix'!$B$1:$CW$1=G13)+('0359-matrix'!$B$1:$CW$1=H13)+('0359-matrix'!$B$1:$CW$1=I13)+('0359-matrix'!$B$1:$CW$1=J13))*'0359-matrix'!$B$2:$CW$101)>0
I copied only last part, or when it starts from second row..Because it is too long to write whole funciton - it cuts down automatically.
('0359-matrix'!$B$1:$CW$1=$Q$10)+('0359-matrix'!$B$1:$CW$1=$B$13)+('0359-matrix'!$B$1:$CW$1=$C$13)+('0359-matrix'!$B$1:$CW$1=$D$13)+('0359-matrix'!$B$1:$CW$1=$E$13)+('0359-matrix'!$B$1:$CW$1=$F$13))*'0359-matrix'!$B$2:$CW$101)>0
But on marked cells I am getting the same results: B22 - F22 has the same as B21 - F21 (boolean) what shouldnt be like that but to follow color, green is False, it has to be something with an array reference.
Checkout the following. A1 to E5 is the matrix that shows which pieces are incompatible (=1). The others have to be empty or 0.
In cell I8 I used the following formula (and copied it down up to I11):
=SUMPRODUCT(($A$2:$A$5=H8)*(($B$1:$E$1=$H$8)+($B$1:$E$1=$H$9)+($B$1:$E$1=$H$10)+($B$1:$E$1=$H$11))*$B$2:$E$5)
The formula result shows you the amount of incompatibilities a part has. Eg AA1 has one incompatibility with BB2 but BB2 is incompatible with 2 AA1 and CC3.
To get the TRUE/FALSE use the same formula and append >0: like =SUMPRODUCT(…)>0
For any additinonal "group" (Model, Endpoint, …) you need to add another +($B$1:$E$1=$H$12) where $B$1:$E$1 points to your matrix data and $H$12 to your selected group value.
Overview of the formula ranges:
Note that this kind of calculation can only tell the amount of incompatibilites a part has but not the names of the parts that are incompatible.
Edited horizontal version
Formula in the selected cell is
=SUMPRODUCT(($A$2:$A$5=G8)*(($B$1:$E$1=$G$8)+($B$1:$E$1=$H$8)+($B$1:$E$1=$I$8)+($B$1:$E$1=$J$8))*$B$2:$E$5)
you can pull it to the right.

Generating a unique identifier list with multiple tables & criteria

I'm not a coder, just someone who uses excel for basic estimating functions at work. However I've found myself in need of a complex list or index system.
Background/Intent: (Skip below if doesn't matter.) In an apartment building construction they build buildings like opened books - mirror images of 2 bed 2 bath apartments, for example. There is a standard "typical" unit and then the mirror image across the hall, the "reverse" unit. The door swings are all opposite from one to the other. My job is to figure out how to give each door a unique identifier code based on: Bldg No., Unit Type, Door No., Door Swing (left or right.) The raw data tables are provided below.
I've attempted to clean this up as much as possible, but there are two steps (I think) to this process.
Step 1:
The raw data table is on the left. My output field is on the right. I want to be able to select a drag down box, like data validation list, and select the building. Then a formula (which one?) spits out a list of every unit type per building. For example, Bldg 5 has 2 each of "A1 Typ." How do I get the formula to recognize that if there are 2 of them, to produce 2 separate lines for "A1 Typ." And so on and so forth until all 41 occurences/units have been accounted for and labeled appropriately. Some occur once, some multiple times, and some zero.
Step 1
From there, Step 2.
I want to use this output field again to automate another sequence, this time pulling from a different table, see picture. Now, depending on the unit type under the "type" column, I want it to expand each unit type showing each indivudual door number (1,2,3 etc through 12) and if it's an L (LH) or R (RH), and if there is more than one, to list out each occurence. (what formula?)
Then the decriptor text that will pop up under "DOOR LABEL" column would just be a joining of several fields to give a unique identifier. (suggestions?)
Step 2.
Easy right? Is this too much for excel, or can this be done?
Thanks so much for considering helping me out!

Heuristic function of A* search for sorting

My problem is sorting strings given in three lists using implementation of A* search,so I need to develop a heuristic function that will make solving various instances of this problem efficient.
The state can be represented s a list of 3 lists, example: [ [C B], [D], [H G F A E] ]
I pick up the top portion of any stack and move it to any other. For example, the H above could be moved on top of the C or the D, and the [H G] could be moved onto the second stack to create [H G D], etc. In this domain, there are unit operator costs, so each move costs 1, regardless of how many words are being moved.
The goal is to take an initial, configuration of blocks and move them all to the left stack in sorted order from top down. For example, given the 8 blocks in the above example, the goal would be [[A B C D E F G H] [] []].
I need to develop a heuristic that can be used with A* search to make the search efficient.
I should try to keep the heuristics you develop admissible. For that you may try to have your heuristics to approximate the number of steps remaining to reach the goal state.
I thinking about a heuristic depends on the sorted words in each stack and the sum of points of each stack is the heuristic for the state, but this is not efficient, I think that I need to include the ascii code of each letter to my calculations, any ideas?
At the beginning, try a simple or naive heuristic. For example, "h" will be the sum of non-ascending order of two letters. Lets say when you develop a new child you got something like this [ACBED] here take first couple [AC] they are in ascending order, do nothing, but for the next couple [CB] it is not in ascending order then add one to "h". [BE] is good. For [ED] add one to "h". So "h == 2". This Heuristic looks simple but I believe it is better than blind search (i.e. breadth/depth search). From this idea you can add more rules to enhance the heuristic based on your analysis of outcomes. I hope that is useful.

Finding Substring of Number with certain property

I am given a string consisting of only numbers from 0 to 9. I want to calculate how many sub strings of them are power of 2.
For example for substring 2560616 substring 256 and 16 are power of 2. I need to calculate how many such substrings are there in any given substring.
Note that the substring is very large so brute force can't work. So I mainly want to address 2 issues
How to efficiently count all substrings that are power of 2
How to efficiently calculate whether a substring is power of 2
I think there might be a DP approach, but I am not sure about it.
Create a tree from the digits of the powers of 2 with the following algorithm:
Start with a root representing the empty character.
Get the next power of 2, get its digits in reverse order.
Select the root. Select the last digit of the current number.
Go to the child node of the selected node corresponding to the selected digit. If it does not exists yet, create it.
Select the previous digit of the current number. Repeat from (2.) until there are no more digits.
Mark the current node as a valid endpoint.
Repeat from (2.) until number of digits > 10^5
This tree might take a couple GBs in the memory.
Now you have your tree. To count the number of substrings that are power of 2, do the following:
Start from the end of the string.
Get the previous character.
Select the root of the tree.
Select the previous character (starting with the one selected in the outer (2.)).
Select the child node of the selected node corresponding to the selected digit.
If the selected child node is marked as valid endpoint, increment count by 1.
Repeat from (2.) until selected node is null or reached first character of the string.
Go back to character selected in outer (2.)
Select previous character. Repeat from (2.) until reached beginning of string.
The description of the algorithm is not "exam-ready", but i hope its understandable enough.

Resources