Circuit simulator

Description

Electric circuit simulator in CLP(R)

Source: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.

Download

Program source code: circuit_simulator.pl

Listing

% Electric circuit simulator in CLP(R)
 
% resistor( T1, T2, R):
%  R=resistance; T1, T2 its terminals
 
resistor( (V1,I1), (V2,I2), R)  :-
   I1 = -I2, V1-V2 = I1*R .
 
% diode( T1, T2):
%   T1, T2 terminals of a diode
%   Diode open in direction from T1 to T2
 
diode( (V1,I1), (V2,I2) )  :-
   I1 + I2 = 0,
   I1 > 0, V1 = V2
    ;
    I1 = 0, V1 =< V2.
 
battery( (V1,I1), (V2,I2), Voltage)  :-
   I1 + I2 = 0, Voltage = V1 - V2 .
 
% conn( [T1,T2,...]):
%  Terminals T1, T2, ... connected
%  Therefore all el. potentials equal, sum of currents = 0
 
conn( Terminals)  :-
  conn( Terminals, 0).
 
conn( [ (V,I) ], Sum)  :-
   Sum + I = 0 .
 
conn( [ (V1,I1), (V2,I2) | Rest], Sum)  :-
   V1 = V2, Sum1 = Sum + I1,
  conn( [ (V2, I2) | Rest], Sum1).

Comments

pl/prolog/pllib/circuit_simulator.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0