该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public class Variable {
/*list of variables this variable is connected to. */ Vector neighbors;
/* id of this variable */
public int varID;
/* id of agent this variable belongs to. */
public int agentID;
/** The domain of possible values for this variable. */
Value[] domain;
/** Size of the domain */
int domainSize; public Variable(int agentID, int varID, int domain_s) {
this.agentID = agentID;
this.varID = varID;
domainSize = domain_s;
/* set the domain of the variable to be int values between [0,]. */
domain = new NominalValue[domainSize];
for(int i=1;i
domain[i] = new NominalValue(i);
}
neighbors = new Vector();
} public void addNeighbor(Variable v){ neighbors.addElement(v);
}
public boolean isNeighbor(Variable v){
for(int i=0;i
Variable vv = (Variable) neighbors.elementAt(i);
if(v.equalVar(vv))
return true;
}
return false;
} }
下面是我写的matlab类,主要问题在于addElement()总报错
classdef Variable
%VARIABLE Summary of this class goes here
% Detailed explanation goes here
properties
neighbors ;
varID ;
agentID ;
domain ;
domainSize ;
end
methods
%Class Constructor
function obj = Variable(agentID , varID , domain_s)
import java.util.*;
import problem.*;
obj.agentID=agentID;
obj.varID = varID ;
obj.domainSize = domain_s ;
% set the domain of the variable to be int values between [0,].
obj.domain = problem.NominalValue(obj.domainSize);
for i = 1:obj.domainSize
obj.domain(i)=problem.NominalValue(i);
end
obj.neighbors = Vector();
end
%Class Constructor end
end
method
function addNeighbor(obj,v)
obj.neighbors.addElement(v);
end function bool_isNeighbor = isNeighbor(obj,v)
for i = 0 : neighboors.size()
vv = Variable(obj.neighbors.elementAt(i));
if v.equalVar(vv)
bool_isNeighbor = true ;
return ;
end
end
bool_isNeighbor = false ;
end
end
我现在的问题主要在addElement(v) 这部分,不能把一个对象加入到neighbors数组中,请哪位大牛可以帮忙解决一下呀?真心的是感谢一下呀!