Web of Lossy Adapters for Interface Interoperability: An Algorithm and NP-completeness of Minimization
aa r X i v : . [ c s . S E ] J u l Web of Lossy Adapters for Interface Interoperability:An Algorithm and NP-completeness of Minimization
Yoo Chung, Dongman Lee ∗ KAIST ICC, 119 Munjiro, Yuseong-gu, Daejeon 305-732, South Korea
Abstract
By using different interface adapters for different methods, it is possible toconstruct a maximally covering web of interface adapters which incurs minimumloss during interface adaptation. We introduce a polynomial-time algorithm thatcan achieve this. However, we also show that minimizing the number of adaptersincluded in a maximally covering web of interface adapters is an NP-completeproblem.
Key words: software engineering, interface adaptation, interoperability
1. Introduction
Different services that provide similar functionality will often be accessedusing widely different interfaces, especially if standardization is lacking. Toavoid having to rewrite separate code for all interfaces that may have to beused, interface adapters can be used to translate calls to one interface into callsto another interface. [4]These interface adapters may not be able to achieve perfect adaptation. Itbecomes harder to analyze the adaptation loss when combining such interfaceadapters in order to reduce the number of adapters that must be developed.Our previous work has defined a rigorous mathematical basis for analyzing theloss in single interface adapter chains. [1]This paper extends our previous work by considering the use of a web ofinterface adapters. This allows the adaptation of interfaces with minimum loss,and we describe a polynomial-time algorithm that can achieve this. However, wealso show that finding a web of adapters that can achieve minimum adaptationloss with the minimum number of interface adapters is an NP-complete problem,which implies that reducing the number of adapters included in a web of interfaceadapters should be done heuristically. ∗ Corresponding author
Email addresses: [email protected] (Yoo Chung), [email protected] (DongmanLee)
Preprint submitted to Information Processing Letters November 16, 2018 . Preliminaries
The basic concepts and notations we use follow those in our previous work. [1]We will be using a range convention for the index notation used to expressmatrixes and vectors. [2]We take the view that an interface defines multiple methods, and that aninterface adapter converts a call to one method in a source interface into callsto one or more methods in a target interface. We assume that if a method ina source interface can be adapted, then it can be adapted perfectly. Any losswould be incurred if a method in a source interface cannot be adapted at all.We also assume that interface adapters do not store any state.An interface adapter graph is a directed graph where interfaces are nodesand adapters are edges. If there are interfaces I and I with an adapter A thatadapts source interface I to target interface I , then I and I would be nodesin the interface adapter graph while A would be a directed edge from I to I .The method dependency matrix a ji for an adapter A is defined by how theadapter depends on the availability of a method in the source interface in order toimplement a method in the target interface. a ji is true if and only if method j inthe target interface can be implemented only if method i in the source interfaceis available. We denote the method dependency matrix associated with anadapter A as depend ( A ).
3. Web of lossy adapters
Existing approaches use only a single interface adapter to adapt a giventarget interface from one or more source interfaces. [6, 8, 7] These approachesforce us to choose among imperfect chains of interface adapters, where one chainmight be able to adapt certain methods in the source interface but cannot adaptother methods covered by another chain and vice versa. However, using a webof interface adapters , a directed acyclic interface adapter graph where differentadapters can be used to adapt different methods in an interface, can cover allmethods that can possibly be adapted, incurring minimum loss.Algorithm 1 can construct a web of interface adapters that can cover allpossible methods in a target interface given a fully functional source interface,which we will refer to as a maximally covering web of interface adapters. It isbased on unit propagation for Horn formulae [3], targeted towards building aweb of interface adapters. It works in two phases, where it first computes allmethods in all interfaces that can be adapted given the source interface, and thenextracts only the subgraph relevant for the target interface. Algorithms 2 and 3are subalgorithms responsible for setup and subgraph extraction, respectively.Simply constructing a web of interface adapters is not the goal by itself, ofcourse. The real goal is to use the interface adapters to adapt methods froma source interface into those of a target interface. Choosing which adaptersshould be used for which methods is more complex than in the case for a singlechain, where there is no choice at all. Algorithm 4 is an abstract algorithmfor determining which interface adapters should be invoked when adapting each2 lgorithm 1
Constructing maximally covering web of interface adapters. function
Maximal-Cover ( G , s , t )( Q, D, S, M, C ) ← Cover-Setup (G, s) while Q is not empty do extract ( I, i ) from Q for ( A = ( I, I ′ ) , j ) ∈ M [ I ][ i ] doif C [ A ][ j ] > then C [ A ][ j ] ← C [ A ][ j ] − if C [ A ][ j ] = 0 then ⊲ adaptation viable D [ I ′ ][ j ] ← D [ I ′ ][ j ] ∪ { A } if not S [ I ′ ][ j ] then S [ I ′ ][ j ] ← true insert ( I ′ , j ) into Q ⊲ trigger new dependent end ifend ifend ifend forend whilereturn ( Cover-Subgraph ( D , t ), D ) end functionAlgorithm 2 Setup for constructing maximal covering. function
Cover-Setup ( G = ( V, E ), s ) Q ← empty queue for I ∈ V and method i of I do D [ I ][ i ] ← ∅ ⊲ list of viable adapters S [ I ][ i ] ← false ⊲ whether satisfiable M [ I ][ i ] ← ∅ for A = ( I, I ′ ) ∈ E do M [ I ][ i ] ← M [ I ][ i ] ∪ { ( A, j ) | depend ( A ) ji } ⊲ dependents end forend forfor A = ( I , I ) ∈ E and method j of I do C [ A ][ j ] ← |{ i | depend ( A ) ji }| ⊲ unsatisfied dependency count end forfor each method i of s do ⊲ start with source interface S [ s ][ i ] = true insert ( s, i ) into Q end forreturn ( Q, D, S, M, C ) end function lgorithm 3 Extract subgraph comprising web of interface adapters. function
Cover-Subgraph ( D , t ) V ′ ← ∅ , E ′ ← ∅ Q ← empty queue, Q ′ ← ∅ for method i of t do insert ( t, i ) in Q and Q ′ end forwhile Q is not empty do extract ( I ′ , j ) from QV ′ ← V ′ ∪ { I ′ } E ′ ← E ′ ∪ D [ I ′ ][ j ] for A = ( I, I ′ ) ∈ D [ I ′ ][ j ] dofor i such that depend ( A ) ji doif ( I, i ) Q ′ then insert ( I, i ) into Q and Q ′ end ifend forend forend whilereturn ( V ′ , E ′ ) end function method. It needs more information than just the web of interface adapters,which is provided by the value D also returned in algorithm 1.The interface adapters used to adapt a given method are specified by algo-rithm 4; the concrete steps involved in actually adapting a method are left tohow interface adaptation is actually done, whether it be direct invocation by theinterface adapter, call substitution after constructing the call graph, or composi-tion of interface adapters specified in a high-level language. The exact criterionfor selecting an adapter in algorithm 4 also does not affect the correctness ofthe algorithm.Algorithm 1 constructs a maximally covering web of adapters, but it com-pletely ignores the number of interface adapters it incorporates in the web. Itcould end up constructing a web with hundreds of interface adapters when lessthan a dozen would do. However, trying to minimize the number of incorpo-rated interface adapters is an NP-complete problem as we will show in section 4.Invoking the minimum number of interface adapters while actually adapting amethod also turns out to be NP-complete.
4. Minimizing number of adapters
While algorithm 1 can construct a maximally covering web of interfaceadapters in polynomial time ( O ( m ) being a loose time bound with a straight-forward implementation, where m is the total number of methods), it is unlikelythere will be a polynomial-time algorithm for finding a maximally covering web4 lgorithm 4 Adapting a specific method in the target interface. procedure
Adapt-Method ( D , s , t , m ) if D [ t ][ m ] = ∅ then adaptation not possible else Recursive-Adapt ( D , s , t , m , { t } ) end ifend procedureprocedure Recursive-Adapt ( D , s , I , m , V ) if I = s thenreturnend if select A = ( I ′ , I ) ∈ D [ I ][ m ] where I ′ V for method i in I ′ where depend ( A ) mi do Recursive-Adapt ( D , s , I ′ , i , V ∪ { I ′ } ) end for adapt method m in interface I using A end procedure of adapters with the minimum number of interface adapters. This is because theproblem is NP-complete, which we will prove with a reduction from one-in-three3SAT. [5]We formally define MINWEB as the problem of whether there is a web ofinterface adapters in an interface adapter graph from a given source interfaceto a given target interface such that it is maximally covering and has at most K interface adapters. Given a candidate boolean expression for one-in-three3SAT with c clauses and v variables, we will reduce it to a candidate interfaceadapter graph for MINWEB such that the boolean expression is an instance ofone-in-three 3SAT if and only if there is a maximally covering web of interfaceadapters with at most v + 2 c adapters.For each variable, we create an interface with methods corresponding to allthe literals, two for each variable. For each clause, we create an interface withonly a single method. We also separately create a source interface with meth-ods corresponding to the possible literals and a target interface with methodscorresponding to the clauses.Starting from the source interface, we connect the interfaces corresponding tovariables serially. Between each of these interfaces, we define two adapters, onewhich makes the method corresponding the successor variable true and the otherwhich makes it false, by making the method correspoding to the positive literalavailable and the method corresponding to the negative literal unavailable inone adapter and the opposite in the other adapter. Other literals are left alone.This is identical to how a variable handling subgraph is constructed in [1].From the sink node of the variable handling subgraph, we create threeadapters to each of the interfaces corresponding to the clauses. Each adapter5orresponds to a literal in the clause, and the sole method in the interface isavailable only if the method corresponding to the literal is available. And fromeach interface corresponding to a clause, there is a single adapter to the targetinterface for the entire graph which makes the method corresponding to theclause available only if the sole method in the clause interface is available.For the graph constructed this way, the entire graph is obviously maximallycovering with 2 v + 4 c adapters and all methods available at the target interface.If the original boolean expression is an instance of one-in-three 3SAT, thena satisfying assignment can specify a singly-linked path through the variableinterfaces, followed by each true literal specifying the adapters to pass throughto each clause interface, followed by the adapters to the target interface, and theresulting directed acyclic graph is a maximally covering web of adapters with v + 2 c adapters, since all methods will be available at the target interface.Conversely, if there is a maximally covering web of adapters with v + 2 c adapters, then 2 c adapters connect to the clause interfaces since all clause in-terfaces must be included. The remaining v adapters must be a singly-linkedpath through the variable interfaces, and the selection of adapters for each vari-able interface specifies a variable assignment which satisfies the original booleanexpression with only one true literal in each clause. Therefore MINWEB isNP-complete, and we can also conclude that minimizing the number of requiredadapters to adapt a single method is also NP-complete by removing the othermethods in the target interface.
5. Related work [6] implements a network repository of interface adapters for adapting Javainterfaces using single chains of adapters. [8] implements a similar adaptationframework for network services. Although it allows an interface adapter toadapt a target interface from multiple source interfaces, only a single interfaceadapter is used for each target interface, so it has the same limitations as singleadapter chains in that not all methods that could be adapted may actually beadapted. Both mention the possibility of lossy interface adaptation, but neitherconsiders how to minimize such loss.[7] proposes an interface adaptation framework which attempts to minimizethe loss incurred by an interface adapter chain, and [1] rigorously defines themathematical background required to implement such a framework. These onlyconsider the use of single chains of interface adapters.
6. Conclusions
We described a polynomial-time algorithm which can construct a maximallycovering web of interface adapters, which may include a much larger number ofinterface adapters than necessary. However, we also showed that minimizing thenumber of interface adapters included in a maximally covering web of interfaceadapters is an NP-complete problem. 6urther work can be done to extend these results by relaxing the assump-tions made for this paper. We can consider the case when a method in a targetinterface can only be partially implemented from methods in a source inter-face. We can also consider how the quality of adapters should be dealt with inalgorithms, or how to deal with adapters that maintain state. Heuristic algo-rithms which attempt to minimize the number of adapters included in a nearlymaximally covering web of interface adapters is another area for future work.
References [1] Y. Chung and D. Lee. A mathematical basis for the chaining of lossy interfaceadapters. In revision for IET Software. http://arxiv.org/abs/0901.4835 .[2] M. Crampin and F. A. E. Pirani.
Applicable Differential Geometry , chap-ter 0, pages 5–7. Number 59 in London Mathematical Society Lecture NoteSeries. Cambridge University Press, Mar. 1987.[3] W. F. Dowling and J. H. Gallier. Linear-time algorithms for testing thesatisfiability of propositional Horn formulae.
Journal of Logic Programming ,1(3):267–284, Oct. 1984.[4] E. Gamma, R. Helm, R. Johnson, and J. M. Vlissides.
Design Patterns:Elements of Reusable Object-Oriented Software . Addison-Wesley, Nov. 1994.[5] M. R. Garey and D. S. Johnson.
Computers and Intractability: A Guide tothe Theory of NP-Completeness . W. H. Freeman and Company, Jan. 1979.[6] T. Gschwind. Type based adaptation: An adaptation approach for dynamicdistributed systems. In
Proceedings of the Third International Workshopon Software Engineering and Middleware , volume 2596 of
Lecture Notes inComputer Science , pages 130–143, May 2002.[7] B. Kim, K. Lee, and D. Lee. An adapter chaining scheme for service con-tinuity in ubiquitous environments with adapter evaluation. In
Proceedingsof the Sixth IEEE International Conference on Pervasive Computing andCommunications , pages 537–542. IEEE Computer Society Press, Mar. 2008.[8] S. R. Ponnekanti and A. Fox. Application-service interoperation withoutstandardized service interfaces. In