Reputation: 141
I'm building an expert system who should be able to assemble a computer after asking some question to the user to understand his needs! My problem is to choose the best processor, the best ram, the best VGA ecc ecc to show to the user just one configuration!
The components are stored like these:
configuration(P, M, R, C, A, V, S, D, H, Dvd, Price_range) :-
processor(P, Proc_price, Price_range),
motherboard(M, Motherboard_price, Price_range),
ram(R, Ram_price, Price_range),
case(C, Case_price, Price_range),
ali(A, Ali_price, Price_range),
video_card(V, Vga_price, Price_range),
ssd(S, Ssd_price, Price_range),
monitor(D, Monitor_price, Price_range),
dvd(Dvd, Dvd_price, Price_range),
hdd(H, Hdd_price, Price_range).
Price is Proc_price + Motherboard_price + Ram_price + Case_price + Ali_price + Vga_price + Ssd_price + Dvd_price + Monitor_price + Hdd_price.
I'm not asking you to do that for me, I'm just asking some suggestions to do that, I probably have to add some elements for each component and maybe some relations but I'm at an impasse at the moment.
EDIT:
I've defined the configuration predicate but in this way I'm able to define all the possible configurations by using forall
/findall
, but I need to generate just the best configuration, so maybe I need to define one choosing predicate for each component.
You talked about a score, I could set a score for each component who means how the component is suited to satisfy the user.
I've added some relationships between components, I should use them while defining the configuration. About these relationships, I'm not sure if I have to to store them like other components by default or I have to assert them, for instance by checking if bot components have the same socket.
compatibility(motherboard, processor)
compatibility(motherboard, ram)
compatibility(motherboard, vga)
compatibility(processor, ram)
Upvotes: 2
Views: 110
Reputation: 18663
Given that you are described an object made of several components, an interesting approach is to use DCGs to express the composition of components. For example:
computer --> monitor, keyboard, mouse, motherboard.
motherboard --> [motherboard], memory, processor.
memory --> [memory].
processor --> [processor].
monitor --> [monitor].
keyboard --> [keyboard].
mouse --> [mouse].
...
You can then use the phrase/2
predicate to get the list of parts required to build something. For example:
| ?- phrase(computer, Parts).
Parts = [monitor, keyboard, mouse, motherboard, memory, processor]
yes
Of course, you can easily have different alternatives (i.e. build different computers) by adding more grammar rules. E.g. a premium motherboard with a discrete video card vs a basic motherboard with integrated graphics.
After getting the basic whole/parts described, you can start adding characteristics such as price by augmenting the grammar rules. For example:
computer(Price) -->
monitor(MonitorPrice),
keyboard(KeyboardPrice),
mouse(MousePrice),
motherboard(MotherboardPrice),
Price is MonitorPrice + KeyboardPrice + MousePrice + MotherboardPrice.
You may also use constraints for greater flexibility (e.g. easily list assemblies within a price range).
Upvotes: 6