MATLAB urlread function error appears when trying to connect to a server

29 views Asked by At

I am trying to run the code "[orig_n,start_t_exact,travel_times,acts,act_durations,time_windows,koord,types]=generate_inputs_from_xls('Input.xls','PT','symOTP',5);" using the fuction "generate_inputs_from_xls". though I've run into a problem that I haven't seen before. I run the open trip planner (otp) sever in in command prompt.

The code is : **[orig_n,start_t_exact,travel_times,acts,act_durations,time_windows,koord,types]=generate_inputs_from_xls('Input.xls','PT','symOTP',5);**

symOTP’: generates the travel time matrix for the whole problem using OTP (open trip planner), which requiers to run the OTP server by command prompt. I used this code to run the server

"C:\Users\len\Downloads\OTP\otp>java -Xmx2G -jar otp-2.3.0-shaded.jar
> --build --serve /C:/Users/len/Downloads/OTP/otp"

I think the problem how to connect Matlab with this server.

**The error is: ** Error using urlreadwrite_legacy Error downloading URL. Your network connection may be down or your proxy settings improperly configured.

Error in urlreadwrite (line 88) [output,status] = urlreadwrite_legacy(fcn,catchErrors,varargin{:});

Error in urlread (line 16) [s,status] = urlreadwrite(mfilename,catchErrors,url,varargin{:});

Error in OTP_mivel_mennyi (line 18) str = urlread(url);

Error in generate_inputs_from_xls (line 205) travel_times(i,j)=OTP_mivel_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')]),query_time+0.5);

here is the code of generate_inputs_from_xls from line 63 to 214 :

% finding substitute locations for the activities
for j=1:size(Prio,1)
    % if we know a location for an activity we add it to the list
    if isempty(coord{j,2,1})==0
        koord=[koord; [str2num(coord{j,2,1}),str2num(coord{j,3,1})]];
        countactivities(j+1)=1;
        act_durations=[act_durations Proc_time(j)];
        % intersect user demand time and corresponding opening times
        time_windows=[time_windows; max(TRstart(j),TDstart(j)) min(TRend(j),TDend(j))];
        acts=[acts; zeros(1,size(Prio,1)+1)];
        acts(sum(countactivities),j+1)=1;
    end
    % if prio label is 2 (flexible location) we search for substitute locations
    if Prio(j)==2
        % function finding substitute location in osm data for the given query time
        [cserekoord,openclose]=find_in_csv(budapest,[str2num(coord{j,2,1}),str2num(coord{j,3,1})],coord{j,1,1},query_time);
        % adding the new locations and its properties to the lists
        koord=[koord; cserekoord'];
        act_durations=[act_durations Proc_time(j)*ones(1,size(openclose,1))];
        % intersect user demand time and corresponding opening times
        time_windows=[time_windows; [(max([openclose(:,1) repmat(TDstart(j),[size(openclose,1),1])]'))' (min([openclose(:,2) repmat(TDend(j),[size(openclose,1),1])]'))']];
        acts=[acts; zeros(size(openclose,1),size(Prio,1)+1)];
        acts(sum(countactivities(1:j+1))+1:end,j+1)=ones(size(openclose,1),1);
        countactivities(j+1)=countactivities(j+1)+size(openclose,1);
    end
end

% total number of nodes
orig_n = sum(countactivities);

% initialization of distances
distances=zeros(size(koord,1),size(koord,1));

% linear distances between points
for i=1:size(koord,1)
    for j=1:size(koord,1)
        if i~=j
           if i>j
               distances(i,j)=distances(j,i);
           else
               distances(i,j)=lldistkm(koord(i,:),koord(j,:));
           end
        end
    end
end

% initalization of travel times
travel_times=0*distances;

switch ttmethod
    case 'fullOTP'
        % chossing n closest points
        if nargin==4
            cs=[0 cumsum(countactivities)]; % auxiliary variable
            or_acts=cs(1:end-1)+1; %location of original activities
            % finding points closest to the fix points
            or_acts=or_acts([1; Prio]==1);
            numbers=[];
            for i=1:length(countactivities)
                if countactivities(i)>parameter
                    if length(or_acts)>1
                        [~,closestindices]=sort(sum(distances(or_acts,cs(i)+1:cs(i+1))));
                    else
                        [~,closestindices]=sort(distances(or_acts,cs(i)+1:cs(i+1)));
                    end
                    numbers=[numbers closestindices(1:parameter)+cs(i)];
                else
                    numbers=[numbers cs(i)+1:cs(i+1)];
                end
            end
            % reducing the problem
            orig_n=length(numbers);
            travel_times=travel_times(numbers,numbers);
            koord=koord(numbers,:);
            acts=acts(numbers,:);
            act_durations=act_durations(numbers);
            time_windows=time_windows(numbers,:);
        end
        % correct travel time calculation with OTP
        for i=1:size(koord,1)
            for j=1:size(koord,1)
                if i~=j
                    if mod==0
                        % travel time in driving mode based on OTP
                        travel_times(i,j)=OTP_driving_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')]));
                    end
                    if mod==1
                        % travel time in Public Transport mode based on OTP
                        % at the estimated start time noon
                        travel_times(i,j)=OTP_mivel_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')]),query_time+0.5);
                    end
                    if mod==2
                       travel_times(i,j)=OTP_walking_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')])); 
                    end
                end
            end
        end
     
    case 'symOTP'
        % chossing n closest points
        if nargin==4
            cs=[0 cumsum(countactivities)]; % auxiliary variable
            or_acts=cs(1:end-1)+1; %location of original activities
            % finding points closest to the fix points
            or_acts=or_acts([1; Prio]==1);
            numbers=[];
            for i=1:length(countactivities)
                if countactivities(i)>parameter
                    if length(or_acts)>1
                        [~,closestindices]=sort(sum(distances(or_acts,cs(i)+1:cs(i+1))));
                    else
                        [~,closestindices]=sort(distances(or_acts,cs(i)+1:cs(i+1)));
                    end
                    numbers=[numbers closestindices(1:parameter)+cs(i)];
                else
                    numbers=[numbers cs(i)+1:cs(i+1)];
                end
            end
            % reducing the problem
            orig_n=length(numbers);
            travel_times=travel_times(numbers,numbers);
            koord=koord(numbers,:);
            acts=acts(numbers,:);
            act_durations=act_durations(numbers);
            time_windows=time_windows(numbers,:);
        end
        % approximated travel time calculations (assuming matrix is symmetric to its diagonal) with OTP leaving out unnecessary edges
        for i=1:size(koord,1)
            for j=1:size(koord,1)
                if i~=j
                   if i>j
                       travel_times(i,j)=travel_times(j,i);
                   else
                       if ismember(acts(i,:),acts(j,:),'rows')
                           travel_times(i,j)=Inf;
                       else
                           if mod==0
                               % travel time in driving mode based on OT
                                travel_times(i,j)=OTP_driving_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')]));
                           end
                           if mod==1
                               % travel time in Public Transport mode based on OTP
                               % at the estimated start time noon
                               travel_times(i,j)=OTP_mivel_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')]),query_time+0.5);
                           end
                           if mod==2
                               travel_times(i,j)=OTP_walking_mennyi(cellstr([num2str(koord(i,1),'%3.7f'),',',num2str(koord(i,2),'%3.7f')]),cellstr([num2str(koord(j,1),'%3.7f'),',',num2str(koord(j,2),'%3.7f')])); 
                           end
                       end
                   end
                end
            end
        end

How to solve this problem.

0

There are 0 answers